aboutsummaryrefslogtreecommitdiff
path: root/.config/zsh
diff options
context:
space:
mode:
Diffstat (limited to '.config/zsh')
-rw-r--r--.config/zsh/.zshenv237
-rw-r--r--.config/zsh/.zshrc566
2 files changed, 803 insertions, 0 deletions
diff --git a/.config/zsh/.zshenv b/.config/zsh/.zshenv
new file mode 100644
index 0000000..8d204c8
--- /dev/null
+++ b/.config/zsh/.zshenv
@@ -0,0 +1,237 @@
+# Load local/system wide binaries and scripts
+export PATH=$HOME/.bin:$HOME/.local/bin:$HOME/.local/bin/scripts:/usr/local/bin:/sbin:/usr/sbin:$PATH
+export PATH="/data/data/com.termux/files/usr/local/bin:$PATH"
+
+# Conditionally set WM(window manager)
+available_wms=("bspwm" "mutter" "i3")
+for wm in "${available_wms[@]}"; do
+ if command -v "$wm" &> /dev/null; then
+ export WM="$wm"
+ break
+ fi
+done
+
+# Conditionally set Display server
+if [ -n "$WAYLAND_DISPLAY" ]; then
+ export XDG_SESSION_TYPE=wayland
+else
+ export XDG_SESSION_TYPE=x11
+
+ # X11-specific variables
+ export XINITRC="$HOME/.config/X11/.xinitrc"
+ export XSERVERRC="$XDG_CONFIG_HOME/X11/xserverrc"
+ export USERXSESSION="$XDG_CONFIG_HOME/X11/xsession"
+ export USERXSESSIONRC="$XDG_CONFIG_HOME/X11/xsessionrc"
+ export ALTUSERXSESSION="$XDG_CONFIG_HOME/X11/Xsession"
+ export ERRFILE="$XDG_CONFIG_HOME/X11/xsession-errors"
+ export ICEAUTHORITY="$XDG_CACHE_HOME/.ICEauthority"
+fi
+
+available_terms=("wezterm" "alacritty" "xterm")
+
+for term in "${available_terms[@]}"; do
+ if command -v "$term" &> /dev/null; then
+ export TERMINAL="$term"
+ break
+ fi
+done
+
+# Default Programs:
+export EDITOR=$(command -v nvim || echo "vim")
+export VISUAL=$EDITOR
+export COLORTERM="truecolor"
+export TERM="xterm-256color"
+export READER="zathura"
+export BROWSER="firefox"
+export OPENER="xdg-open"
+export MANPAGER="echo \$EDITOR +Man!"
+export PAGER="less"
+export FAQ_STYLE='github'
+export VIDEO="vlc"
+#export IMAGE="sxiv"
+
+# XDG Paths:
+export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
+export XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
+export XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}
+export INPUTRC="${XDG_CONFIG_HOME:-$HOME/.config}/inputrc"
+export ZDOTDIR="$XDG_CONFIG_HOME/zsh"
+export HISTFILE="$ZDOTDIR/.zhistory" # History filepath
+export HISTSIZE=1000000 # Maximum events for internal history
+export SAVEHIST=1000000 # Maximum events in history file
+export BANG_HIST # Treat the '!' character specially during expansion.
+export EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format.
+export INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
+export SHARE_HISTORY # Share history between all sessions.
+export HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.
+export HIST_IGNORE_DUPS # Don't record an entry that was just recorded again.
+export HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
+export HIST_FIND_NO_DUPS # Do not display a line previously found.
+export HIST_IGNORE_SPACE # Don't record an entry starting with a space.
+export HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
+export HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry.
+export HIST_VERIFY # Don't execute immediately upon history expansion.
+export HIST_BEEP # Beep when accessing nonexistent history.
+
+# Customize `ls` colours
+export LSCOLORS=ExGxBxDxCxEgEdxbxgxcxd
+
+# Other XDG paths:
+export RIPGREP_CONFIG_PATH="$XDG_CONFIG_HOME/ripgrep/ripgreprc"
+export DOCKER_CONFIG="$XDG_CONFIG_HOME/docker"
+export VSCODE_PORTABLE="$XDG_DATA_HOME/vscode"
+export GTK2_RC_FILES="$XDG_CONFIG_HOME/gtk-2.0/gtkrc"
+#export PATH="/usr/bin/cmake:$PATH"
+#export PATH=$PATH:/opt/google/chrome
+
+# Manage Arch linux build sources
+export ASPROOT="${XDG_CACHE_HOME:-$HOME/.cache}/asp"
+
+# GnuPG
+export GPG_TTY=$(tty)
+export GNUPGHOME="$XDG_CONFIG_HOME/gnupg"
+
+
+# Android Home
+export ANDROID_HOME=/opt/android-sdk
+export PATH=$ANDROID_HOME/tools:$PATH
+export PATH=$ANDROID_HOME/tools/bin:$PATH
+export PATH=$ANDROID_HOME/platform-tools:$PATH
+# Android emulator PATH
+export PATH=$ANDROID_HOME/emulator:$PATH
+# Android SDK ROOT PATH
+export ANDROID_SDK_ROOT=/opt/android-sdk
+export PATH=$ANDROID_SDK_ROOT:$PATH
+#export ANDROID_SDK_HOME="${XDG_CONFIG_HOME:-$HOME/.config}/android"
+
+# Programming Environment Variables:
+
+# Rust
+export RUSTUP_HOME=${XDG_DATA_HOME:-$HOME/.local/share}/rustup
+export CARGO_HOME=${XDG_DATA_HOME:-$HOME/.local/share}/cargo
+[[ -d $CARGO_HOME/bin ]] && path=($CARGO_HOME/bin $path)
+if which rustc > /dev/null; then export RUST_BACKTRACE=1; fi
+#export PATH="$HOME/.cargo/bin:$PATH"
+#export CARGO_HOME=${XDG_DATA_HOME}/cargo
+#export RUSTUP_HOME=${XDG_DATA_HOME}/rustup
+#export PATH="${CARGO_HOME}/bin:${RUSTUP_HOME}/bin:$PATH"
+
+
+# Java
+export JAVA_HOME='/usr/lib/jvm/java-8-openjdk'
+#export JAVA_HOME='/usr/lib/jvm/java-10-openjdk'
+export PATH=$JAVA_HOME/bin:$PATH
+export _JAVA_OPTIONS=-Djava.util.prefs.userRoot="$XDG_CONFIG_HOME"/java
+#export _JAVA_AWT_WM_NONREPARENTING=1
+export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
+#export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.xml.bind'
+#Windows:
+#set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee
+
+# Dart/Flutter
+export PATH="/usr/bin/flutter:/usr/lib/dart/bin:$PATH"
+
+# Go
+export GO_PATH=${XDG_DATA_HOME}/go
+
+
+# Javascript
+# global node installs (gross)
+[[ -d "$XDG_DATA_HOME/node/bin" ]] && path=($XDG_DATA_HOME/node/bin $path)
+export NODE_REPL_HISTORY="$XDG_DATA_HOME"/node_repl_history
+export NPM_CONFIG_USERCONFIG=$XDG_CONFIG_HOME/npm/npmrc
+#export NPM_CONFIG_INIT_AUTHOR_NAME='srdusr'
+#export NPM_CONFIG_INIT_AUTHOR_EMAIL='trevorgray@srdusr.com'
+#export NPM_CONFIG_INIT_AUTHOR_URL='https://srdusr.com'
+#export NPM_CONFIG_INIT_LICENSE='GPL-3.0'
+#export NPM_CONFIG_INIT_VERSION='0.0.0'
+#export NPM_CONFIG_SIGN_GIT_TAG='true'
+export NVM_DIR="$HOME/.config/nvm"
+[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
+
+
+# Ruby
+export GEM_PATH="$XDG_DATA_HOME/ruby/gems"
+export GEM_SPEC_CACHE="$XDG_DATA_HOME/ruby/specs"
+export GEM_HOME="$XDG_DATA_HOME/ruby/gems"
+#if [[ -d ~/.gem/ruby ]]; then
+# ver=$(find ~/.gem/ruby/* -maxdepth 0 | sort -rV | head -n 1)
+# export PATH="$PATH:${ver}/bin"
+#fi
+
+
+# Python
+# lazy load pyenv
+export PYENV_ROOT=${PYENV_ROOT:-$HOME/.pyenv}
+[[ -a $PYENV_ROOT/bin/pyenv ]] && path=($PYENV_ROOT/bin $path)
+if type pyenv &> /dev/null || [[ -a $PYENV_ROOT/bin/pyenv ]]; then
+ function pyenv() {
+ unset pyenv
+ path=($PYENV_ROOT/shims $path)
+ eval "$(command pyenv init -)"
+ if which pyenv-virtualenv-init > /dev/null; then
+ eval "$(pyenv virtualenv-init -)"
+ export PYENV_VIRTUALENV_DISABLE_PROMPT=1
+ fi
+ pyenv $@
+ }
+fi
+export WORKON_HOME="$XDG_DATA_HOME/virtualenvs"
+export JUPYTER_CONFIG_DIR="$XDG_CONFIG_HOME/jupyter"
+export IPYTHONDIR="$XDG_CONFIG_HOME/jupyter"
+export VIRTUAL_ENV_DISABLE_PROMPT=true
+
+# PHP
+PATH="$HOME/.config/composer/vendor/bin:$PATH"
+
+
+# Lua
+export PATH=$PATH:/usr/local/luarocks/bin
+#export PATH="$XDG_DATA_HOME/luarocks/bin:$PATH"
+
+#ver=$(find lua* -maxdepth 0 | sort -rV | head -n 1)
+#export LUA_PATH="$LUA_PATH:${ver}/share/lua/5.1/?.lua;${ver}/share/lua/5.1/?/init.lua;;"
+#export LUA_CPATH="$LUA_CPATH:${ver}/lib/lua/5.1/?.so;;"
+
+#LUAROCKS_PREFIX=/usr/local
+#export LUA_PATH="$LUAROCKS_PREFIX/share/lua/5.1/?.lua;$LUAROCKS_PREFIX/share/lua/5.1/?/init.lua;;"
+#export LUA_CPATH="$LUAROCKS_PREFIX/lib/lua/5.1/?.so;;"
+
+#export LUA_PATH="<path-to-add>;;"
+#export LUA_CPATH="./?.so;/usr/local/lib/lua/5.3/?.so;
+# /usr/local/share/lua/5.3/?.so;<path-to-add>"
+
+
+# Program settings
+#export MOZ_USE_XINPUT2="1" # Mozilla smooth scrolling/touchpads.
+
+
+# Scaling
+#export QT_AUTO_SCREEN_SCALE_FACTOR=0
+#export QT_SCALE_FACTOR=1
+#export QT_SCREEN_SCALE_FACTORS="1;1;1"
+#export GDK_SCALE=1
+#export GDK_DPI_SCALE=1
+
+
+#typeset -U PATH path
+export GTK_IM_MODULE='fcitx'
+export QT_IM_MODULE='fcitx'
+export SDL_IM_MODULE='fcitx'
+export XMODIFIERS='@im=fcitx'
+
+
+# Start blinking
+#export LESS_TERMCAP_mb=$(tput bold; tput setaf 2) # green
+# Start bold
+#export LESS_TERMCAP_md=$(tput bold; tput setaf 2) # green
+# Start stand out
+#export LESS_TERMCAP_so=$(tput bold; tput setaf 3) # yellow
+# End standout
+#export LESS_TERMCAP_se=$(tput rmso; tput sgr0)
+# Start underline
+#export LESS_TERMCAP_us=$(tput smul; tput bold; tput setaf 1) # red
+# End Underline
+#export LESS_TERMCAP_ue=$(tput sgr0)
+# End bold, blinking, standout, underline
+#export LESS_TERMCAP_me=$(tput sgr0).
diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc
new file mode 100644
index 0000000..582408e
--- /dev/null
+++ b/.config/zsh/.zshrc
@@ -0,0 +1,566 @@
+
+# ███████╗███████╗██╗ ██╗██████╗ ██████╗
+# ╚══███╔╝██╔════╝██║ ██║██╔══██╗██╔════╝
+# ███╔╝ ███████╗███████║██████╔╝██║
+# ███╔╝ ╚════██║██╔══██║██╔══██╗██║
+# ███████╗███████║██║ ██║██║ ██║╚██████╗
+# ╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝
+
+# If not running interactively, don't do anything
+[[ $- != *i* ]] && return
+
+if [[ -n "$SSH_CLIENT" ]]; then
+ export KEYTIMEOUT=1
+else
+ export KEYTIMEOUT=15
+fi
+
+########## Vi mode ##########
+bindkey -v
+bindkey -M viins '^?' backward-delete-char
+bindkey -M viins '^[[3~' delete-char
+bindkey -M vicmd '^[[3~' delete-char
+bindkey -v '^?' backward-delete-char
+bindkey -r '\e/'
+bindkey -s jk '\e'
+bindkey "^W" backward-kill-word
+bindkey "^H" backward-delete-char # Control-h also deletes the previous char
+bindkey "^U" backward-kill-line
+bindkey "^[j" history-search-forward # or you can bind it to the down key "^[[B"
+bindkey "^[k" history-search-backward # or you can bind it to Up key "^[[A"
+
+# Define the 'autosuggest-execute' and 'autosuggest-accept' ZLE widgets
+autoload -Uz autosuggest-execute autosuggest-accept
+zle -N autosuggest-execute
+zle -N autosuggest-accept
+bindkey '^X' autosuggest-execute
+bindkey '^Y' autosuggest-accept
+
+# Edit line in vim with alt-e
+autoload edit-command-line; zle -N edit-command-line
+bindkey '^e' edit-command-line
+bindkey '^[e' edit-command-line # alt + e
+
+# Allow CTRL+D to exit zsh with partial command line (non empty line)
+exit_zsh() { exit }
+zle -N exit_zsh
+bindkey '^D' exit_zsh
+
+# Auto-completion
+#autoload -U promptinit && promptinit
+autoload -Uz compinit && compinit
+
+# Accept completion with <tab> or Ctrl+i and go to next/previous suggestions with Vi like keys: Ctrl+n/p
+zmodload -i zsh/complist
+accept-and-complete-next-history() {
+ zle expand-or-complete-prefix
+}
+
+zle -N accept-and-complete-next-history
+bindkey -M menuselect '^i' accept-and-complete-next-history
+bindkey '^n' expand-or-complete
+bindkey '^p' reverse-menu-complete
+zstyle ':completion:*' menu select=1
+
+# Some other useful functionalities
+setopt autocd # Automatically cd into typed directory.
+stty intr '^q' # free Ctrl+C for copy use Ctrl+q instead
+stty lnext '^-' # free Ctrl+V for paste use ^- instead
+stty stop undef # Disable ctrl-s to freeze terminal.
+stty start undef
+#unsetopt BEEP
+
+# Enable various options
+setopt interactive_comments beep extendedglob nomatch notify completeinword prompt_subst
+
+########## Prompt(s) ##########
+
+# Enable colors
+autoload -U colors && colors
+
+# Prompt with Vi insert-mode/normal-mode and blinking '$', note blinking '$' only works on some terminals.
+terminfo_down_sc=$terminfo[cud1]$terminfo[cuu1]$terminfo[sc]$terminfo[cud1]
+git_branch_test_color() {
+ local ref=$(git symbolic-ref --short HEAD 2> /dev/null)
+ if [ -n "${ref}" ]; then
+ if [ -n "$(git status --porcelain)" ]; then
+ local gitstatuscolor='%F{196}'
+ else
+ local gitstatuscolor='%F{82}'
+ fi
+ echo "${gitstatuscolor}${ref}"
+ else
+ echo ""
+ fi
+}
+
+# Job indicator
+jobs_status_indicator() {
+ local jobs_output
+ declare -p jobs_output >/dev/null 2>&1
+ if [[ $? -eq 0 ]]; then
+ unset jobs_output
+ fi
+ jobs_output=$(jobs -s)
+ if [[ -n "$jobs_output" ]]; then
+ local jobs_count=$(echo "$jobs_output" | wc -l)
+ echo "jobs: ${jobs_count}"
+ fi
+}
+
+remote_indicator() {
+ if [[ -n "$SSH_CONNECTION" || -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
+ echo 'ssh '
+ else
+ echo ''
+ fi
+}
+
+# Version control (git)
+autoload -Uz add-zsh-hook vcs_info
+zstyle ':vcs_info:*' stagedstr ' +%F{15}staged%f'
+zstyle ':vcs_info:*' unstagedstr ' -%F{15}unstaged%f'
+zstyle ':vcs_info:*' check-for-changes true
+zstyle ':vcs_info:*' actionformats '%F{5}%F{2}%b%F{3}|%F{1}%a%F{5}%f '
+zstyle ':vcs_info:*' formats '%F{208} '$'\uE0A0'' %f$(git_branch_test_color)%f%F{76}%c%F{3}%u%f '
+zstyle ':vcs_info:git*+set-message:*' hooks git-untracked
+zstyle ':vcs_info:*' enable git
++vi-git-untracked() {
+ if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \
+ [[ $(git ls-files --other --directory --exclude-standard | sed q | wc -l | tr -d ' ') == 1 ]] ; then
+ hook_com[unstaged]+='%F{196} !%f%F{15}untracked%f'
+ fi
+}
+
+# Prompt
+function insert-mode() {
+ echo "-- INSERT --"
+}
+
+function normal-mode() {
+ echo "-- NORMAL --"
+}
+
+function my_precmd () {
+ vcs_info
+ PS1="%{┌─[%F{145}%n%f] %F{39}%0~%f%} ${vcs_info_msg_0_} \$(remote_indicator)\$(jobs_status_indicator)
+ %{%{$terminfo_down_sc$(insert-mode)$terminfo[rc]%}%{└─%{["%{$(tput setaf 226)%}""%{$(tput blink)%}"%{$%}"%{$(tput sgr0)%}"%{%G]%}%}%}%}"
+}
+
+add-zsh-hook precmd my_precmd
+
+function set-prompt() {
+ if [[ ${KEYMAP} == vicmd || ${KEYMAP} == vi-cmd-mode ]]; then
+ echo -ne '\e[1 q'
+ VI_MODE=$(normal-mode)
+ elif [[ ${KEYMAP} == main || ${KEYMAP} == viins || ${KEYMAP} == '' ]]; then
+ echo -ne '\e[5 q'
+ VI_MODE=$(insert-mode)
+ fi
+ PS1="%{┌─[%F{145}%n%f] %F{39}%0~%f%} ${vcs_info_msg_0_} \$(remote_indicator)\$(jobs_status_indicator)
+ %{%{$terminfo_down_sc$VI_MODE$terminfo[rc]%}%{└─%{["%{$(tput setaf 226)%}""%{$(tput blink)%}"%{$%}"%{$(tput sgr0)%}"%{%G]%}%}%}%}"
+}
+
+function update-mode-file() {
+ set-prompt
+ local current_mode=$(cat ~/.vi-mode)
+ local new_mode="$VI_MODE"
+ if [[ "$new_mode" != "$current_mode" ]]; then
+ echo "$new_mode" >| ~/.vi-mode
+ fi
+ if command -v tmux &>/dev/null && [[ -n "$TMUX" ]]; then
+ tmux refresh-client -S
+ fi
+}
+
+function check-nvim-running() {
+ if pgrep -x "nvim" > /dev/null; then
+ VI_MODE=""
+ update-mode-file
+ if command -v tmux &>/dev/null && [[ -n "$TMUX" ]]; then
+ tmux refresh-client -S
+ fi
+ else
+ if [[ ${KEYMAP} == vicmd || ${KEYMAP} == vi-cmd-mode ]]; then
+ VI_MODE=$(normal-mode)
+ elif [[ ${KEYMAP} == main || ${KEYMAP} == viins || ${KEYMAP} == '' ]]; then
+ VI_MODE=$(insert-mode)
+ fi
+ update-mode-file
+ if command -v tmux &>/dev/null && [[ -n "$TMUX" ]]; then
+ tmux refresh-client -S
+ fi
+ fi
+}
+
+function zle-line-init() {
+ zle reset-prompt
+ case "${KEYMAP}" in
+ vicmd)
+ echo -ne '\e[1 q'
+ ;;
+ main|viins|*)
+ echo -ne '\e[5 q'
+ ;;
+ esac
+}
+
+function zle-keymap-select() {
+ update-mode-file
+ zle reset-prompt
+ case "${KEYMAP}" in
+ vicmd)
+ echo -ne '\e[1 q'
+ ;;
+ main|viins|*)
+ echo -ne '\e[5 q'
+ ;;
+ esac
+}
+
+preexec () { print -rn -- $terminfo[el]; echo -ne '\e[5 q' ; }
+
+zle -N zle-line-init
+zle -N zle-keymap-select
+
+TRAPWINCH() { # Trap the WINCH signal to update the mode file on window size changes
+ update-mode-file
+}
+
+#function nvim-listener() {
+# local prev_nvim_status="inactive"
+# local nvim_pid=""
+# while true; do
+# local current_nvim_pid=$(pgrep -x "nvim")
+# if [[ -n "$current_nvim_pid" && "$current_nvim_pid" != "$nvim_pid" ]]; then
+# # Neovim started
+# prev_nvim_status="active"
+# nvim_pid="$current_nvim_pid"
+# VI_MODE="" # Clear VI_MODE to show Neovim mode
+# update-mode-file
+# if command -v tmux &>/dev/null && [[ -n "$TMUX" ]]; then
+# tmux refresh-client -S
+# fi
+# elif [[ -z "$current_nvim_pid" && "$prev_nvim_status" == "active" ]]; then
+# # Neovim stopped
+# prev_nvim_status="inactive"
+# nvim_pid=""
+# if [[ ${KEYMAP} == vicmd || ${KEYMAP} == vi-cmd-mode ]]; then
+# VI_MODE=$(normal-mode)
+# elif [[ ${KEYMAP} == main || ${KEYMAP} == viins || ${KEYMAP} == '' ]]; then
+# VI_MODE=$(insert-mode)
+# fi
+# update-mode-file
+# if command -v tmux &>/dev/null && [[ -n "$TMUX" ]]; then
+# tmux refresh-client -S
+# fi
+# fi
+# done
+#}
+
+# Start Neovim listener in the background
+#nvim-listener &!
+set-prompt
+
+RPROMPT='%(?..[%F{196}%?%f] )'
+
+
+########## Useful Commands/Alias ##########
+
+alias s="systemctl"
+alias j="journalctl xe"
+
+# Enter directory and list contents
+cd() {
+ if [ -n "$1" ]; then
+ builtin cd "$@" && ls -pvA --color=auto --group-directories-first
+ else
+ builtin cd ~ && ls -pvA --color=auto --group-directories-first
+ fi
+}
+
+# cd into $XDG_CONFIG_HOME/$1 directory
+c() {
+ local root=${XDG_CONFIG_HOME:-~/.config}
+ local dname="$root/$1"
+ if [[ ! -d "$dname" ]]; then
+ return
+ fi
+ cd "$dname"
+}
+
+# Make and cd into directory and any parent directories
+mkcd () {
+ if [[ -z "$1" ]]; then
+ echo "Usage: mkcd <dir>" 1>&2
+ return 1
+ fi
+ mkdir -p "$1"
+ cd "$1"
+}
+
+# Back up a file. Usage "backupthis <filename>"
+backupthis() {
+ cp -riv $1 ${1}-$(date +%Y%m%d%H%M).backup;
+}
+
+# Let FZF use ripgrep by default
+if type rg &> /dev/null; then
+ export FZF_DEFAULT_COMMAND='rg --files'
+ export FZF_DEFAULT_OPTS='-m --height 50% --border'
+fi
+
+# wget does not support environment variables
+alias wget=wget --hsts-file="$XDG_CACHE_HOME/wget-hsts"
+
+# Spawn a clone of current terminal
+putstate () {
+ declare +x >~/environment.tmp
+ declare -x >>~/environment.tmp
+ echo cd "$PWD" >>~/environment.tmp
+}
+
+getstate () {
+ . ~/environment.tmp
+}
+
+# use ctrl-z to toggle in and out of bg
+function toggle_fg_bg() {
+ if [[ $#BUFFER -eq 0 ]]; then
+ BUFFER="fg"
+ zle accept-line
+ else
+ BUFFER=""
+ zle clear-screen
+ fi
+}
+zle -N toggle_fg_bg
+bindkey '^Z' toggle_fg_bg
+
+# cd using "up n" as a command up as many directories, example "up 3"
+up() {
+ # default parameter to 1 if non provided
+ declare -i d=${@:-1}
+ # ensure given parameter is non-negative. Print error and return if it is
+ (( $d < 0 )) && (>&2 echo "up: Error: negative value provided") && return 1;
+ # remove last d directories from pwd, append "/" in case result is empty
+ cd "$(pwd | sed -E 's;(/[^/]*){0,'$d'}$;;')/";
+}
+
+# Tmux layout
+openSession () {
+ tmux split-window -h -t
+ tmux split-window -v -t
+ tmux resize-pane -U 5
+}
+
+# More history for cd and use "cd -TAB"
+setopt AUTO_PUSHD # pushes the old directory onto the stack
+zstyle ':completion:*:directory-stack' list-colors '=(#b) #([0-9]#)*( *)==95=38;5;12'
+
+# List upto last 10 visited directories using "d" and quickly cd into any specific one
+# using just a number from "0" to "9"
+alias d="dirs -v | head -10"
+alias 0="cd +0"
+alias 1="cd +1"
+alias 2="cd +2"
+alias 3="cd +3"
+alias 4="cd +4"
+alias 5="cd +5"
+alias 6="cd +6"
+alias 7="cd +7"
+alias 8="cd +8"
+alias 9="cd +9"
+
+# Allow nnn filemanager to cd on quit
+nnn() {
+ declare -x +g NNN_TMPFILE=$(mktemp --tmpdir $0.XXXX)
+ trap "rm -f $NNN_TMPFILE" EXIT
+ =nnn $@
+ [ -s $NNN_TMPFILE ] && source $NNN_TMPFILE
+}
+
+# Extract with one command
+extract () {
+ if [ -f $1 ] ; then
+ case $1 in
+ *.tar.bz2) tar xjf $1 ;;
+ *.tar.gz) tar xzf $1 ;;
+ *.bz2) bunzip2 $1 ;;
+ *.rar) rar x $1 ;;
+ *.gz) gunzip $1 ;;
+ *.tar) tar xf $1 ;;
+ *.tbz2) tar xjf $1 ;;
+ *.tgz) tar xzf $1 ;;
+ *.zip) unzip $1 ;;
+ *.Z) uncompress $1 ;;
+ *.7z) 7z x $1 ;;
+ *) echo "'$1' cannot be extracted via extract()" ;;
+ esac
+ else
+ echo "'$1' is not a valid file"
+ fi
+}
+
+# Time aliases
+alias ber='TZ=Europe/Berlin date'
+alias nyc='TZ=America/New_York date'
+alias sfo='TZ=America/Los_Angeles date'
+alias utc='TZ=Etc/UTC date'
+
+### Dotfiles
+alias config='git --git-dir=$HOME/.cfg --work-tree=$HOME'
+
+# Set bare dotfiles repository git environment variables dynamically
+function set_git_env_vars() {
+ # Check if the current command is a package manager command
+ if [[ "${(%)${(z)history[1]}}" =~ ^(pacman|yay|apt|dnf|brew|npm|pip|gem|go|cargo) ]]; then
+ return
+ fi
+ local git_dir="$(git rev-parse --git-dir -C . 2>/dev/null)"
+ if [[ -n "$git_dir" ]]; then
+ local is_bare="$(git -C "$git_dir" rev-parse --is-bare-repository 2>/dev/null)"
+ if [[ "$is_bare" == "true" ]]; then
+ export GIT_DIR="$HOME/.cfg"
+ export GIT_WORK_TREE=$(realpath $(eval echo ~))
+ else
+ unset GIT_DIR
+ unset GIT_WORK_TREE
+ fi
+ else
+ local root_dir="$(git rev-parse --show-toplevel 2>/dev/null)"
+ if [[ -n "$root_dir" ]]; then
+ unset GIT_DIR
+ export GIT_WORK_TREE="$root_dir"
+ else
+ export GIT_DIR="$HOME/.cfg"
+ export GIT_WORK_TREE=$(realpath $(eval echo ~))
+ fi
+ fi
+}
+
+# Define an auto_cd hook to automatically update Git environment variables
+function chpwd() {
+ set_git_env_vars
+}
+# Call the function to set Git environment variables when the shell starts up
+set_git_env_vars
+
+function gsp
+{
+ # Config file for subtrees
+ #
+ # Format:
+ # <prefix>;<remote address>;<remote branch>
+ # # Lines starting with '#' will be ignored
+ GIT_SUBTREE_FILE="$PWD/.gitsubtrees"
+
+ if [ ! -f $GIT_SUBTREE_FILE ]; then
+ echo "Nothing to do - file <`basename $GIT_SUBTREE_FILE`> does not exist."
+ return
+ fi
+
+ OLD_IFS=$IFS
+ IFS=$'\n'
+ for LINE in $(cat $GIT_SUBTREE_FILE); do
+
+ # Skip lines starting with '#'.
+ if [[ $LINE = \#* ]]; then
+ continue
+ fi
+
+ # Parse the current line.
+ PREFIX=`echo $LINE | cut -d';' -f 1`
+ REMOTE=`echo $LINE | cut -d';' -f 2`
+ BRANCH=`echo $LINE | cut -d';' -f 3`
+
+ # Push to the remote.
+ echo "config subtree pull --prefix=$PREFIX $REMOTE $BRANCH"
+ config subtree pull --prefix=$PREFIX $REMOTE $BRANCH
+ done
+}
+
+alias vi='nvim'
+alias nv='nvim'
+alias trash_restore='gio trash --restore "$(gio trash --list | fzf | cut -f 1)"'
+alias ec='$EDITOR $HOME/.config/zsh/.zshrc'
+alias sc="source $HOME/.config/zsh/.zshrc"
+alias keyname="xev | sed -n 's/[ ]*state.* \([^ ]*\)).*/\1/p'"
+
+# Print previous command into a file
+getlast () {
+ fc -nl $((HISTCMD - 1))
+}
+
+alias pp='getlast 2>&1 |&tee -a output.txt'
+
+# Print output of a command NOTE: Must be used in conjunction but no need for "|" symbol
+alias -g cap='2>&1 | tee -a output.txt'
+
+# confirmation #
+alias mv='mv -i'
+alias cp='cp -i'
+alias ln='ln -i'
+alias rm='rm -i'
+
+# Suspend(sleep)/hibernate and lock screen if using systemctl
+alias suspend='systemctl suspend && betterlockscreen --lock dimblur'
+alias hibernate='systemctl hibernate'
+
+# Kubernetes
+# kubernetes aliases
+if command -v kubectl > /dev/null; then
+ function replaceNS() { kubectl config view --minify --flatten --context=$(kubectl config current-context) | yq ".contexts[0].context.namespace=\"$1\"" }
+ alias kks='KUBECONFIG=<(replaceNS "kube-system") kubectl'
+ alias kam='KUBECONFIG=<(replaceNS "authzed-monitoring") kubectl'
+ alias kas='KUBECONFIG=<(replaceNS "authzed-system") kubectl'
+ alias kar='KUBECONFIG=<(replaceNS "authzed-region") kubectl'
+ alias kt='KUBECONFIG=<(replaceNS "tenant") kubectl'
+ if command -v kubectl-krew > /dev/null; then
+ path=($XDG_CONFIG_HOME/krew/bin $path)
+ fi
+ function rmfinalizers() {
+ kubectl get deployment $1 -o json | jq '.metadata.finalizers = null' | k apply -f -
+ }
+fi
+
+# Alias for android-studio
+alias android-studio='/opt/android-studio/bin/studio.sh'
+
+# NVM
+#nvm() {
+# local green_color
+# green_color=$(tput setaf 2)
+# local reset_color
+# reset_color=$(tput sgr0)
+# echo -e "${green_color}nvm${reset_color} $@"
+#}
+
+if [ -s "$NVM_DIR/nvm.sh" ]; then
+ nvm_cmds=(nvm node npm yarn)
+ for cmd in "${nvm_cmds[@]}"; do
+ alias "$cmd"="unalias ${nvm_cmds[*]} && unset nvm_cmds && . $NVM_DIR/nvm.sh && $cmd"
+ done
+fi
+
+
+########## Source Plugins, should be last ##########
+#source /usr/share/nvm/init-nvm.sh
+
+# Load zsh-syntax-highlighting
+source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
+#source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 2>/dev/null
+
+# Load fzf keybindings and completion
+source /usr/share/fzf/key-bindings.zsh
+source /usr/share/fzf/completion.zsh
+source /usr/share/fzf-marks/fzf-marks.zsh
+#source /usr/share/fzf-marks/fzf-marks.plugin.zsh 2>/dev/null
+
+# Suggest aliases for commands
+source /usr/share/zsh/plugins/zsh-you-should-use/you-should-use.plugin.zsh
+#source /usr/share/zsh/plugins/zsh-you-should-use/you-should-use.plugin.zsh 2>/dev/null
+
+# Load fish like auto suggestions
+source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh
+source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh