# Theming {{- if eq .theme_variant "dark" }} # https://github.com/catppuccin/zsh-syntax-highlighting source ~/.config/zsh/themes/everforest-hard-dark.zsh export BAT_THEME="ansi" {{- end }} {{- if eq .theme_variant "light" }} # https://github.com/catppuccin/zsh-syntax-highlighting source ~/.config/zsh/themes/everforest-soft-light.zsh export BAT_THEME="ansi" {{- end }} # Remove older command from the history if a duplicate is to be added. setopt HIST_IGNORE_ALL_DUPS # Prompt for spelling correction of commands. setopt CORRECT # Customize spelling correction prompt. SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? ' # Remove path separator from WORDCHARS. WORDCHARS=${WORDCHARS//[\/]} # Use degit instead of git as the default tool to install and update modules. zstyle ':zim:zmodule' use 'degit' # Set a custom prefix for the generated aliases. The default prefix is 'G'. #zstyle ':zim:git' aliases-prefix 'g' # Append `../` to your input for each `.` you type after an initial `..` zstyle ':zim:input' double-dot-expand no # Set a custom terminal title format using prompt expansion escape sequences. # See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Simple-Prompt-Escapes # If none is provided, the default '%n@%m: %~' is used. zstyle ':zim:termtitle' hooks 'preexec' 'precmd' zstyle ':zim:termtitle:preexec' format '${${(A)=1}[1]}' zstyle ':zim:termtitle:precmd' format '%1~' # Customize the style that the suggestions are shown with. # Set what highlighters will be used. # See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md ZSH_HIGHLIGHT_HIGHLIGHTERS=(main cursor) # Customize the main highlighter styles. # See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md#how-to-tweak-it typeset -gA ZSH_HIGHLIGHT_STYLES # XDG variables export XDG_DATA_HOME="$HOME/.local/share" export XDG_CONFIG_HOME="$HOME/.config" export XDG_STATE_HOME="$HOME/.local/state" export XDG_CACHE_HOME="$HOME/.cache" export XDG_BIN_HOME="$HOME/.local/bin" export NODE_PATH="$XDG_DATA_HOME/npm-packages/lib/node_modules" export PATH="$PATH:$XDG_DATA_HOME/npm-packages/bin" # Moving dotfiles around zstyle ':completion:*' cache-path "$XDG_CACHE_HOME"/zsh/zcompcache export ZDOTDIR="$HOME"/.config/zsh export WINEPREFIX="$XDG_DATA_HOME"/wine export WORKON_HOME="$XDG_DATA_HOME/virtualenvs" export SQLITE_HISTORY="$XDG_CACHE_HOME"/sqlite_history export BUNDLE_USER_CONFIG="$XDG_CONFIG_HOME"/bundle export BUNDLE_USER_CACHE="$XDG_CACHE_HOME"/bundle export BUNDLE_USER_PLUGIN="$XDG_DATA_HOME"/bundle export NUGET_PACKAGES="$XDG_CACHE_HOME"/NuGetPackages export DVDCSS_CACHE="$XDG_DATA_HOME"/dvdcss export KDEHOME="$XDG_CONFIG_HOME"/kde export GOPATH="$XDG_DATA_HOME"/go export ZIM_HOME="$XDG_CONFIG_HOME"/.zim export GHCUP_USE_XDG_DIRS="ishouldjustbeabletoexportthisnotsetit" alias wget=wget --hsts-file="$XDG_DATA_HOME/wget-hsts" alias svn="svn --config-dir $XDG_CONFIG_HOME/subversion" fpath=($XDG_CONFIG_HOME/zsh/completions $fpath) # ------------------ # Initialize modules # ------------------ if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then # Download zimfw script if missing. command mkdir -p ${ZIM_HOME} if (( ${+commands[curl]} )); then command curl -fsSL -o ${ZIM_HOME}/zimfw.zsh https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh else command wget -nv -O ${ZIM_HOME}/zimfw.zsh https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh fi fi if [[ ! ${ZIM_HOME}/init.zsh -nt ${ZDOTDIR:-${HOME}}/.zimrc ]]; then # Install missing modules, and update ${ZIM_HOME}/init.zsh if missing or outdated. source ${ZIM_HOME}/zimfw.zsh init -q fi source ${ZIM_HOME}/init.zsh # ------------------------------ # Post-init module configuration # ------------------------------ # Bind ^[[A/^[[B manually so up/down works both before and after zle-line-init bindkey '^[[A' history-substring-search-up bindkey '^[[B' history-substring-search-down # Bind up and down keys zmodload -F zsh/terminfo +p:terminfo if [[ -n ${terminfo[kcuu1]} && -n ${terminfo[kcud1]} ]]; then bindkey ${terminfo[kcuu1]} history-substring-search-up bindkey ${terminfo[kcud1]} history-substring-search-down fi bindkey '^P' history-substring-search-up bindkey '^N' history-substring-search-down bindkey -M vicmd 'k' history-substring-search-up bindkey -M vicmd 'j' history-substring-search-down # End configuration added by Zim install # Ruby crap eval "$(rbenv init - zsh)" export GEM_HOME="$(gem env user_gemhome)" export PATH="$PATH:$GEM_HOME/bin" eval "$(rbenv init -)" # Android crap export ANDROID_HOME="$XDG_DATA_HOME/Android" export ANDROID_SDK_ROOT="$ANDROID_HOME" export PATH="$PATH:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator" # Executable paths export PATH="$PATH:$XDG_CONFIG_HOME/emacs/bin" export PATH="$PATH:$HOME/.gem/ruby/3.0.0/bin" export PATH="$PATH:$GOPATH/bin" export PATH="$PATH:$CACHE/yay/distrobox/pkg/distrobox/usr/bin" export PATH="$PATH:$XDG_DATA_HOME/cargo/bin" export PATH="$PATH:$HOME/.radicle/bin" export PATH="$HOME/.local/bin:$PATH" export PATH="$PATH:/usr/lib/kf6" export PATH="$PATH:/usr/lib/kf5" # Additional preferences export LANG=en_GB.UTF-8 export EDITOR="zeditor --wait" export VISUAL="$EDITOR" export _JAVA_AWT_WM_NONREPARENTING=1 export MANPAGER="nvim +Man!" export COLUMNS=80 export MANWIDTH=80 export CHARM_HOST=charm.secluded.site export RIPGREP_CONFIG_PATH="$HOME/.config/ripgreprc" CASE_SENSITIVE="false" # Disable dumb Python keyring integration export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring #HYPHEN_INSENSITIVE="true" # Uncomment the following line if pasting URLs and other text is messed up. # DISABLE_MAGIC_FUNCTIONS=true # Ranger conf export RANGER_LOAD_DEFAULT_RC=false # Bunch of aliases alias joe="joe-gitignore" alias ts="tailscale" alias tmateqr='tmate show-messages | tail -n 1 | qrencode -o - -t ANSIUTF8' alias info="info --vi-keys" alias datetime="date +%Y-%m-%d_%H%M%S_%Z" alias u="linx-client" alias clip="xclip -selection clipboard" alias tmp="cd $(mktemp -d) && export TEMP=$(pwd)" alias send="rsync -amzzP" alias bat="bat -n --tabs 2" alias mov="joshuto ~/Bulk/Media/Movies" alias tv="joshuto ~/Bulk/Media/TV\ Shows" alias yt="joshuto ~/Bulk/Media/YouTube" alias erase="shred -vzfun 32" alias 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'" alias us="unsilence -t 15 -as 1.25" alias roll="roll -v" alias sxiv="sxiv -p" alias c="chezmoi" alias t="tea" alias j="just" alias k="klog" alias ls="lsd" # Blog-related aliases alias secluded="cd ~/repos/personal/secluded && ./gen" alias drafts='e $(rg -l "draft: true" $HOME/repos/personal/secluded | fzf --preview "bat --color=always {}" --preview-window "~3")' # Custom functions function gi() { curl -sLw https://www.toptal.com/developers/gitignore/api/$@ ; } sshedit() { emulate -L zsh setopt pipefail if [[ $# -lt 2 ]]; then echo "Usage: sshedit remote_host remote_file" >&2 return 1 fi local tmpdir=$(mktemp -d) chmod 700 "$tmpdir" # Define cleanup function function cleanup() { [[ $PWD == $tmpdir ]] && popd >/dev/null 2>&1 [[ -d "$tmpdir" ]] && rm -rf "$tmpdir" } # Set trap but don't use EXIT which might cause terminal closure trap cleanup INT TERM HUP pushd "$tmpdir" > /dev/null || { echo "Failed to enter temp directory"; return 1; } local remote_host="$1" local remote_file="$2" local local_file="${remote_file:t}" # ZSH way to get basename # Check ssh connection if ! ssh -q -o BatchMode=yes -o ConnectTimeout=5 "$remote_host" true; then echo "Error: Cannot connect to $remote_host" >&2 cleanup return 1 fi if ! ssh "$remote_host" "test -f '$remote_file'"; then echo -n "Remote file doesn't exist. Create it? [y/N] " >&2 read -q response || { echo "\nAborting" >&2; return 1 } echo ssh "$remote_host" "touch '$remote_file'" || { echo "Failed to create remote file" >&2 return 1 } fi # Download file if ! rsync -az "${remote_host}:${remote_file}" "$local_file"; then echo "Error: Failed to download the remote file" >&2 cleanup return 1 fi local before_checksum=$(sha256sum "$local_file" 2>/dev/null | awk '{print $1}') eval "${EDITOR:-vim}" "$local_file" local edit_status=$? if [[ $edit_status -ne 0 ]]; then echo "Editor exited with status $edit_status" >&2 cleanup return $edit_status fi local after_checksum=$(sha256sum "$local_file" 2>/dev/null | awk '{print $1}') if [[ "$before_checksum" != "$after_checksum" ]]; then if ! rsync -az "$local_file" "${remote_host}:${remote_file}"; then echo "Error: Failed to upload edited file" >&2 cleanup return 1 fi echo "File successfully updated on $remote_host" >&2 else echo "No changes made to file" >&2 fi cleanup trap - INT TERM HUP return 0 } # Navi integration _call_navi() { local selected if selected="$(printf "$(navi --print --path ${XDG_DATA_HOME}/navi/cheats /dev/null # hide the errors on ctrl+c } zle-keymap-select() { set-short-prompt } zle -N zle-keymap-select zle-line-finish() { set-short-prompt } zle -N zle-line-finish trap 'set-short-prompt; return 130' INT # try to fix vi mode indication (not working 100%) zvm_after_init_commands+=(' function zle-keymap-select() { if [[ ${KEYMAP} == vicmd ]] || [[ $1 = "block" ]]; then echo -ne "\e[1 q" STARSHIP_KEYMAP=vicmd elif [[ ${KEYMAP} == main ]] || [[ ${KEYMAP} == viins ]] || [[ ${KEYMAP} = "" ]] || [[ $1 = "beam" ]]; then echo -ne "\e[5 q" STARSHIP_KEYMAP=viins fi zle reset-prompt } zle -N zle-keymap-select # Ensure vi mode is set zle-line-init() { zle -K viins echo -ne "\e[5 q" } zle -N zle-line-init ') # Configure history file export HISTFILE="$XDG_STATE_HOME"/zsh/history export HISTSIZE=1000000 export SAVEHIST=1000000