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 OpenAI
148export OPENAI_API_KEY="{{ onepasswordRead "op://Private/OpenAI API Token/password" }}"
149
150# Authenticate to local Radicle (.xyz) node
151export RAD_PASSWORD='{{ onepasswordRead "op://Private/2ujzijel6ni3np2uj5k5syptzm/password" }}'
152
153#HYPHEN_INSENSITIVE="true"
154# Uncomment the following line if pasting URLs and other text is messed up.
155# DISABLE_MAGIC_FUNCTIONS=true
156
157# Integrate z - jump around
158source /usr/share/z/z.sh
159
160# Integrate FZF
161source /usr/share/fzf/key-bindings.zsh
162source /usr/share/fzf/completion.zsh
163
164# Completions for git extras
165source /usr/share/doc/git-extras/git-extras-completion.zsh
166
167# Ranger conf
168export RANGER_LOAD_DEFAULT_RC=false
169
170# Bunch of aliases
171alias joe="joe-gitignore"
172alias ts="tailscale"
173alias tmateqr='tmate show-messages | tail -n 1 | qrencode -o - -t ANSIUTF8'
174alias info="info --vi-keys"
175alias datetime="date +%Y-%m-%d_%H%M%S_%Z"
176alias e="devour eval $EDITOR"
177alias u="linx-client"
178alias clip="xclip -selection clipboard"
179alias tmp="cd $(mktemp -d) && export TEMP=$(pwd)"
180alias send="rsync -amzzP"
181alias bat="bat -n --tabs 2"
182alias mov="joshuto ~/Bulk/Media/Movies"
183alias tv="joshuto ~/Bulk/Media/TV\ Shows"
184alias yt="joshuto ~/Bulk/Media/YouTube"
185alias erase="shred -vzfun 32"
186alias 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'"
187alias us="unsilence -t 15 -as 1.25"
188alias roll="roll -v"
189alias sxiv="sxiv -p"
190alias c="chezmoi"
191alias t="tea"
192alias j="just"
193alias ac="aicommits"
194alias tc="turbocommit"
195alias ai="sgpt"
196alias k="klog"
197alias ls="lsd"
198
199# Blog-related aliases
200alias secluded="cd ~/repos/personal/secluded && ./gen"
201alias drafts='e $(rg -l "draft: true" $HOME/repos/personal/secluded | fzf --preview "bat --color=always {}" --preview-window "~3")'
202
203# Custom functions
204function gi() {
205	curl -sLw https://www.toptal.com/developers/gitignore/api/$@ ;
206}
207
208sshedit() {
209	emulate -L zsh
210    setopt err_exit no_unset pipe_fail
211
212    local tmpdir=$(mktemp -d)
213    chmod 700 "$tmpdir"
214    pushd "$tmpdir" > /dev/null
215    local remote_host="$1"
216    local remote_file="$2"
217    local local_file="${remote_file:t}"  # ZSH way to get basename
218
219    rsync -az "${remote_host}:${remote_file}" "$local_file"
220    eval "$EDITOR $local_file"
221    rsync -az "$local_file" "${remote_host}:${remote_file}"
222    popd > /dev/null
223    rm -rf "$tmpdir"
224}
225
226# Navi integration
227_call_navi() {
228  local selected
229  if selected="$(printf "$(navi --print --path ${XDG_DATA_HOME}/navi/cheats </dev/tty)")"; then
230    LBUFFER="$selected"
231  fi
232  zle redisplay
233}
234zle -N _call_navi
235bindkey '^n' _call_navi
236
237zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate
238zstyle ':completion:*' group-name ''
239zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
240zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
241zstyle ':completion:*' menu select=1
242zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
243zstyle :compinstall filename '/home/amolith/.config/zsh/.zshrc'
244
245# Additional completions
246source $XDG_CONFIG_HOME/zsh/completions/charm.zsh
247source $XDG_CONFIG_HOME/zsh/completions/starship.zsh
248source $XDG_CONFIG_HOME/zsh/completions/antidot.zsh
249source $XDG_CONFIG_HOME/zsh/completions/klog.zsh
250source $XDG_CONFIG_HOME/zsh/completions/chezmoi.zsh
251source $XDG_CONFIG_HOME/zsh/completions/himalaya.zsh
252eval "$(op completion zsh)"; compdef _op op
253
254eval "$(starship init zsh)"
255
256precmd_functions=(zvm_init "${(@)precmd_functions:#zvm_init}")
257precmd_functions+=(set-long-prompt)
258zvm_after_init_commands+=("zle -N zle-line-finish; zle-line-finish() { set-short-prompt }")
259
260set-long-prompt() {
261    PROMPT=$(starship prompt)
262    RPROMPT=""
263}
264
265export COLUMNS=$(($COLUMNS + ($COLUMNS*0.1)))
266set-short-prompt() {
267    # setting this doesn't seem to actually work
268    PROMPT="$(STARSHIP_KEYMAP=${KEYMAP:-viins} starship module character)"
269    RPROMPT=$'%{\e[999C%}\e[8D%F{8}%*%f ' # remove if you don't want right prompt
270    zle .reset-prompt 2>/dev/null # hide the errors on ctrl+c
271}
272
273zle-keymap-select() {
274    set-short-prompt
275}
276zle -N zle-keymap-select
277
278zle-line-finish() { set-short-prompt }
279zle -N zle-line-finish
280
281trap 'set-short-prompt; return 130' INT
282
283# try to fix vi mode indication (not working 100%)
284zvm_after_init_commands+=('
285  function zle-keymap-select() {
286    if [[ ${KEYMAP} == vicmd ]] ||
287       [[ $1 = "block" ]]; then
288      echo -ne "\e[1 q"
289      STARSHIP_KEYMAP=vicmd
290    elif [[ ${KEYMAP} == main ]] ||
291         [[ ${KEYMAP} == viins ]] ||
292         [[ ${KEYMAP} = "" ]] ||
293         [[ $1 = "beam" ]]; then
294      echo -ne "\e[5 q"
295      STARSHIP_KEYMAP=viins
296    fi
297    zle reset-prompt
298  }
299  zle -N zle-keymap-select
300
301  # Ensure vi mode is set
302  zle-line-init() {
303    zle -K viins
304    echo -ne "\e[5 q"
305  }
306  zle -N zle-line-init
307')
308
309# Configure history file
310export HISTFILE="$XDG_STATE_HOME"/zsh/history
311export HISTSIZE=1000000
312export SAVEHIST=1000000
313
314autoload -Uz compinit && compinit
315autoload -U +X bashcompinit && bashcompinit
316
317compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-"$ZSH_VERSION"