diff options
author | Alyssa Ross <hi@alyssa.is> | 2019-02-10 19:59:18 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2019-02-10 19:59:18 +0000 |
commit | e0a178df252d6801108699fa07cd1ea494ebc12d (patch) | |
tree | 13217ea9caf3b75a9ff81351ee747d291a1a784a /modules/shell/zsh | |
parent | 2349ca0a596f73209c7491769879c065db513ca6 (diff) | |
download | nixlib-e0a178df252d6801108699fa07cd1ea494ebc12d.tar nixlib-e0a178df252d6801108699fa07cd1ea494ebc12d.tar.gz nixlib-e0a178df252d6801108699fa07cd1ea494ebc12d.tar.bz2 nixlib-e0a178df252d6801108699fa07cd1ea494ebc12d.tar.lz nixlib-e0a178df252d6801108699fa07cd1ea494ebc12d.tar.xz nixlib-e0a178df252d6801108699fa07cd1ea494ebc12d.tar.zst nixlib-e0a178df252d6801108699fa07cd1ea494ebc12d.zip |
config: give up on this experiment
This ended up being way more trouble than it was worth, and the approach just flat out didn't work for stuff like OpenSSH.
Diffstat (limited to 'modules/shell/zsh')
-rw-r--r-- | modules/shell/zsh/default.nix | 22 | ||||
-rw-r--r-- | modules/shell/zsh/zshrc.nix | 193 |
2 files changed, 215 insertions, 0 deletions
diff --git a/modules/shell/zsh/default.nix b/modules/shell/zsh/default.nix new file mode 100644 index 000000000000..d151e1434eca --- /dev/null +++ b/modules/shell/zsh/default.nix @@ -0,0 +1,22 @@ +{ pkgs, config, ... }: + +{ + environment.etc.zshrc.text = '' + unsetopt GLOBAL_RCS + + if [ -z "$__NIXOS_SET_ENVIRONMENT_DONE" ]; then + . ${config.system.build.setEnvironment} + fi + ''; + + environment.extraInit = '' + export ZDOTDIR="/etc/xdg/nixos/per-user/$USER/zsh" + ''; + + home.qyliss.dirs."state/zsh" = {}; + + xdg.config.users.qyliss.paths."zsh/.zshrc" = + with pkgs; writeText "zshrc" (callPackage ./zshrc.nix {}); + + environment.systemPackages = with pkgs; [ zsh nix-zsh-completions ]; +} diff --git a/modules/shell/zsh/zshrc.nix b/modules/shell/zsh/zshrc.nix new file mode 100644 index 000000000000..a91236d900cb --- /dev/null +++ b/modules/shell/zsh/zshrc.nix @@ -0,0 +1,193 @@ +{ 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=~/state/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%# " + +'' |