This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / tools / zsh.nix
6.1 kB 201 lines
1{ ... }: 2{ 3 perSystem = 4 { pkgs, ... }: 5 let 6 zshrc = '' 7 autoload -U compinit && compinit 8 9 # Setup custom interactive shell init stuff. 10 # Bind gpg-agent to this TTY if gpg commands are used. 11 export GPG_TTY=$(tty) 12 13 # show how long a command takes 14 ZSH_COMMAND_TIME_MIN_SECONDS=3 15 ZSH_COMMAND_TIME_EXCLUDE=(vim) 16 ZSH_COMMAND_TIME_MSG="took: %s sec" 17 source ${ 18 pkgs.fetchFromGitHub { 19 owner = "popstas"; 20 repo = "zsh-command-time"; 21 rev = "803d26eef526bff1494d1a584e46a6e08d25d918"; 22 hash = "sha256-ndHVFcz+XmUW0zwFq7pBXygdRKyPLjDZNmTelhd5bv8="; 23 } 24 }/command-time.plugin.zsh 25 26 unsetopt nomatch # no matches found urls 27 setopt autocd extendedglob 28 bindkey -e 29 30 #C-x C-e open line in editor 31 autoload -z edit-command-line 32 zle -N edit-command-line 33 bindkey "^X^E" edit-command-line 34 35 #fzf inclusion 36 source ${pkgs.fzf}/share/fzf/completion.zsh 37 source ${pkgs.fzf}/share/fzf/key-bindings.zsh 38 39 # atuin distributed shell history 40 if type -p atuin >/dev/null; then 41 export ATUIN_CONFIG_DIR=${pkgs.writeTextDir "/config.toml" '' 42 auto_sync = true 43 update_check = false 44 sync_address = "http://green.r:8888" 45 sync_frequency = 0 46 style = "compact" 47 ''}; 48 export ATUIN_NOBIND="true" # disable all keybdinings of atuin 49 eval "$(${pkgs.atuin}/bin/atuin init zsh)" # TODO make this optional? 50 bindkey '^r' _atuin_search_widget # bind ctrl+r to atuin 51 # use zsh only session history 52 fc -p 53 fi 54 55 #completion magic 56 autoload -Uz compinit 57 compinit 58 zstyle ':completion:*' menu select 59 60 #enable automatic rehashing of $PATH 61 zstyle ':completion:*' rehash true 62 63 # fancy mv which interactively gets the second argument if not given 64 function mv() { 65 if [[ "$#" -ne 1 ]] || [[ ! -e "$1" ]]; then 66 command mv -v "$@" 67 return 68 fi 69 70 newfilename="$1" 71 vared newfilename 72 command mv -v -- "$1" "$newfilename" 73 } 74 75 #emacs bindings 76 bindkey "[7~" beginning-of-line 77 bindkey "[8~" end-of-line 78 bindkey "Oc" emacs-forward-word 79 bindkey "Od" emacs-backward-word 80 81 # direnv integration 82 eval "$(${pkgs.direnv}/bin/direnv hook zsh)" 83 84 # This function is called whenever a command is not found. 85 command_not_found_handler() { 86 local p='${pkgs.nix-index}/etc/profile.d/command-not-found.sh' 87 if [ -x "$p" ] && [ -f '/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite' ]; then 88 # Run the helper program. 89 "$p" "$@" 90 91 # Retry the command if we just installed it. 92 if [ $? = 126 ]; then 93 "$@" 94 else 95 return 127 96 fi 97 else 98 # Indicate than there was an error so ZSH falls back to its default handler 99 echo "$1: command not found" >&2 100 return 127 101 fi 102 } 103 104 download_nixpkgs_cache_index () { 105 filename="index-$(uname -m | sed 's/^arm64$/aarch64/')-$(uname | tr A-Z a-z)" 106 mkdir -p ~/.cache/nix-index && cd ~/.cache/nix-index 107 # -N will only download a new version if there is an update. 108 wget -q -N https://github.com/nix-community/nix-index-database/releases/latest/download/$filename 109 ln -f $filename files 110 } 111 112 # Setup aliases. 113 alias -- grep='grep --color=auto' 114 alias -- ip='ip -color=auto' 115 alias -- l='ls -alh' 116 alias -- la='ls -la' 117 alias -- ll='ls -l' 118 alias -- ls='ls --color' 119 alias -- ns='nix-shell --command zsh' 120 alias -- nb='nix build --no-link --print-out-paths -L' 121 alias -- ne='nix eval --strict --json' 122 123 # Setup prompt. 124 autoload -U promptinit 125 promptinit 126 127 p_error='%(?..%F{red}%?%f )' 128 t_error='%(?..%? )' 129 130 case $UID in 131 0) 132 p_username='%F{red}root%f' 133 t_username='root' 134 ;; 135 1337) 136 p_username="" 137 t_username="" 138 ;; 139 *) 140 p_username='%F{blue}%n%f' 141 t_username='%n' 142 ;; 143 esac 144 145 if test -n "$SSH_CLIENT"; then 146 p_hostname='@%F{magenta}%M%f ' 147 t_hostname='@%M ' 148 else 149 p_hostname="" 150 t_hostname="" 151 fi 152 153 #check if in nix shell 154 if test -n "$IN_NIX_SHELL"; then 155 p_nixshell='%F{green}[s]%f ' 156 t_nixshell='[s] ' 157 else 158 p_nixshell="" 159 t_nixshell="" 160 fi 161 162 PROMPT="$p_error$p_username$p_hostname$p_nixshell%~ " 163 TITLE="$t_error$t_username$t_hostname$t_nixshell%~" 164 case $TERM in 165 (*xterm* | *rxvt*) 166 function precmd { 167 PROMPT_EVALED=$(print -P "$TITLE") 168 echo -ne "\033]0;$$ $PROMPT_EVALED\007" 169 } 170 # This seems broken for some reason 171 # # This is seen while the shell waits for a command to complete. 172 # function preexec { 173 # PROMPT_EVALED=$(print -P "$TITLE") 174 # echo -ne "\033]0;$$ $PROMPT_EVALED $1\007" 175 # } 176 ;; 177 esac 178 179 180 # Disable some features to support TRAMP. 181 if [ "$TERM" = dumb ]; then 182 unsetopt zle prompt_cr prompt_subst 183 unset RPS1 RPROMPT 184 PS1='$ ' 185 PROMPT='$ ' 186 fi 187 ''; 188 in 189 { 190 packages.shell = pkgs.writeScriptBin "shell" '' 191 #!/bin/sh 192 export ZDOTDIR=${pkgs.writeTextDir "/.zshrc" zshrc} 193 exec ${pkgs.zsh}/bin/zsh "$@" 194 ''; 195 packages.zsh = pkgs.writeScriptBin "zsh" '' 196 #!/bin/sh 197 export ZDOTDIR=${pkgs.writeTextDir "/.zshrc" zshrc} 198 exec ${pkgs.zsh}/bin/zsh "$@" 199 ''; 200 }; 201}