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