zshrc (5767B)
1 2 # For emacs TRAMP mode. 3 if [[ $TERM == "tramp" ]]; then 4 unsetopt zle 5 unsetopt prompt_cr 6 PS1='$ ' 7 return 8 fi 9 10 # Fixes old versions of tmux 11 if [[ -n "$TMUX" && $(tmux -V | awk '{print $2}' | head -c3) -lt "1.8" ]] 12 then 13 PROMPT_COMMAND="printf '\ePtmux;\e\e[<u\e\\'" 14 fi 15 16 autoload -U colors && colors 17 autoload -Uz vcs_info 18 precmd() { vcs_info } 19 20 setopt PROMPT_SUBST 21 22 ssh_info() { 23 [[ "$SSH_CONNECTION" != '' ]] && echo '%(!.%{$fg[red]%}.%{$fg[yellow]%})%n%{$reset_color%}@%{$fg[green]%}%m%{$reset_color%}:' || echo '' 24 } 25 26 color_codes=(1 2 4 5 6 9 10 12 13 14) 27 28 29 color_code_from_str() { 30 local h=$(sum <<< "$1" | cut -f1 -d' ') 31 local i=$((h % ${#color_codes})) 32 printf ${color_codes[i]} 33 } 34 35 36 user="%F{$(color_code_from_str "$USER")}%n" 37 host="%F{$(color_code_from_str "$HOST")}%m" 38 PROMPT='%(?.%F{243}.%F{red})%U${(l:COLUMNS:: :)?}%u 39 %B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[blue]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b ' 40 41 function check_last_exit_code() { 42 local LAST_EXIT_CODE=$? 43 if [[ $LAST_EXIT_CODE -ne 0 ]]; then 44 local EXIT_CODE_PROMPT=' ' 45 EXIT_CODE_PROMPT+="%{$fg[red]%}-%{$reset_color%}" 46 EXIT_CODE_PROMPT+="%{$fg_bold[red]%}$LAST_EXIT_CODE%{$reset_color%}" 47 EXIT_CODE_PROMPT+="%{$fg[red]%}-%{$reset_color%}" 48 echo "$EXIT_CODE_PROMPT" 49 fi 50 } 51 52 # TODO make this better 53 function git_prompt_string() { 54 stat .git &>/dev/null && git status | head -n1 | awk '{print $3}' 55 } 56 57 RPROMPT='$(git_prompt_string)' 58 59 setopt autocd 60 stty stop undef 61 62 autoload -U compinit 63 zstyle ':completion:*' menu select 64 zmodload zsh/complist 65 compinit 66 #_comp_options+=(globdots) # Include hidden files. 67 68 # Ctrl-Arrow keys 69 bindkey "^[[1;5C" forward-word 70 bindkey "^[[1;5D" backward-word 71 72 bindkey '^[[P' delete-char 73 bindkey '^[[3~' delete-char 74 75 HISTSIZE=10000 76 SAVEHIST=10000 77 # Make sure to create this dir and touch history when installing on new system 78 HISTFILE=~/.cache/zsh/history 79 80 # Write to history immediately 81 setopt inc_append_history 82 # History shared among terminals 83 setopt share_history 84 # Save extended info in history 85 setopt extended_history 86 # Ignore duplicates 87 setopt hist_ignoredups 88 89 # Directory stack 90 export DIRSTACKSIZE=9 91 setopt autopushd pushdminus pushdsilent pushdtohome 92 93 # Aliases for directory stack 94 alias 1='cd -1' 95 alias 2='cd -2' 96 alias 3='cd -3' 97 alias 4='cd -4' 98 alias 5='cd -5' 99 alias 6='cd -6' 100 alias 7='cd -7' 101 alias 8='cd -8' 102 alias 9='cd -9' 103 104 COMPLETION_WAITING_DOTS="true" 105 106 # Reload piwal theme 107 [[ -v SSH_CLIENT ]] || (cat ~/.cache/wal/sequences &) 108 109 zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' 110 111 112 # en_US.UTF-8 UTF-8 113 export DICPATH='/usr/share/hunspell' 114 115 # Programming language globals. 116 export LANG='en_US.UTF-8' 117 export SCRIPTS="$HOME/src/dotfiles/scripts/" 118 export GOARCH="amd64" 119 export GOOS="linux" 120 export CC="gcc" 121 export CXX="g++" 122 export CGO_ENABLED="1" 123 export GOROOT="/usr/lib/go" 124 export GOBIN="$HOME/src/goproj/bin/" 125 export GOPATH="$HOME/src/goproj/" 126 export PATH="$PATH:$GOROOT/bin:/usr/lib/go/bin/:$SCRIPTS:$HOME/bin/" 127 128 # The HURD does have /sbin in its path 129 (uname -a | grep "gnu-mach" -qi) && export PATH="$PATH:/sbin" 130 131 export MUSIC="$HOME/Music/" 132 export TERMINAL='xterm-256color' 133 export TERM='xterm-256color' 134 export BROWSER='brave' 135 export COLORTERM='truecolor' 136 export NODE_PATH="$HOME/src/node_modules" 137 export MEDNAFEN_HOME="$HOME/.config/mednafen/" 138 139 140 # Editor and zsh 141 export EDITOR="emacsclient -t -a emacs" 142 export VISUAL="emacsclient -c -a emacs" 143 144 alias srz='source ~/.zshrc' 145 alias jrc='joe $HOME/.config/joestar/joestarrc' 146 alias vim='nvim' 147 alias cfz="$EDITOR $HOME/.zshrc" 148 alias cfe="$EDITOR $HOME/.config/emacs/config.org $HOME/.config/emacs/init.el" 149 alias jrd='joe -rdonly' 150 # default options and shortcuts 151 alias rip='abcde -o opus' 152 alias ls='ls --color -h --group-directories-first' 153 154 # Arch based vs debian based package manager aliases 155 if type "pacman" &>/dev/null; then 156 alias up='paru -Syu' 157 alias pac='doas pacman -Syu' 158 alias aur='paru -Syu' 159 alias purge='doas pacman -R' 160 elif type "apt" &>/dev/null; then 161 alias up='doas apt-get update && doas apt-get upgrade' 162 alias inst='doas apt-get install' 163 alias purge='doas apt purge' 164 fi 165 166 alias dosu='doas -u root -s' 167 alias untar='tar -xvf' 168 alias ztar='tar -cvJf' 169 alias latex='lualatex' 170 alias cls='clear' 171 alias mkd='mkdir -pv' 172 alias mkdir='mkdir -pv' 173 alias dvdtube="youtube-dl -f 'bestvideo[height<=480,ext=mp4]+bestaudio/best[ext=mp3]/mp4'" 174 alias youaud='youtube-dl --output "%(title)s.%(ext)s" --extract-audio --audio-format mp3 --audio-quality 0' 175 alias otheru="youtube-dl -f 'bestvideo[height<=480,ext=mp4]+bestaudio[ext=mp3]/mp4' --write-all-thumbnails --merge-output-format mp4" 176 alias you7="youtube-dl -f 'bestvideo[height<=720,ext=mp4]+bestaudio[ext=mp3]/mp4' --write-all-thumbnails --merge-output-format mp4" 177 alias rm='rm -v' 178 # Shortcuts to config files and folders 179 alias i3cfg='joe ~/.config/i3/config' 180 alias jrz='joe ~/.zshrc' 181 alias comicv='ls -v | sxiv -' 182 alias ec='emacsclient -c' 183 alias et='emacsclient -t' 184 # Basically an alias for man 185 function man() { 186 local command="$2($1)" 187 [ -z $2 ] && command="$1" 188 emacsclient -t -e '(man-mode-shell "'"$command"'")' || man "$@" 189 } 190 191 # Emacs vterm 192 if [[ "$INSIDE_EMACS" = 'vterm' ]]; then 193 alias clear='vterm_printf "51;Evterm-clear-scrollback";tput clear' 194 fi 195 196 setopt interactivecomments 197 198 setopt HIST_IGNORE_ALL_DUPS 199 autoload -U history-search-end 200 zle -N history-beginning-search-backward-end history-search-end 201 zle -N history-beginning-search-forward-end history-search-end 202 bindkey "^[[A" history-beginning-search-backward-end 203 bindkey "^[[B" history-beginning-search-forward-end 204 unset HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND 205 206 source /usr/share/zsh/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh 2>/dev/null