diff options
Diffstat (limited to 'config/zsh/zshrc.nix')
-rw-r--r-- | config/zsh/zshrc.nix | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/config/zsh/zshrc.nix b/config/zsh/zshrc.nix new file mode 100644 index 000000000000..e7553d63d873 --- /dev/null +++ b/config/zsh/zshrc.nix @@ -0,0 +1,195 @@ +{ stdenv, lib + +, coreutils +, zsh-autosuggestions +, zsh-history-substring-search +, zsh-nix-shell +, zsh-syntax-highlighting + + }: + +let + options = { + # Completion + always_to_end = true; + auto_name_dirs = true; + complete_in_word = true; + list_packed = true; + + # Expansion and Globbing + bad_pattern = true; + brace_ccl = true; + extended_glob = true; + equals = true; + glob_star_short = true; + magic_equal_subst = true; + rc_expand_param = true; + rematch_pcre = true; + + # Input/Output + correct = true; + mail_warning = true; + rc_quotes = true; + rm_star_wait = true; + short_loops = true; + + # History + share_history = true; + bang_hist = true; + hist_allow_clobber = true; + hist_beep = true; + hist_expire_dups_first = true; + hist_ignore_dups = true; + hist_ignore_space = true; + hist_no_store = true; + hist_reduce_blanks = true; + + # Prompting + prompt_sp = true; + + # Scripts and Functions + c_bases = true; + c_precedences = true; + octal_zeroes = true; + }; + + enabledOptions = lib.attrNames (lib.filterAttrs (_: lib.id) options); + disabledOptions = lib.attrNames (lib.filterAttrs (_: v: !v) options); + +in '' + +. ${<nixpkgs/nixos/modules/programs/zsh/zinputrc>} + +# Disable silver searcher numbers when piped or redirected. +ag() { + if ! [ -t 1 ]; then + command ag --no-numbers "$@" + else + command ag "$@" + fi +} + +fzf_ctrl_t() { + if git rev-parse >/dev/null 2>&1; then + git ls-files -co --exclude-standard + else + find . -type f | sed 's/^\.\///g' + fi +} + +HISTFILE="$XDG_DATA_HOME/zsh/history" +REPORTTIME=5 +SAVEHIST=9000 +ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets) + +${lib.optionalString (enabledOptions == []) + "setopt ${lib.concatStringsSep " " enabledOptions}"} + +${lib.optionalString (disabledOptions == []) + "unsetopt ${lib.concatStringsSep " " enabledOptions}"} + +autoload -Uz colors && colors + +zstyle ':completion::complete:*' use-cache on +zstyle ':completion::complete:*' cache-path "$XDG_CACHE_DIR/zsh/zcompcache" +zstyle ':completion:*' auto-description '%d' +zstyle ':completion:*' completer _expand _complete _ignored _match _correct \ + _approximate _prefix +zstyle ':completion:*' expand suffix +zstyle ':completion:*' group-name ''' +zstyle ':completion:*' insert-unambiguous true +zstyle ':completion:*' list-colors ''' +zstyle ':completion:*' list-suffixes true +zstyle ':completion:*' matcher-list \ + 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' \ + 'r:|[._-/]=* r:|=*' 'l:|=* r:|=*' +zstyle ':completion:*' menu select=1 +zstyle ':completion:*' original false +zstyle ':completion:*' preserve-prefix '//[^/]##/' +zstyle ':completion:*' select-prompt \ + %SScrolling active: current selection at %p%s +zstyle ':completion:*' squeeze-slashes true +zstyle ':completion:*' use-compctl true +zstyle ':completion:*' verbose true + +autoload -U url-quote-magic +zle -N self-insert url-quote-magic + +autoload -Uz compinit +compinit -d "$XDG_CACHE_HOME/zsh/zcompdump" + +source ${zsh-nix-shell}/share/zsh-nix-shell/nix-shell.plugin.zsh +source ${zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh +source ${zsh-history-substring-search}/share/zsh-history-substring-search/zsh-history-substring-search.zsh +source ${zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh + +zmodload zsh/complist +bindkey -M menuselect "^[[Z" reverse-menu-complete + +zmodload zsh/terminfo +bindkey "^[[A" history-substring-search-up +bindkey "^[[B" history-substring-search-down + +bindkey "^[[3~" delete-char +bindkey "^[[F" end-of-line +bindkey "^[[H" beginning-of-line +bindkey "^[[1~" beginning-of-line +bindkey "^[[4~" end-of-line +bindkey "^[^[[C" forward-word +bindkey "^[^[[D" backward-word + +if [ -n "$TMUX" ]; then + tmux-page-up() { tmux copy-mode -ue } + tmux-page-down() { tmux send-keys -X page-down 2>/dev/null } + zle -N tmux-page-up + zle -N tmux-page-down + bindkey "^[[5~" tmux-page-up + bindkey "^[[6~" tmux-page-down +fi + +autoload -U edit-command-line +zle -N edit-command-line +bindkey "^x^e" edit-command-line + +if [[ -v TMUX ]]; then + _tmux_hook() { + local exit_status="$?" + tmux set-environment "last_exit_status_$(tmux display-message -p '#D')" "$exit_status" + tmux refresh-client -S + } + + typeset -ag precmd_functions; + if [[ -z $${precmd_functions[(r)_tmux_hook]} ]]; then + precmd_functions+=_tmux_hook; + fi +fi + +${lib.optionalString stdenv.isDarwin '' + # Load SSH passphrases from the Keychain. + # Use an explicit path because upstream OpenSSH + # doesn't have the keychain functionality. + (/usr/bin/ssh-add -A &) 2> /dev/null +''} + +if command -v fzf-share >/dev/null; then + source "$(fzf-share)/key-bindings.zsh" +fi + +# Aliases +alias beep='printf "\a"' +alias ls=${lib.escapeShellArg (if stdenv.isDarwin then + "/bin/ls -AFh" + else + "${coreutils}/bin/ls -AF --si --color=auto")} +alias tree='tree -aRF -I .git' +alias vim=nvim + +for command in cargo curl dig find git mutt ri wget; do + alias "$command=noglob $command" +done + +# Prompt +nl=$'\n' +PS1="%F{yellow}%(?..[exit %?]$nl)''${IN_NIX_SHELL+[nix-shell''${NIX_SHELL_PACKAGES:+($NIX_SHELL_PACKAGES)}] }%1(j.[%j job%2(j.s.)] .)%f%# " + +'' |