dotfiles

My dotfiles.
git clone git://git.ryanmj.xyz/dotfiles.git
Log | Files | Refs | LICENSE

.zshrc (8452B)


      1 # For emacs TRAMP mode.
      2 if [[ $TERM == "tramp" || $TERM == "dumb" ]]; then
      3     unsetopt zle
      4     unsetopt prompt_cr
      5     PS1='$ '
      6     return
      7 fi
      8 
      9 # Fixes old versions of tmux
     10 if [[ -n "$TMUX" && $(tmux -V | awk '{print $2}' | head -c3) -lt "1.8" ]]
     11 then
     12         PROMPT_COMMAND="printf '\ePtmux;\e\e[<u\e\\'"
     13 fi
     14 
     15 # Shorthands for various modern linux paths
     16 MY_DATA_DIR="${XDG_DATA_HOME:-${HOME}/.local/share}"
     17 MY_CONF_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}"
     18 MY_CACHE_DIR="${XDG_CACHE_HOME:-${HOME}/.cache}"
     19 
     20 autoload -U colors && colors
     21 autoload -Uz vcs_info
     22 precmd() { vcs_info }
     23 
     24 # Key hash, for better keybinds.
     25 typeset -A key
     26 
     27 key[Home]=${terminfo[khome]}
     28 key[End]=${terminfo[kend]}
     29 key[Insert]=${terminfo[kich1]}
     30 key[Delete]=${terminfo[kdch1]}
     31 key[Up]=${terminfo[kcuu1]}
     32 key[Down]=${terminfo[kcud1]}
     33 key[Left]=${terminfo[kcub1]}
     34 key[Right]=${terminfo[kcuf1]}
     35 key[PageUp]=${terminfo[kpp]}
     36 key[PageDown]=${terminfo[knp]}
     37 
     38 
     39 # Change cursor shape for different vi modes.
     40 function zle-keymap-select {
     41   if [[ ${KEYMAP} == vicmd ]] ||
     42      [[ $1 = 'block' ]]; then
     43     echo -ne '\e[1 q'
     44   elif [[ ${KEYMAP} == main ]] ||
     45        [[ ${KEYMAP} == viins ]] ||
     46        [[ ${KEYMAP} = '' ]] ||
     47        [[ $1 = 'beam' ]]; then
     48     echo -ne '\e[5 q'
     49   fi
     50 }
     51 setopt PROMPT_SUBST
     52 
     53 ssh_info() {
     54   [[ "$SSH_CONNECTION" != '' ]] && echo '%(!.%{$fg[red]%}.%{$fg[yellow]%})%n%{$reset_color%}@%{$fg[green]%}%m%{$reset_color%}:' || echo ''
     55 }
     56 
     57 
     58 setopt autocd
     59 stty stop undef
     60 
     61 autoload -U compinit
     62 zstyle ':completion:*' menu select
     63 zmodload zsh/complist
     64 compinit
     65 #_comp_options+=(globdots)		# Include hidden files.
     66 
     67 # Ctrl-Arrow keys
     68 bindkey "^[[1;5C" forward-word
     69 bindkey "^[[1;5D" backward-word
     70 
     71 bindkey '^[[P' delete-char
     72 bindkey '^[[3~' delete-char 
     73 
     74 HISTSIZE=10000
     75 SAVEHIST=10000
     76 # Make sure to create this dir and touch history when installing on new system
     77 HISTFILE="$MY_CACHE_DIR/zsh/history"
     78 
     79 # Write to history immediately
     80 setopt inc_append_history
     81 # History shared among terminals
     82 setopt share_history
     83 # Save extended info in history
     84 setopt extended_history
     85 # Ignore duplicates
     86 setopt hist_ignoredups
     87 
     88 # Directory stack
     89 export DIRSTACKSIZE=9
     90 setopt autopushd pushdminus pushdsilent pushdtohome
     91 
     92 # Aliases for directory stack
     93 alias 1='cd -1'
     94 alias 2='cd -2'
     95 alias 3='cd -3'
     96 alias 4='cd -4'
     97 alias 5='cd -5'
     98 alias 6='cd -6'
     99 alias 7='cd -7'
    100 alias 8='cd -8'
    101 alias 9='cd -9'
    102 
    103 COMPLETION_WAITING_DOTS="true"
    104 
    105 zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
    106 
    107 
    108 #  en_US.UTF-8 UTF-8
    109 export DICPATH='/usr/share/hunspell'
    110 
    111 # Programming language globals.
    112 export LANG='en_US.UTF-8'
    113 export SCRIPTS="$HOME/src/dotfiles/scripts/:$HOME/src/scripts"
    114 export GOARCH="amd64"
    115 export GOOS="linux"
    116 export CC="gcc"
    117 export CXX="g++"
    118 export CGO_ENABLED="1"
    119 export GOROOT="/usr/lib/go"
    120 export GOBIN="$HOME/src/go/bin/"
    121 export GOPATH="$HOME/src/go/"
    122 export PATH="$PATH:$GOROOT/bin:/usr/lib/go/bin/:$SCRIPTS:$HOME/bin/:/home/ryan/.local/share/gem/ruby/3.0.0/bin:$HOME/.pub-cache/bin"
    123 
    124 [ -d "/mingw64/bin" ] && export PATH="$PATH:/mingw64/bin"
    125 [ -d "/mingw32/bin" ] && export PATH="$PATH:/mingw32/bin"
    126 
    127 # The HURD does not have /sbin in its path
    128 (uname -a | grep "gnu-mach" -qi) && export PATH="$PATH:/sbin"
    129 
    130 export MUSIC="$HOME/Music/"
    131 export TERMINAL='kitty-xterm'
    132 export BROWSER='brave'
    133 export COLORTERM='truecolor'
    134 export NODE_PATH="$HOME/src/node_modules"
    135 # TODO patch mednafen to use .config/ by default
    136 export MEDNAFEN_HOME="$MY_CONF_DIR/mednafen/"
    137 
    138 
    139 # Editor and zsh
    140 export EDITOR="emacsclient -t -a emacs"
    141 export VISUAL="emacsclient -c -a emacs"
    142 # Shortcuts to config files and folders
    143 alias cfk="$EDITOR $MY_CONF_DIR/kitty/kitty.conf "
    144 alias srz='source ~/.config/zsh/.zshrc'
    145 alias jrc='joe $MY_CONF_DIR/joestar/joestarrc'
    146 if type "nvim" &>/dev/null; then
    147     alias vim='nvim'
    148     alias cfv="nvim $MY_CONF_DIR/nvim/init.lua"
    149 else
    150     alias cfv="vim $HOME/.vimrc"
    151 fi
    152 alias cfz="$EDITOR $MY_CONF_DIR/zsh/.zshrc"
    153 alias cfe="$EDITOR $MY_CONF_DIR/emacs/init.el"
    154 # default options and shortcuts
    155 alias rip='abcde -o opus'
    156 alias ls='ls --hyperlink=auto --color -h --group-directories-first'
    157 alias lmk='latexmk -lualatex -synctex=1 -pvc'
    158 
    159 # Arch based vs debian based package manager aliases
    160 if type "pacman" &>/dev/null; then
    161     alias up='paru -Syu --noconfirm'
    162     alias pac='doas pacman -Syu --noconfirm'
    163     alias aur='paru -Syu --noconfirm'
    164     alias purge='doas pacman -R'
    165 elif type "apt" &>/dev/null; then
    166     alias up='doas apt-get update && doas apt-get upgrade'
    167     alias inst='doas apt-get install'
    168     alias purge='doas apt purge'
    169 fi
    170 
    171 alias redocmake='../; rm -rf bin; mkdir bin; cd bin; cmake .. -DCMAKE_BUILD_TYPE=debug'
    172 alias dosu='doas -u root -s'
    173 alias ll='ls -l'
    174 alias untar='tar -xvf'
    175 alias ztar='tar -cvJf'
    176 alias latex='lualatex'
    177 alias cls='clear'
    178 alias mkd='mkdir -pv'
    179 alias mkdir='mkdir -pv'
    180 alias dvdtube="youtube-dl -f 'bestvideo[height<=480,ext=mp4]+bestaudio/best[ext=mp3]/mp4'"
    181 alias youaud='youtube-dl --output "%(title)s.%(ext)s" --extract-audio --audio-format mp3 --audio-quality 0'
    182 alias otheru="youtube-dl -f 'bestvideo[height<=480,ext=mp4]+bestaudio[ext=mp3]/mp4' --write-all-thumbnails --merge-output-format mp4"
    183 alias you7="youtube-dl -f 'bestvideo[height<=720,ext=mp4]+bestaudio[ext=mp3]/mp4' --write-all-thumbnails --merge-output-format mp4"
    184 alias rm='rm -v'
    185 alias comicv='ls -v | sxiv -'
    186 alias ec='emacsclient -c'
    187 alias et='emacsclient -t'
    188 # Basically an alias for man
    189 
    190 # emacs aliases
    191 
    192 alias magit="emacsclient -t -e  '(progn (magit) (delete-other-windows))'"
    193 function man() {
    194     local command="$2($1)"
    195     [ -z $2 ] && command="$1"
    196     emacsclient -t -e '(man-mode-shell "'"$command"'")' || man "$@"
    197 }
    198 # Create a list of packages to install to move installations.
    199 function create_pkg_list() {
    200     pacman -Qqen > pac.lst
    201     pacman -Qqm > aur.lst
    202 }
    203 
    204 function eternity() {
    205     SDL_SOUNDFONTS=/usr/share/soundfonts/GeneralUser.sf2\
    206         SDL_FORCE_SOUNDFONTS=1\
    207         /usr/bin/eternity $@
    208 }
    209 
    210 function det() {
    211     local realargs=()
    212     for a in $@; do
    213         realargs+="/sudo::$a"
    214     done
    215 
    216     et $realargs
    217 }
    218 
    219 function shet() {
    220     local realargs=()
    221     for a in $@; do
    222         realargs+="/ssh:$1:${@:1}"
    223     done
    224 
    225     et $realargs
    226 }
    227 
    228 function dec() {
    229     local realargs=()
    230     for a in $@; do
    231         realargs+="/sudo::$a"
    232     done
    233 
    234     ec $realargs
    235 }
    236 
    237 function shec() {
    238     local realargs=()
    239     for a in $@; do
    240         realargs+="/ssh:$1:${@:2}"
    241     done
    242 
    243     echo "${@:2}"
    244 
    245     ec $realargs
    246 }
    247 
    248 
    249 setopt interactivecomments
    250 
    251 # Set up plugins and extensions.
    252 
    253 # Vterm
    254 source "${HOME}/.config/zsh/emacs-vterm-zsh.sh"
    255 
    256 # Zinit.
    257 if [ -d "/usr/share/zinit" ]; then
    258     source /usr/share/zinit/zinit.zsh 2>/dev/null
    259 else
    260     ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
    261     [ ! -d "$ZINIT_HOME" ] && mkdir -p "$(dirname $ZINIT_HOME)" && git clone 'https://github.com/zdharma-continuum/zinit.git' "$ZINIT_HOME"
    262     source "${ZINIT_HOME}/zinit.zsh"
    263 fi
    264 # If source zinit is under compload.
    265 autoload -Uz _zinit
    266 (( ${+_comps} )) && _comps[zinit]=_zinit
    267 
    268 zinit load "zdharma-continuum/fast-syntax-highlighting"
    269 # Must load after fast-syntax-highlighting
    270 zinit load "zsh-users/zsh-history-substring-search"
    271 
    272 # Vim mode.
    273 # The plugin will auto execute this zvm_after_lazy_keybindings function
    274 # This makes substring history search play nice with vim mode.
    275 function zvm_after_lazy_keybindings() {
    276     # TODO replace key sequence with "${key[Up]}"
    277     zvm_bindkey vicmd '^[[A' history-substring-search-up
    278     zvm_bindkey vicmd '^[[B' history-substring-search-down
    279     zvm_bindkey vicmd 'k' history-substring-search-up
    280     zvm_bindkey vicmd 'j' history-substring-search-down
    281 }
    282 # Zsh vi mode.
    283 zinit load "jeffreytse/zsh-vi-mode"
    284 # Also needed for substring history search
    285 zvm_define_widget history-substring-search-up
    286 zvm_define_widget history-substring-search-down
    287 zvm_bindkey viins '^[[A' history-substring-search-up
    288 zvm_bindkey viins '^[[B' history-substring-search-down
    289 
    290 # Zsh plugins to use oh-my-zsh themes
    291 zinit snippet "OMZL::spectrum.zsh"
    292 zinit snippet "OMZL::theme-and-appearance.zsh"
    293 zinit snippet "OMZL::git.zsh"
    294 zinit snippet "OMZP::mercurial"
    295 # oh-my-zsh theme
    296 zinit snippet "OMZT::/af-magic"
    297 
    298 
    299 # Load a few important annexes, without Turbo
    300 # (this is currently required for annexes)
    301 zinit light-mode for \
    302     zdharma-continuum/zinit-annex-as-monitor \
    303     zdharma-continuum/zinit-annex-bin-gem-node \
    304     zdharma-continuum/zinit-annex-patch-dl \
    305     zdharma-continuum/zinit-annex-rust
    306 
    307 ### End of Zinit's installer chunk