Skip to content

Instantly share code, notes, and snippets.

@algon-320
Last active April 22, 2023 06:32
Show Gist options
  • Save algon-320/5dcc87c913880364f981f51a685e9989 to your computer and use it in GitHub Desktop.
Save algon-320/5dcc87c913880364f981f51a685e9989 to your computer and use it in GitHub Desktop.
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# set -x
KEYTIMEOUT=1
HISTFILE=~/.zsh_history
HISTSIZE=1000000
SAVEHIST=1000000
setopt EXTENDED_HISTORY
setopt PROMPT_SUBST
cd_to_parent_dir() {
local BUF="${BUFFER}"
zle kill-whole-line
pushd -q ..
zle reset-prompt
[ ! ${#BUF} -eq 0 ] && zle -U "${BUF}"
}
zle -N cd_to_parent_dir
back_to_previous_dir() {
local BUF="${BUFFER}"
zle kill-whole-line
popd -q
zle reset-prompt
[ ! ${#BUF} -eq 0 ] && zle -U "${BUF}"
}
zle -N back_to_previous_dir
bindkey -M vicmd '^P' cd_to_parent_dir
bindkey -M viins '^P' cd_to_parent_dir
bindkey -M vicmd '^O' back_to_previous_dir
bindkey -M viins '^O' back_to_previous_dir
bindkey -M vicmd '^[[3~' delete-char
bindkey -M viins '^[[3~' delete-char
bindkey -M viins '^?' backward-delete-char
bindkey -M viins '^W' backward-kill-word
bindkey -M viins '^R' history-incremental-search-backward
bindkey -v
# loading common stuff
[[ -f ~/.shell/aliases ]] && . ~/.shell/aliases
[[ -f ~/.shell/envvars ]] && . ~/.shell/envvars
[[ -f ~/.shell/paths ]] && . ~/.shell/paths
[[ -f ~/.shell/functions ]] && . ~/.shell/functions
[[ -f ~/.shell/startup ]] && . ~/.shell/startup
# enable # comment under interactive mode
setopt interactivecomments
# auto completion
autoload -Uz compinit && compinit
# setup the prompt
# eval "$(starship init zsh)"
# direnv hook
# eval "$(direnv hook zsh)"
prompt_part_status='%(?.%F{green}.%F{red})$(printf "%3d" $(print -P %?))%f'
prompt_part_cwd='%B%F{magenta}%~%f%b'
prompt_part_jobs='%(1j.*%(2j.%j.).)'
zle-keymap-select () {
case $KEYMAP in
viins|main)
echo -ne '\e[6 q'
prompt_part_hash='%B%F{cyan}%#%f%b'
;;
vicmd)
echo -ne '\e[2 q'
prompt_part_hash='%B%F{blue}%#%f%b'
;;
esac
PROMPT="[${prompt_part_status}] ${prompt_part_cwd} ${prompt_part_jobs}${prompt_part_hash} "
zle reset-prompt
}
zle -N zle-keymap-select
zle-line-init() { zle -K viins; echo -ne '\e[6 q'; }
zle -N zle-line-init
zle-line-finish() { zle -K viins; echo -ne '\e[2 q'; }
zle -N zle-line-finish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment