This commit is contained in:
Geoffrey Frogeye 2019-04-14 19:41:33 +02:00
parent f6a7963f1d
commit 20e67036df
22 changed files with 2414 additions and 246 deletions

View file

@ -51,7 +51,8 @@ bindsym $mod+Shift+d exec --no-startup-id rofi -modi drun -show drun
bindsym $mod+Return exec urxvtc
bindsym $mod+Shift+Return exec urxvt
bindsym $mod+p exec thunar
bindsym $mod+m exec qutebrowser --override-restore --backend=webengine
# bindsym $mod+m exec qutebrowser --override-restore --backend=webengine
bindsym $mod+m exec firefox
# Volume control
bindsym XF86AudioRaiseVolume exec pactl set-sink-mute @DEFAULT_SINK@ false; exec pactl set-sink-volume @DEFAULT_SINK@ +5%

2
config/shell/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*.zwc
.zcompdump

4
config/shell/.zprofile Normal file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env zsh
source ~/.config/shell/shenv
source ~/.config/shell/commonenv

5
config/shell/.zshrc Normal file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env zsh
source ~/.config/shell/shrc
source ~/.config/shell/commonrc
source ~/.config/shell/zshrc

42
config/shell/bashrc Normal file
View file

@ -0,0 +1,42 @@
#!/usr/bin/env bash
#
# Bash aliases and customizations
#
# Shell options
shopt -s expand_aliases
shopt -s histappend
HISTCONTROL=ignoreboth:erasedups
# Prompt customization
INTERACTIVE_BASHPID_TIMER="${HOME}/.cache/bash_timer_$$"
PS0='$(echo $SECONDS > "$INTERACTIVE_BASHPID_TIMER")'
function _update_ps1() {
local __ERRCODE=$?
local __DURATION=0
if [ -e "$INTERACTIVE_BASHPID_TIMER" ]; then
local __END=$SECONDS
local __START=$(cat "$INTERACTIVE_BASHPID_TIMER")
__DURATION="$(($__END - ${__START:-__END}))"
\rm -f "$INTERACTIVE_BASHPID_TIMER"
fi
# echo -en "… $\r"
eval "$(powerline-go -shell bash -eval -duration $__DURATION -error $__ERRCODE "${POWERLINE_GO_DEFAULT_OPTS[@]}")"
}
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
# Completion
trysource /usr/share/bash-completion/bash_completion
# Fuzzy matching all the way
trysource /usr/share/fzf/completion.bash
trysource /usr/share/fzf/key-bindings.bash

8
config/shell/commonenv Normal file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env sh
#
# Bash / ZSH common environment variables and functions
#
export TIME_STYLE='+%Y-%m-%d %H:%M:%S'
eval $(dircolors --sh)

32
config/shell/commonrc Normal file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env sh
#
# Bash / ZSH aliases and customizations
#
# Shell options
HISTSIZE=100000
HISTFILE="$HOME/.cache/shell_history"
## COMMAND CONFIGURATION
# Completion for existing commands
alias cp="cp -i --reflink=auto"
alias grep="grep --color=tty"
alias dd='dd status=progress'
alias rm='rm -Iv --one-file-system'
alias free='free -m'
alias dmesg='dmesg --ctime'
# [ -f ~/.local/bin/colorSchemeApplyFzf ] && . ~/.local/bin/colorSchemeApplyFzf # Only applies RGB colors...
POWERLINE_GO_DEFAULT_OPTS=(-colorize-hostname -max-width 25 -cwd-max-dir-size 10 -modules 'user,host,ssh,venv,cwd,perms,git' -modules-right 'jobs,exit,duration,load') # For reading by shell profiles
FZF_DEFAULT_OPTS="--height 100% --layout=default"
FZF_CTRL_T_OPTS="--preview '[[ -d {} ]] && ls -l --color=always {} || [[ \$(file --mime {}) =~ binary ]] && file --brief {} || (highlight -O ansi -l {} || coderay {} || rougify {} || cat {}) 2> /dev/null | head -500'"
FZF_COMPLETION_OPTS="${FZF_CTRL_T_OPTS}"
## FUNCTIONS
## MISC
trysource ~/.gscripts/gprofile

51
config/shell/shenv Normal file
View file

@ -0,0 +1,51 @@
#!/usr/bin/env sh
#
# Shell common environment variables and functions (BusyBox compatible)
#
# Favourite commands
export PAGER=less
export EDITOR=nvim
export VISUAL=nvim
export BROWSER=qutebrowser
# Program-specific
[ -z "$SSH_AUTH_SOCK" ] && [ -x "$(command -v ssh-agent)" ] && eval "$(ssh-agent -s)"
export GOPATH=$HOME/.cache/go
# export JAVA_FONTS=/usr/share/fonts/TTF
# export ANDROID_HOME=/opt/android-sdk
# export ARDUINO=/usr/share/arduino
# export ARDUINO_DIR=$ARDUINO
# export ARDMK_VENDOR=archlinux-arduino
# Path
# Function stolen from Arch Linux /etc/profile
appendpath() {
if [ ! -d "$1" ]; then
return
fi
case ":$PATH:" in
*:"$1":*) ;;
*)
# TODO Reverse order: I want the latest ones to supersedes the older ones
export PATH="${PATH:+$PATH:}$1"
;;
esac
}
appendpath '/usr/lib/ccache/bin'
appendpath "$GOPATH"
appendpath "$HOME/.local/bin"
appendpath "$HOME/.scripts"
# If running on termux, load those extra scripts
[ -d /data/data/com.termux/ ] && (
appendpath "$HOME/.termux/scripts"
appendpath "$HOME/.termux/bin"
)
# For superseding commands with better ones if they are present

88
config/shell/shrc Normal file
View file

@ -0,0 +1,88 @@
#!/usr/bin/env sh
#
# Shell common aliases and customizations (BusyBox compatible)
#
## COMMAND CONFIGURATION
# Completion for existing commands
alias ls='ls -h --color=auto'
alias mkdir='mkdir -v'
alias cp="cp -i"
alias mv="mv -iv"
alias free='free -h'
alias df='df -h'
alias ffmpeg='ffmpeg -hide_banner'
alias ffprobe='ffprobe -hide_banner'
alias ffplay='ffplay -hide_banner'
# ALIASES
# Frequent mistakes
alias sl=ls
alias al=la
alias mdkir=mkdir
alias systemclt=systemctl
alias please=sudo
# Shortcuts for commonly used commands
alias ll="ls -l"
alias la="ls -la"
alias s='sudo -s -E'
alias n='urxvtc &'
alias x='startx; logout'
alias nx='nvidia-xrun; logout'
# FUNCTIONS
trysource() {
if [ -f "$1" ]
then
. "$1"
else
return 1
fi
}
# Superseding commands with better ones if they are present
_rank_select() { # executables... -- arguments...
for ex in "$@"; do
[ "$ex" = "--" ] && break
if which "$ex" &>/dev/null; then
for al in "$@"; do
shift
[ "$al" = "--" ] && break
alias "$al"="$ex"
done
"$ex" "$@"
return $?
fi
done
for ex in "$@"; do
[ "$al" = "--" ] && break
if [ -z "$list" ]; then
list=$ex
else
list=$list, $ex
fi
done
echo "Not installed: $list"
}
_rank_install() { # executables...
for ex in "$@"; do
list=$@
alias "$ex"="_rank_select $list --"
done
}
_rank_install nvim vim vi
_rank_install gopass pass
_rank_install wakeonlan wol
_rank_install neomutt mutt
## COLORS
[ -f ~/.local/bin/colorSchemeApply ] && . ~/.local/bin/colorSchemeApply
# Needed because xterm/urxvt won't use the last color, needed for vim

187
config/shell/zshrc Normal file
View file

