# Some variables are defined in ../commandline.nix # For users using home-manager if [ -f "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" ]; then . "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" fi # Grml Zsh configuration {{{ # ========================== # With prompt specific sequences local dominated="%{${dominant_escape_code}%}" local dimmed="%{${dim_fg_escape_code}%}" # Use the dominant color in the prompt # In the username item for non-root, in the host item for root if [ "$EUID" -ne 0 ]; then zstyle ':prompt:grml:left:items:user' pre "${dominated}%B" else zstyle ':prompt:grml:left:items:host' pre "${dominated}" zstyle ':prompt:grml:left:items:host' post "%f" fi # Remove the command-path completion of sudo set by grml, since Nix has # non-standard PATHs zstyle -d ':completion:*:sudo:*' command-path # Change the style of VCS prompt info zstyle ':vcs_info:*' check-for-changes true zstyle ':vcs_info:*' stagedstr "s" zstyle ':vcs_info:*' unstagedstr "u" zstyle ':vcs_info:*' formats "${dimmed}(%f%s${dimmed})-[${dominated}%b${dimmed}]-{%f%c%u${dimmed}}%f " "zsh: %r" zstyle ':vcs_info:*' actionformats "${dimmed}(%f%s${dimmed})-[${dominated}%b${dimmed}|%F{yellow}%a${dimmed}]-{%f%c%u${dimmed}}%f " "zsh: %r" # }}} # Completion system {{{ # ===================== # Change completion messages zstyle ':completion:*:corrections' format "${dominated}%BFTFY: %b${dominated}(errors: %e)%f" zstyle ':completion:*:descriptions' format "${dominated} -- So you want a %B%d%b${dominated}? --%f" zstyle ':completion:*:messages' format "${dominated}You got mail: %f%d" zstyle ':completion:*:warnings' format "%F{red}I'm sorry Dave, but I cannot allow you to find%f %d" # Always activate selection in completion zstyle ':completion:*' menu select # Case insensitive completion and substring completion zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' # Increase the number of errors based on the length of the typed word. But make # sure to cap (at 7) the max-errors to avoid hanging. zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3>7?7:($#PREFIX+$#SUFFIX)/3))numeric)' # Tmux Completion {{{ # ------------------- # From: https://blog.plenz.com/2012-01/zsh-complete-words-from-tmux-pane.html # And: https://gist.github.com/blueyed/6856354 _tmux_pane_words() { local expl local -a w if [[ -z "$TMUX_PANE" ]]; then _message "not running inside tmux!" return 1 fi # Based on vim-tmuxcomplete's splitwords function. # https://github.com/wellle/tmux-complete.vim/blob/master/sh/tmuxcomplete _tmux_capture_pane() { tmux capture-pane -J -p -S -100 $@ | # Remove "^C". sed 's/\^C\S*/ /g' | # copy lines and split words sed -e 'p;s/[^a-zA-Z0-9_]/ /g' | # split on spaces tr -s '[:space:]' '\n' | # remove surrounding non-word characters =grep -o "\w.*\w" } # Capture current pane first. w=( ${(u)=$(_tmux_capture_pane)} ) echo $w > /tmp/w1 local i for i in $(tmux list-panes -F '#D'); do # Skip current pane (handled before). [[ "$TMUX_PANE" = "$i" ]] && continue w+=( ${(u)=$(_tmux_capture_pane -t $i)} ) done _wanted values expl 'word from current tmux pane' compadd -a w } zle -C tmux-pane-words-prefix complete-word _generic zle -C tmux-pane-words-anywhere complete-word _generic zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' completer _tmux_pane_words zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' ignore-line current # Display the menu on first execution of the hotkey. zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' menu yes select zstyle ':completion:tmux-pane-words-anywhere:*' matcher-list 'b:=* m:{A-Za-z}={a-zA-Z}' # }}} # }}} # Bindkeys {{{ # ============ bindkey -v bindkey '^X^T' tmux-pane-words-prefix bindkey '^[[A' history-substring-search-up bindkey '^[[B' history-substring-search-down bindkey '^[OA' history-substring-search-up bindkey '^[OB' history-substring-search-down autoload -rUz run-help-nix bindkey '^K' run-help bindkey '^P' push-line-or-edit # }}} # Aliases {{{ # =========== # Some aliases taken from the Prezo zsh configuration framework: # https://github.com/sorin-ionescu/prezto # Git {{{ # ------- alias g='git' # Branch (b) alias gb='git branch' # Commit (c) alias gc='git commit --verbose' alias gca='git commit --verbose --all' alias gcf='git commit --amend --reuse-message HEAD' alias gcs='git show' alias gco='git checkout' alias gcO='git checkout --patch' # Fetch (f) alias gf='git fetch' alias gfm='git pull' alias gfc='git clone' alias gfcr='git clone --recurse-submodules' # Index (i) alias gia='git add' alias giA='git add --patch' alias gid='git diff --cached' alias giD='git diff --cached --word-diff' # Log (l) logMediumFormat='%C(bold)Commit:%C(reset) %C(green)%H%C(red)%d%n%C(bold)Author:%C(reset) %C(cyan)%an <%ae>%n%C(bold)Date:%C(reset) %C(blue)%ai (%ar)%C(reset)%n%+B' logBriefFormat='%C(green)%h%C(reset) %s%n%C(blue)(%ar by %an)%C(red)%d%C(reset)%n' logOnelineFormat='%C(green)%h%C(reset) %s%C(red)%d%C(reset)%n' alias gl='git log --topo-order --pretty=format:"${logMediumFormat}"' alias gls='git log --topo-order --stat --pretty=format:"${logMediumFormat}"' alias gld='git log --topo-order --stat --patch --full-diff --pretty=format:"${logMediumFormat}"' alias glg='git log --topo-order --all --graph --pretty=format:"${logOnelineFormat}"' alias glo='git log --topo-order --pretty=format:"${logOnelineFormat}"' alias glb='git log --topo-order --pretty=format:"${logBriefFormat}"' alias glc='git shortlog --summary --numbered' # Merge (m) alias gm='git merge' alias gmt='git mergetool' # Push (p) alias gp='git push' alias gpf='git push --force-with-lease' alias gpt='git push --tags' # Rebase (r) alias gr='git rebase' # Stash (s) alias gs='git stash' # Working Copy (w) alias gws='git status --ignore-submodules=none' alias gwd='git diff' alias gwD='git diff --word-diff' # }}} # Prevents some mistakes alias cp='cp -i' alias mv='mv -i' alias rm='rm -i' # }}} # Helpful functions {{{ # ===================== function ssht { /usr/bin/env ssh -t "$@" "tmux new-session -A -s 'ssh-$HOST'" } compdef ssht=ssh # }}} # Abbreviations {{{ # ================= # Abbreviation system provided by the grml config # More info here: # http://www.zshwiki.org/home/examples/zleiab abk=( 'P' '|& ${(z)PAGER}' 'L' '|& ${(z)PAGER}' 'HL' ' --help |& ${(z)PAGER}' 'G' '|& rg' 'FG' '|& rg -F' 'H' '| head' 'T' '| tail' 'C' '| wc -l' ) # }}} # GPG / SSH agents {{{ # ==================== #function _gpg-agent-update-tty #{ # gpg-connect-agent UPDATESTARTUPTTY /bye >/dev/null #} # #add-zsh-hook preexec _gpg-agent-update-tty # }}} # vim: fdm=marker