Skip to content

Instantly share code, notes, and snippets.

@VonHeikemen
Last active March 21, 2023 23:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VonHeikemen/8b3bbdfee976683212818b704b08f405 to your computer and use it in GitHub Desktop.
Save VonHeikemen/8b3bbdfee976683212818b704b08f405 to your computer and use it in GitHub Desktop.
HISTFILE="$HOME/.zsh_history"
HISTSIZE=50000
SAVEHIST=10000
## History command configuration
setopt extended_history # record timestamp of command in HISTFILE
setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
setopt hist_ignore_dups # ignore duplicated commands history list
setopt hist_ignore_space # ignore commands that start with space
setopt hist_verify # show command with history expansion to user before running it
setopt inc_append_history # add commands to HISTFILE in order of execution
setopt share_history # share command history data
# Changing/making/removing directory
setopt auto_pushd
setopt pushd_ignore_dups
setopt pushdminus
setopt auto_cd
setopt multios
setopt prompt_subst
autoload -U compaudit compinit
autoload -U colors
colors
compinit
zstyle ':completion:*' menu select
# Make sure the terminal is in application mode, which zle is active. Only then
# are the values from $terminfo valid.
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
function zle-line-init() {
echoti smkx
}
function zle-line-finish() {
echoti rmkx
}
zle -N zle-line-init
zle -N zle-line-finish
fi
# Set LS_COLORS.
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
fi
# If the zsh/complist module is loaded, this style can be used to set color
# specifications.
if [ -z "$LS_COLORS" ]; then
zstyle ':completion:*' list-colors 'di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43:'
else
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
fi
export PATH=$HOME/.npm-packages/bin:$PATH
export EDITOR="nvim"
export PYTHONUSERBASE=~/.local
export TERMINAL='kitty'
export FZF_DEFAULT_COMMAND='rg --files --hidden --follow --glob "!.git/*" --glob "!cache/*" --glob "!node_modules/*"'
alias ls='ls --color=auto'
alias -- -='cd -'
alias npr="pnpm run"
alias npi='pnpm install'
alias npi-flat='pnpm install --shamefully-flatten'
alias lzg="lazygit"
alias ta="tmux attach -t"
alias ts="tmux new-session -s"
alias tl="tmux list-sessions"
alias tmus='tmux new-session -A -D -s music "$(which cmus)"'
alias pomd='tmux new-session -A -D -s pomodoro'
alias pmd-start='pomd gone -e "notify-send -u critical Pomodoro Timeout"'
alias vi-s="nvim -S Session.vim"
alias dcc="docker-compose"
alias doc-start="systemctl start docker"
alias doc-ls="docker ps -a"
alias la='exa --git --header --long --all'
alias ic='node ~/code-stuff/check-internet/index.js "$(which chromium)" --stdout'
autoload -U up-line-or-beginning-search
autoload -U down-line-or-beginning-search
autoload -U edit-command-line
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
zle -N edit-command-line
# enable vi-mode
bindkey -v
# start typing + [Up-Arrow] - fuzzy find history forward
bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search
# start typing + [Down-Arrow] - fuzzy find history backward
bindkey "${terminfo[kcud1]}" down-line-or-beginning-search
# [Space] - do history expansion
bindkey ' ' magic-space
# [Home] - Go to beginning of line
bindkey "${terminfo[khome]}" beginning-of-line
# [End] - Go to end of line
bindkey "${terminfo[kend]}" end-of-line
# [PageUp] - Up a line of history
bindkey "${terminfo[kpp]}" up-line-or-history
# [PageDown] - Down a line of history
bindkey "${terminfo[knp]}" down-line-or-history
# [Shift-tab] - move to the previous completion rather than the next
bindkey "${terminfo[kcbt]}" reverse-menu-complete
# [Ctrl+RightArrow] - move forward one word
bindkey '^[[1;5C' forward-word
# [Ctrl+LeftArrow] - move backward one word
bindkey '^[[1;5D' backward-word
# [Ctrl+e] - use $EDITOR to write a command
bindkey '^e' edit-command-line
# [Backspace] - delete backward
bindkey '^?' backward-delete-char
# [Ctrl+e] - delete word
bindkey -M viins '^W' backward-kill-word
# [Ctrl+h] - delete backward
bindkey -M viins '^H' backward-delete-char
# [Ctrl+u] - delete line
bindkey -M viins '^U' backward-kill-line
# [Slash] - search history with fzf
bindkey -M vicmd '/' fzf-history-widget
# Disable delay when changing modes
export KEYTIMEOUT=1
# Change cursor shape
zle-keymap-select () {
if [ $KEYMAP = vicmd ]; then
# the command mode for vi
echo -ne "\e[2 q"
else
# the insert mode for vi
echo -ne "\e[6 q"
fi
}
zle -N zle-keymap-select
echo -ne "\e[6 q"
# SSH identities (Ex. 'id_rsa')
local identities=()
# Get the filename to store/lookup the environment from
local _ssh_env_cache="$HOME/.ssh/environment-${HOST/.*/}"
_add_identities() {
ssh-add -l > /dev/null
if [ $? -eq 1 ]; then
for id in $identities; do
ssh-add "$HOME/.ssh/$id"
done
fi
}
_start_agent() {
local lifetime='4h'
# start ssh-agent and setup environment
echo "\nStarting ssh-agent..."
ssh-agent -s ${lifetime:+-t} ${lifetime} | sed 's/^echo/#echo/' >! $_ssh_env_cache
chmod 600 $_ssh_env_cache
. $_ssh_env_cache > /dev/null
}
_launch_agent() {
# check identites array
[[ -z $identities ]] && return
if [[ -f "$_ssh_env_cache" ]]; then
# Source SSH settings, if applicable
. $_ssh_env_cache > /dev/null
if [[ $USER == "root" ]]; then
FILTER="ax"
else
FILTER="x"
fi
# check if ssh-agent is already running
ps $FILTER | grep ssh-agent | grep -q $SSH_AGENT_PID || {
_start_agent
}
else
_start_agent
fi
_add_identities
}
_launch_agent
unfunction _start_agent _add_identities _launch_agent
# A modified version of this:
# https://github.com/robbyrussell/oh-my-zsh/blob/master/themes/refined.zsh-theme
autoload -Uz vcs_info
local _current_dir="%{$fg[blue]%}%3~%{$reset_color%}"
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*:*' formats "${_current_dir} %{$fg[green]%}%b"
zstyle ':vcs_info:*:*' nvcsformats "${_current_dir}" "" ""
# Fastest possible way to check if repo is dirty
git_dirty() {
# Check if we're in a git repo
command git rev-parse --is-inside-work-tree &>/dev/null || return
# Check if it's dirty
command git diff --quiet --ignore-submodules HEAD &>/dev/null;
if [ $? -eq 1 ]; then
echo "%{$fg[red]%}✗%{$reset_color%}"
else
echo "%{$fg[green]%}✔%{$reset_color%}"
fi
}
# Display information about the current repository
repo_information() {
echo "%F{blue}${vcs_info_msg_0_%%/.} %F{8}$vcs_info_msg_1_$(git_dirty)"
}
# Output additional information about paths, repos and exec time
precmd() {
vcs_info # Get version control info before we start outputting stuff
print -P "\n$(repo_information)"
}
# Define prompts
PROMPT="%(?.%F{magenta}.%F{red})❯%f " # Display a red prompt char on failure
RPROMPT="%F{8}${SSH_TTY:+%n@%m}%f" # Display username if connected via SSH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment