From caa9323eae8ec54afd6158472ee71050ea584842 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Fri, 18 Nov 2022 13:05:06 +0800 Subject: Add custom zshrc --- zsh/ps1 | 133 -------------------------------------------------------------- zsh/zshrc | 83 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 133 deletions(-) delete mode 100644 zsh/ps1 create mode 100644 zsh/zshrc (limited to 'zsh') diff --git a/zsh/ps1 b/zsh/ps1 deleted file mode 100644 index 903bc79..0000000 --- a/zsh/ps1 +++ /dev/null @@ -1,133 +0,0 @@ -# Purification -# by Matthieu Cneude -# https://github.com/Phantas0s/purification - -# Based on: - -# Purity -# by Kevin Lanni -# https://github.com/therealklanni/purity -# MIT License - -# prompt: -# %F => color dict -# %f => reset color -# %~ => current path -# %* => time -# %n => username -# %m => shortname host -# %(?..) => prompt conditional - %(condition.true.false) - -# Display git status -# TODO to refactor with switch / using someting else than grep -# Might be faster using ripgrep too -git_prompt_status() { - local INDEX STATUS - - INDEX=$(command git status --porcelain -b 2> /dev/null) - - STATUS="" - - if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS" - fi - - if $(echo "$INDEX" | grep '^A ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS" - elif $(echo "$INDEX" | grep '^M ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS" - elif $(echo "$INDEX" | grep '^MM ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS" - fi - - if $(echo "$INDEX" | grep '^ M ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" - elif $(echo "$INDEX" | grep '^AM ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" - elif $(echo "$INDEX" | grep '^MM ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" - elif $(echo "$INDEX" | grep '^ T ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" - fi - - if $(echo "$INDEX" | grep '^R ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS" - fi - - if $(echo "$INDEX" | grep '^ D ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" - elif $(echo "$INDEX" | grep '^D ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" - elif $(echo "$INDEX" | grep '^AD ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" - fi - - if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then - STATUS="$ZSH_THEME_GIT_PROMPT_STASHED$STATUS" - fi - - if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS" - fi - - if $(echo "$INDEX" | grep '^## [^ ]\+ .*ahead' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS" - fi - - if $(echo "$INDEX" | grep '^## [^ ]\+ .*behind' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS" - fi - - if $(echo "$INDEX" | grep '^## [^ ]\+ .*diverged' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS" - fi - - if [[ ! -z "$STATUS" ]]; then - echo " [ $STATUS]" - fi -} - - -prompt_git_branch() { - autoload -Uz vcs_info - precmd_vcs_info() { vcs_info } - precmd_functions+=( precmd_vcs_info ) - setopt prompt_subst - zstyle ':vcs_info:git:*' formats '%b' -} - -prompt_git_info() { - [ ! -z "$vcs_info_msg_0_" ] && echo "$ZSH_THEME_GIT_PROMPT_PREFIX%F{white}$vcs_info_msg_0_%f$ZSH_THEME_GIT_PROMPT_SUFFIX" -} - -prompt_purity_precmd() { - # Pass a line before each prompt - print -P '' -} - -prompt_purification_setup() { - # Display git branch - - autoload -Uz add-zsh-hook - add-zsh-hook precmd prompt_purity_precmd - - ZSH_THEME_GIT_PROMPT_PREFIX=" %F{red}λ%f:" - ZSH_THEME_GIT_PROMPT_DIRTY="" - ZSH_THEME_GIT_PROMPT_CLEAN="" - - ZSH_THEME_GIT_PROMPT_ADDED="%F{green}+%f " - ZSH_THEME_GIT_PROMPT_MODIFIED="%F{blue}%f " - ZSH_THEME_GIT_PROMPT_DELETED="%F{red}x%f " - ZSH_THEME_GIT_PROMPT_RENAMED="%F{magenta}➜%f " - ZSH_THEME_GIT_PROMPT_UNMERGED="%F{yellow}═%f " - ZSH_THEME_GIT_PROMPT_UNTRACKED="%F{white}%f " - ZSH_THEME_GIT_PROMPT_STASHED="%B%F{red}%f%b " - ZSH_THEME_GIT_PROMPT_BEHIND="%B%F{red}%f%b " - ZSH_THEME_GIT_PROMPT_AHEAD="%B%F{green}%f%b " - - prompt_git_branch - RPROMPT='$(prompt_git_info) $(git_prompt_status)' - PROMPT=$'%F{white}%~ %B%F{blue}>%f%b ' -} - -prompt_purification_setup diff --git a/zsh/zshrc b/zsh/zshrc new file mode 100644 index 0000000..d77e299 --- /dev/null +++ b/zsh/zshrc @@ -0,0 +1,83 @@ +# Set name of the theme to load --- if set to "random", it will +# load a random theme each time oh-my-zsh is loaded, in which case, +# to know which specific one was loaded, run: echo $RANDOM_THEME +# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes +ZSH_THEME="archcraft" + +# typebrook/helper +export SETTING_DIR=$HOME/helper +source $SETTING_DIR/tools/init/load-settings.sh +fpath=($SETTING_DIR/zsh $fpath) + +# Options +setopt extended_glob +setopt HIST_SAVE_NO_DUPS # Do not write a duplicate event to the history file. + +_comp_options+=(globdots) # With hidden files +autoload -Uz compinit; compinit +zstyle ':completion:*' menu select +zstyle ':completion::complete:*' gain-privileges 1 + +# PS1 with git status at right +#autoload -U ps1; ps1 +alias ps1="vim $SETTING_DIR/zsh/ps1" +autoload -Uz add-zsh-hook +add-zsh-hook precmd precmd +function precmd() { + RIGHT=$(NUM=$($SETTING_DIR/tools/git/check-repos.sh -n); (( $NUM != 0 )) && echo $NUM) + PROMPT='%B%(?:%F{green}%m%f:%F{red}%m%f)%f %F{cyan} %c%f%b ' + RPROMPT="%B${RIGHT}%b" +} + +# Directory Stack +#setopt AUTO_PUSHD # Push the current directory visited on the stack. +#setopt PUSHD_IGNORE_DUPS # Do not store duplicates in the stack. +#setopt PUSHD_SILENT # Do not print the directory stack after pushd or popd. + +#alias d='dirs -v' +#for index ({1..9}) alias "$index"="cd +${index}"; unset index + +# create a zkbd compatible hash; +# to add other keys to this hash, see: man 5 terminfo +typeset -g -A key + +key[Home]="${terminfo[khome]}" +key[End]="${terminfo[kend]}" +key[Insert]="${terminfo[kich1]}" +key[Backspace]="${terminfo[kbs]}" +key[Delete]="${terminfo[kdch1]}" +key[Up]="${terminfo[kcuu1]}" +key[Down]="${terminfo[kcud1]}" +key[Left]="${terminfo[kcub1]}" +key[Right]="${terminfo[kcuf1]}" +key[PageUp]="${terminfo[kpp]}" +key[PageDown]="${terminfo[knp]}" +key[Shift-Tab]="${terminfo[kcbt]}" + +# setup key accordingly +bindkey -- "\C-A" beginning-of-line +bindkey -- "\C-E" end-of-line +bindkey -- "${key[Insert]}" overwrite-mode +bindkey -- "\C-D" delete-char +bindkey -- "\C-H" backward-delete-char +bindkey -- "\M-D" delete-word +bindkey -- "\C-W" backward-delete-word +bindkey -- "\C-P" up-line-or-history +bindkey -- "\C-N" down-line-or-history +bindkey -- "\C-B" backward-char +bindkey -- "\C-F" forward-char +bindkey -- "\M-B" backward-word +bindkey -- "\M-F" forward-word +bindkey -- "${key[PageUp]}" beginning-of-buffer-or-history +bindkey -- "${key[PageDown]}" end-of-buffer-or-history +bindkey -- "${key[Shift-Tab]}" reverse-menu-complete + +# Finally, make sure the terminal is in application mode, when zle is +# active. Only then are the values from $terminfo valid. +if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then + autoload -Uz add-zle-hook-widget + function zle_application_mode_start { echoti smkx } + function zle_application_mode_stop { echoti rmkx } + add-zle-hook-widget -Uz zle-line-init zle_application_mode_start + add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop +fi -- cgit v1.2.3-70-g09d2