@ -0,0 +1,187 @@
#!/usr/bin/env zsh
#
# ZSH aliases and customizations
#
# TODO Learn `setopt extendedglob`
# TODO Add asdf (oh-my-zsh plugin is air, git clone is the way (aur package outdated))
# Approximate RGB colors by terminal colors
[[ "$COLORTERM" == (24bit|truecolor) || "${terminfo[colors]}" -eq '16777216' ]] || zmodload zsh/nearcolor
# Plugins
ADOTDIR=~/.cache/antigen
mkdir -p $ADOTDIR
typeset -a ANTIGEN_CHECK_FILES=(~/.config/shell/zshrc)
source ~/.local/share/zsh/antigen.zsh # Don't work with trysource, why?
antigen bundle zsh-users/zsh-completions
antigen bundle zsh-users/zsh-syntax-highlighting
antigen bundle zsh-users/zsh-autosuggestions
antigen bundle zsh-users/zsh-history-substring-search
antigen apply
# Prompt customization
zmodload zsh/datetime
function preexec() {
__TIMER=$EPOCHREALTIME
}
function powerline_precmd() {
local __ERRCODE=$?
local __DURATION=0
if [ -n $__TIMER ]; then
local __ERT=$EPOCHREALTIME
__DURATION="$(($__ERT - ${__TIMER:-__ERT}))"
fi
# echo -en "… $\r"
eval "$(powerline-go -shell zsh -eval -duration $__DURATION -error $__ERRCODE "${POWERLINE_GO_DEFAULT_OPTS[@]}")"
unset __TIMER
}
function install_powerline_precmd() {
for s in "${precmd_functions[@]}"; do
if [ "$s" = "powerline_precmd" ]; then
return
fi
done
precmd_functions+=(powerline_precmd)
}
install_powerline_precmd
# Cursor based on mode
if [ $TERM = "linux" ]; then
_LINE_CURSOR="\e[?0c"
_BLOCK_CURSOR="\e[?8c"
else
_LINE_CURSOR="\e[6 q"
_BLOCK_CURSOR="\e[2 q"
fi
function zle-keymap-select zle-line-init
{
case $KEYMAP in
vicmd) print -n -- "$_BLOCK_CURSOR";;
viins|main) print -n -- "$_LINE_CURSOR";;
esac
# zle reset-prompt
# zle -R
}
function zle-line-finish
{
print -n -- "$_BLOCK_CURSOR"
}
zle -N zle-line-init
zle -N zle-line-finish
zle -N zle-keymap-select
# Should I really put a comment to explain what this does?
bindkey 'jk' vi-cmd-mode
# Edit command line
autoload edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
# History search
# bind UP and DOWN arrow keys
zmodload zsh/terminfo
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey "$terminfo[kcud1]" history-substring-search-down
# bind UP and DOWN arrow keys (compatibility fallback
# for Ubuntu 12.04, Fedora 21, and MacOSX 10.9 users)
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
# bind P and N for EMACS mode
bindkey -M emacs '^P' history-substring-search-up
bindkey -M emacs '^N' history-substring-search-down
# bind k and j for VI mode
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down
# Autocompletion
autoload -Uz compinit promptinit
compinit
promptinit
# Color common prefix
zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)(?)*==35=00}:${(s.:.)LS_COLORS}")'
setopt GLOBDOTS # Complete hidden files
setopt NO_BEEP # that annoying beep goes away
# setopt NO_LIST_BEEP # beeping is only turned off for ambiguous completions
setopt AUTO_LIST # when the completion is ambiguous you get a list without having to type ^D
# setopt BASH_AUTO_LIST # the list only happens the second time you hit tab on an ambiguous completion
# setopt LIST_AMBIGUOUS # this is modified so that nothing is listed if there is an unambiguous prefix or suffix to be inserted --- this can be combined with BASH_AUTO_LIST, so that where both are applicable you need to hit tab three times for a listing
unsetopt REC_EXACT # if the string on the command line exactly matches one of the possible completions, it is accepted, even if there is another completion (i.e. that string with something else added) that also matches
unsetopt MENU_COMPLETE # one completion is always inserted completely, then when you hit TAB it changes to the next, and so on until you get back to where you started
unsetopt AUTO_MENU # you only get the menu behaviour when you hit TAB again on the ambiguous completion.
unsetopt AUTO_REMOVE_SLASH
# Fuzzy matching all the way
# trysource /usr/share/fzf/completion.zsh
trysource /usr/share/fzf/key-bindings.zsh
# Help
autoload -Uz run-help
unalias run-help
alias help=run-help
autoload -Uz run-help-git
autoload -Uz run-help-ip
autoload -Uz run-help-openssl
autoload -Uz run-help-p4
autoload -Uz run-help-sudo
autoload -Uz run-help-svk
autoload -Uz run-help-svn
# Dir stack
DIRSTACKFILE="$HOME/.cache/zsh/dirs"
if [[ -f $DIRSTACKFILE ]] && [[ $#dirstack -eq 0 ]]; then
dirstack=( ${(f)"$(< $DIRSTACKFILE)"} )
# [[ -d $dirstack[1] ]] && cd $dirstack[1]
fi
chpwd() {
print -l $PWD ${(u)dirstack} >$DIRSTACKFILE
}
DIRSTACKSIZE=100
setopt AUTO_PUSHD PUSHD_SILENT PUSHD_TO_HOME
setopt PUSHD_IGNORE_DUPS # Remove duplicate entries
setopt PUSHD_MINUS # This reverts the +/- operators.
# Command not found
# (since we have syntax highlighting there is no need to wait to see that we typed crap)
trysource /usr/share/doc/pkgfile/command-not-found.zsh
# History
# From https://unix.stackexchange.com/a/273863
SAVEHIST=$HISTSIZE
setopt BANG_HIST # Treat the '!' character specially during expansion.
unsetopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format.
setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space.
setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry.
unsetopt HIST_VERIFY # Don't execute immediately upon history expansion.
unsetopt HIST_BEEP # Beep when accessing nonexistent history.