private_dot_zshrc.tmpl

  1# Theming
  2{{- if eq .theme_variant "dark" }}
  3# https://github.com/catppuccin/zsh-syntax-highlighting
  4source ~/.config/zsh/themes/everforest-hard-dark.zsh
  5export BAT_THEME="ansi"
  6{{- end }}
  7{{- if eq .theme_variant "light" }}
  8# https://github.com/catppuccin/zsh-syntax-highlighting
  9source ~/.config/zsh/themes/everforest-soft-light.zsh
 10export BAT_THEME="ansi"
 11{{- end }}
 12
 13# Remove older command from the history if a duplicate is to be added.
 14setopt HIST_IGNORE_ALL_DUPS
 15# Prompt for spelling correction of commands.
 16setopt CORRECT
 17# Customize spelling correction prompt.
 18SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
 19# Remove path separator from WORDCHARS.
 20WORDCHARS=${WORDCHARS//[\/]}
 21# Use degit instead of git as the default tool to install and update modules.
 22zstyle ':zim:zmodule' use 'degit'
 23# Set a custom prefix for the generated aliases. The default prefix is 'G'.
 24#zstyle ':zim:git' aliases-prefix 'g'
 25# Append `../` to your input for each `.` you type after an initial `..`
 26zstyle ':zim:input' double-dot-expand no
 27# Set a custom terminal title format using prompt expansion escape sequences.
 28# See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Simple-Prompt-Escapes
 29# If none is provided, the default '%n@%m: %~' is used.
 30zstyle ':zim:termtitle' hooks 'preexec' 'precmd'
 31zstyle ':zim:termtitle:preexec' format '${${(A)=1}[1]}'
 32zstyle ':zim:termtitle:precmd'  format '%1~'
 33# Customize the style that the suggestions are shown with.
 34# Set what highlighters will be used.
 35# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
 36ZSH_HIGHLIGHT_HIGHLIGHTERS=(main cursor)
 37# Customize the main highlighter styles.
 38# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md#how-to-tweak-it
 39typeset -gA ZSH_HIGHLIGHT_STYLES
 40
 41# XDG variables
 42export XDG_DATA_HOME="$HOME/.local/share"
 43export XDG_CONFIG_HOME="$HOME/.config"
 44export XDG_STATE_HOME="$HOME/.local/state"
 45export XDG_CACHE_HOME="$HOME/.cache"
 46export XDG_BIN_HOME="$HOME/.local/bin"
 47
 48# Moving dotfiles around
 49zstyle ':completion:*' cache-path "$XDG_CACHE_HOME"/zsh/zcompcache
 50export ZDOTDIR="$HOME"/.config/zsh
 51export WINEPREFIX="$XDG_DATA_HOME"/wine
 52export WORKON_HOME="$XDG_DATA_HOME/virtualenvs"
 53export SQLITE_HISTORY="$XDG_CACHE_HOME"/sqlite_history
 54export BUNDLE_USER_CONFIG="$XDG_CONFIG_HOME"/bundle
 55export BUNDLE_USER_CACHE="$XDG_CACHE_HOME"/bundle
 56export BUNDLE_USER_PLUGIN="$XDG_DATA_HOME"/bundle
 57export NUGET_PACKAGES="$XDG_CACHE_HOME"/NuGetPackages
 58export DVDCSS_CACHE="$XDG_DATA_HOME"/dvdcss
 59export KDEHOME="$XDG_CONFIG_HOME"/kde
 60export GOPATH="$XDG_DATA_HOME"/go
 61export ZIM_HOME="$XDG_CONFIG_HOME"/.zim
 62export GHCUP_USE_XDG_DIRS="ishouldjustbeabletoexportthisnotsetit"
 63alias wget=wget --hsts-file="$XDG_DATA_HOME/wget-hsts"
 64alias svn="svn --config-dir $XDG_CONFIG_HOME/subversion"
 65
 66# ------------------
 67# Initialize modules
 68# ------------------
 69if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then
 70  # Download zimfw script if missing.
 71  command mkdir -p ${ZIM_HOME}
 72  if (( ${+commands[curl]} )); then
 73    command curl -fsSL -o ${ZIM_HOME}/zimfw.zsh https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
 74  else
 75    command wget -nv -O ${ZIM_HOME}/zimfw.zsh https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
 76  fi
 77fi
 78if [[ ! ${ZIM_HOME}/init.zsh -nt ${ZDOTDIR:-${HOME}}/.zimrc ]]; then
 79  # Install missing modules, and update ${ZIM_HOME}/init.zsh if missing or outdated.
 80  source ${ZIM_HOME}/zimfw.zsh init -q
 81fi
 82source ${ZIM_HOME}/init.zsh
 83
 84# ------------------------------
 85# Post-init module configuration
 86# ------------------------------
 87
 88# Bind ^[[A/^[[B manually so up/down works both before and after zle-line-init
 89bindkey '^[[A' history-substring-search-up
 90bindkey '^[[B' history-substring-search-down
 91
 92# Bind up and down keys
 93zmodload -F zsh/terminfo +p:terminfo
 94if [[ -n ${terminfo[kcuu1]} && -n ${terminfo[kcud1]} ]]; then
 95  bindkey ${terminfo[kcuu1]} history-substring-search-up
 96  bindkey ${terminfo[kcud1]} history-substring-search-down
 97fi
 98
 99bindkey '^P' history-substring-search-up
100bindkey '^N' history-substring-search-down
101bindkey -M vicmd 'k' history-substring-search-up
102bindkey -M vicmd 'j' history-substring-search-down
103# End configuration added by Zim install
104
105# Ruby crap
106eval "$(rbenv init - zsh)"
107export GEM_HOME="$(gem env user_gemhome)"
108export PATH="$PATH:$GEM_HOME/bin"
109eval "$(rbenv init -)"
110
111# Android crap
112export ANDROID_HOME="$XDG_DATA_HOME/Android"
113export ANDROID_SDK_ROOT="$ANDROID_HOME"
114export PATH="$PATH:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator"
115
116# Executable paths
117export PATH="$PATH:$XDG_CONFIG_HOME/emacs/bin"
118export PATH="$PATH:$HOME/.gem/ruby/3.0.0/bin"
119export PATH="$PATH:$GOPATH/bin"
120export PATH="$PATH:$CACHE/yay/distrobox/pkg/distrobox/usr/bin"
121export PATH="$PATH:$XDG_DATA_HOME/cargo/bin"
122export PATH="$PATH:$HOME/.radicle/bin"
123export PATH="$HOME/.local/bin:$PATH"
124export PATH="$PATH:/usr/lib/kf6"
125export PATH="$PATH:/usr/lib/kf5"
126
127# Additional preferences
128export LANG=en_GB.UTF-8
129export EDITOR="zeditor --wait"
130export VISUAL="$EDITOR"
131export _JAVA_AWT_WM_NONREPARENTING=1
132export MANPAGER="nvim +Man!"
133export COLUMNS=80
134export MANWIDTH=80
135export CHARM_HOST=charm.secluded.site
136export RIPGREP_CONFIG_PATH="$HOME/.config/ripgreprc"
137
138# Partially in response to https://sourcehut.org/blog/2023-01-09-gomodulemirror/
139# Partially because GOPROXY bad
140export GOPROXY=direct
141
142CASE_SENSITIVE="false"
143
144# Disable dumb Python keyring integration
145export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
146
147# Authenticate to local Radicle (.xyz) node
148export RAD_PASSWORD='{{ onepasswordRead "op://Private/2ujzijel6ni3np2uj5k5syptzm/password" }}'
149
150export JIRA_API_TOKEN='{{ onepasswordRead "op://Private/Atlassian/jira key" }}'
151
152#HYPHEN_INSENSITIVE="true"
153# Uncomment the following line if pasting URLs and other text is messed up.
154# DISABLE_MAGIC_FUNCTIONS=true
155
156# Integrate z - jump around
157source /usr/share/z/z.sh
158
159# Integrate FZF
160source /usr/share/fzf/key-bindings.zsh
161source /usr/share/fzf/completion.zsh
162
163# Completions for git extras
164source /usr/share/doc/git-extras/git-extras-completion.zsh
165
166# Ranger conf
167export RANGER_LOAD_DEFAULT_RC=false
168
169# Bunch of aliases
170alias joe="joe-gitignore"
171alias ts="tailscale"
172alias tmateqr='tmate show-messages | tail -n 1 | qrencode -o - -t ANSIUTF8'
173alias info="info --vi-keys"
174alias datetime="date +%Y-%m-%d_%H%M%S_%Z"
175alias e="devour eval $EDITOR"
176alias u="linx-client"
177alias clip="xclip -selection clipboard"
178alias tmp="cd $(mktemp -d) && export TEMP=$(pwd)"
179alias send="rsync -amzzP"
180alias bat="bat -n --tabs 2"
181alias mov="joshuto ~/Bulk/Media/Movies"
182alias tv="joshuto ~/Bulk/Media/TV\ Shows"
183alias yt="joshuto ~/Bulk/Media/YouTube"
184alias erase="shred -vzfun 32"
185alias dl="yt-dlp --write-sub --write-auto-sub --sub-lang en --sub-format srt/best --convert-subs srt --embed-subs -o '%(upload_date)s %(title)s.%(ext)s'"
186alias us="unsilence -t 15 -as 1.25"
187alias roll="roll -v"
188alias sxiv="sxiv -p"
189alias c="chezmoi"
190alias t="tea"
191alias j="just"
192alias ac="aicommits"
193alias tc="turbocommit"
194alias ai="sgpt"
195alias k="klog"
196alias ls="lsd"
197
198# Blog-related aliases
199alias secluded="cd ~/repos/personal/secluded && ./gen"
200alias drafts='e $(rg -l "draft: true" $HOME/repos/personal/secluded | fzf --preview "bat --color=always {}" --preview-window "~3")'
201
202# Custom functions
203function gi() {
204	curl -sLw https://www.toptal.com/developers/gitignore/api/$@ ;
205}
206
207sshedit() {
208	emulate -L zsh
209    setopt err_exit no_unset pipe_fail
210
211    local tmpdir=$(mktemp -d)
212    chmod 700 "$tmpdir"
213    pushd "$tmpdir" > /dev/null
214    local remote_host="$1"
215    local remote_file="$2"
216    local local_file="${remote_file:t}"  # ZSH way to get basename
217
218    rsync -az "${remote_host}:${remote_file}" "$local_file"
219    eval "$EDITOR $local_file"
220    rsync -az "$local_file" "${remote_host}:${remote_file}"
221    popd > /dev/null
222    rm -rf "$tmpdir"
223}
224
225# Navi integration
226_call_navi() {
227  local selected
228  if selected="$(printf "$(navi --print --path ${XDG_DATA_HOME}/navi/cheats </dev/tty)")"; then
229    LBUFFER="$selected"
230  fi
231  zle redisplay
232}
233zle -N _call_navi
234bindkey '^n' _call_navi
235
236zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate
237zstyle ':completion:*' group-name ''
238zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
239zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
240zstyle ':completion:*' menu select=1
241zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
242zstyle :compinstall filename '/home/amolith/.config/zsh/.zshrc'
243
244# Additional completions
245source $XDG_CONFIG_HOME/zsh/completions/charm.zsh
246source $XDG_CONFIG_HOME/zsh/completions/starship.zsh
247source $XDG_CONFIG_HOME/zsh/completions/antidot.zsh
248source $XDG_CONFIG_HOME/zsh/completions/klog.zsh
249source $XDG_CONFIG_HOME/zsh/completions/chezmoi.zsh
250source $XDG_CONFIG_HOME/zsh/completions/himalaya.zsh
251eval "$(op completion zsh)"; compdef _op op
252
253eval "$(starship init zsh)"
254
255precmd_functions=(zvm_init "${(@)precmd_functions:#zvm_init}")
256precmd_functions+=(set-long-prompt)
257zvm_after_init_commands+=("zle -N zle-line-finish; zle-line-finish() { set-short-prompt }")
258
259set-long-prompt() {
260    PROMPT=$(starship prompt)
261    RPROMPT=""
262}
263
264export COLUMNS=$(($COLUMNS + ($COLUMNS*0.1)))
265set-short-prompt() {
266    # setting this doesn't seem to actually work
267    PROMPT="$(STARSHIP_KEYMAP=${KEYMAP:-viins} starship module character)"
268    RPROMPT=$'%{\e[999C%}\e[8D%F{8}%*%f ' # remove if you don't want right prompt
269    zle .reset-prompt 2>/dev/null # hide the errors on ctrl+c
270}
271
272zle-keymap-select() {
273    set-short-prompt
274}
275zle -N zle-keymap-select
276
277zle-line-finish() { set-short-prompt }
278zle -N zle-line-finish
279
280trap 'set-short-prompt; return 130' INT
281
282# try to fix vi mode indication (not working 100%)
283zvm_after_init_commands+=('
284  function zle-keymap-select() {
285    if [[ ${KEYMAP} == vicmd ]] ||
286       [[ $1 = "block" ]]; then
287      echo -ne "\e[1 q"
288      STARSHIP_KEYMAP=vicmd
289    elif [[ ${KEYMAP} == main ]] ||
290         [[ ${KEYMAP} == viins ]] ||
291         [[ ${KEYMAP} = "" ]] ||
292         [[ $1 = "beam" ]]; then
293      echo -ne "\e[5 q"
294      STARSHIP_KEYMAP=viins
295    fi
296    zle reset-prompt
297  }
298  zle -N zle-keymap-select
299
300  # Ensure vi mode is set
301  zle-line-init() {
302    zle -K viins
303    echo -ne "\e[5 q"
304  }
305  zle -N zle-line-init
306')
307
308# Configure history file
309export HISTFILE="$XDG_STATE_HOME"/zsh/history
310export HISTSIZE=1000000
311export SAVEHIST=1000000
312
313autoload -Uz compinit && compinit
314autoload -U +X bashcompinit && bashcompinit
315
316compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-"$ZSH_VERSION"