{ stdenv, lib , any-nix-shell , direnv , zsh-autosuggestions , zsh-history-substring-search , 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 = false; 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=~/state/zsh/history HISTSIZE=10000 REPORTTIME=5 SAVEHIST=9000 ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets) ${lib.optionalString (enabledOptions != []) "setopt ${lib.concatStringsSep " " enabledOptions}"} ${lib.optionalString (disabledOptions != []) "unsetopt ${lib.concatStringsSep " " disabledOptions}"} 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" eval "$(${any-nix-shell}/bin/any-nix-shell zsh --info-right)" eval "$(${direnv}/bin/direnv hook 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 df='df -h' alias gdb='gdb -q' alias ip='ip -c=auto' alias ls=${lib.escapeShellArg (if stdenv.isDarwin then "ls -AFh" else "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 PS1="%F{yellow}%1(j.&%j .)%f%# " if tput hs then _tsl="$(tput tsl)" _fsl="$(tput fsl)" set_title() { echo -n "$_tsl$1$_fsl" } else set_title() {} fi preexec() { show_exit=1 set_title "$([ -n "$SSH_TTY" ] && hostname && printf ": ")$TTY: $2" } precmd() { local ex="$?" if [[ -n "$show_exit" && "$ex" -ne 0 ]] then echo -e "\r\e[33m[exit $ex]\e[0m" fi unset show_exit set_title "$TTY: $ZSH_NAME" } ''