diff options
| author | Xian Wang <dev@xianwang.io> | 2022-03-23 10:12:52 -0400 |
|---|---|---|
| committer | Xian Wang <dev@xianwang.io> | 2022-03-23 10:12:52 -0400 |
| commit | 99b6971f62cdb02d52c3c4f15f84c97dccaeb344 (patch) | |
| tree | 58c94010cd51514b9e515573b3fb8b51ef51adc6 | |
| parent | bebf6d947abf4637e1239cd902572cd24945e7cc (diff) | |
| download | dotfiles-99b6971f62cdb02d52c3c4f15f84c97dccaeb344.tar.gz dotfiles-99b6971f62cdb02d52c3c4f15f84c97dccaeb344.tar.bz2 dotfiles-99b6971f62cdb02d52c3c4f15f84c97dccaeb344.zip | |
zsh: update rcs and functions
| -rw-r--r-- | install.conf.yaml | 8 | ||||
| -rw-r--r-- | zsh/functions/chpwd_update_git_vars | 1 | ||||
| -rw-r--r-- | zsh/functions/fake-enter | 4 | ||||
| -rw-r--r-- | zsh/functions/precmd_term_title | 1 | ||||
| -rw-r--r-- | zsh/functions/precmd_update_git_vars | 4 | ||||
| -rw-r--r-- | zsh/functions/preexec_term_title | 3 | ||||
| -rw-r--r-- | zsh/functions/preexec_update_git_vars | 5 | ||||
| -rw-r--r-- | zsh/functions/prompt_git_info | 22 | ||||
| -rw-r--r-- | zsh/functions/term_title | 4 | ||||
| -rw-r--r-- | zsh/functions/update_current_git_vars | 43 | ||||
| -rw-r--r-- | zshrc | 206 |
11 files changed, 267 insertions, 34 deletions
diff --git a/install.conf.yaml b/install.conf.yaml index fec4bbc..21c16f6 100644 --- a/install.conf.yaml +++ b/install.conf.yaml @@ -10,14 +10,18 @@ - link: ~/.config/fontconfig/fonts.conf: - path: config/fontconfig/fonts.conf create: true force: true + path: config/fontconfig/fonts.conf ~/.gnupg/gpg-agent.conf: path: gnupg/gpg-agent.conf ~/.vimrc: + force: true path: vimrc + ~/.zsh/functions: + create: true force: true + path: zsh/functions ~/.zshrc: - path: zshrc force: true + path: zshrc diff --git a/zsh/functions/chpwd_update_git_vars b/zsh/functions/chpwd_update_git_vars new file mode 100644 index 0000000..84860d7 --- /dev/null +++ b/zsh/functions/chpwd_update_git_vars @@ -0,0 +1 @@ +update_current_git_vars diff --git a/zsh/functions/fake-enter b/zsh/functions/fake-enter new file mode 100644 index 0000000..0582c26 --- /dev/null +++ b/zsh/functions/fake-enter @@ -0,0 +1,4 @@ +fake-enter() { + print -s "$BUFFER" + zle send-break +} diff --git a/zsh/functions/precmd_term_title b/zsh/functions/precmd_term_title new file mode 100644 index 0000000..c035974 --- /dev/null +++ b/zsh/functions/precmd_term_title @@ -0,0 +1 @@ +term_title "zsh [`print -Pn "%~"`]" diff --git a/zsh/functions/precmd_update_git_vars b/zsh/functions/precmd_update_git_vars new file mode 100644 index 0000000..c08c41a --- /dev/null +++ b/zsh/functions/precmd_update_git_vars @@ -0,0 +1,4 @@ +if [ -n "$__EXECUTED_GIT_COMMAND" ]; then + update_current_git_vars + unset __EXECUTED_GIT_COMMAND +fi diff --git a/zsh/functions/preexec_term_title b/zsh/functions/preexec_term_title new file mode 100644 index 0000000..d551094 --- /dev/null +++ b/zsh/functions/preexec_term_title @@ -0,0 +1,3 @@ +emulate -L zsh +local -a cmd; cmd=(${(z)1}) +term_title "$cmd" diff --git a/zsh/functions/preexec_update_git_vars b/zsh/functions/preexec_update_git_vars new file mode 100644 index 0000000..2b6245d --- /dev/null +++ b/zsh/functions/preexec_update_git_vars @@ -0,0 +1,5 @@ +case "$1" in + git*) + __EXECUTED_GIT_COMMAND=1 + ;; +esac diff --git a/zsh/functions/prompt_git_info b/zsh/functions/prompt_git_info new file mode 100644 index 0000000..6098669 --- /dev/null +++ b/zsh/functions/prompt_git_info @@ -0,0 +1,22 @@ +if [ -n "$__CURRENT_GIT_BRANCH" ]; then + local s=":" + s+="$__CURRENT_GIT_BRANCH" + + case "$__CURRENT_GIT_BRANCH_STATUS" in + ahead) + s+="↑" + ;; + diverged) + s+="↕" + ;; + behind) + s+="↓" + ;; + esac + + if [ -n "$__CURRENT_GIT_BRANCH_IS_DIRTY" ]; then + s+="⚡" + fi + + echo $s +fi diff --git a/zsh/functions/term_title b/zsh/functions/term_title new file mode 100644 index 0000000..f294310 --- /dev/null +++ b/zsh/functions/term_title @@ -0,0 +1,4 @@ +if [[ $TERM == "screen" ]]; then + print -nR $'\033k'$1$'\033'\\ +fi +print -nR $'\033]0;'$1$'\a' diff --git a/zsh/functions/update_current_git_vars b/zsh/functions/update_current_git_vars new file mode 100644 index 0000000..0e65c37 --- /dev/null +++ b/zsh/functions/update_current_git_vars @@ -0,0 +1,43 @@ +# based on http://sebastiancelis.com/2009/nov/16/zsh-prompt-git-users/ +unset __CURRENT_GIT_BRANCH +unset __CURRENT_GIT_BRANCH_STATUS +unset __CURRENT_GIT_BRANCH_IS_DIRTY + +local git_dir head + +git_dir="$(git rev-parse --git-dir 2>/dev/null)" + +if [[ -n "$git_dir" ]] ; then + head=$(cat "$git_dir/HEAD") + if [[ $head =~ '^ref: ' ]]; then + __CURRENT_GIT_BRANCH=$(expr "$head" : 'ref: refs/heads/\(.*\)') + else + __CURRENT_GIT_BRANCH="no-branch" + fi +fi + +#local st="$(git status 2>/dev/null)" +#if [[ -n "$st" ]]; then +# local -a arr +# arr=(${(f)st}) +# +# if [[ $arr[1] =~ 'Not currently on any branch.' ]]; then +# __CURRENT_GIT_BRANCH='no-branch' +# else +# __CURRENT_GIT_BRANCH="${arr[1][(w)4]}"; +# fi +# +# if [[ $arr[2] =~ 'Your branch is' ]]; then +# if [[ $arr[2] =~ 'ahead' ]]; then +# __CURRENT_GIT_BRANCH_STATUS='ahead' +# elif [[ $arr[2] =~ 'diverged' ]]; then +# __CURRENT_GIT_BRANCH_STATUS='diverged' +# else +# __CURRENT_GIT_BRANCH_STATUS='behind' +# fi +# fi +# +# if [[ ! $st =~ 'nothing to commit' ]]; then +# __CURRENT_GIT_BRANCH_IS_DIRTY='1' +# fi +#fi @@ -1,47 +1,189 @@ -autoload -U compinit -compinit -zstyle ':completion:*:descriptions' format '%U%B%d%b%u' -zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b' +# few terminal keybinds +bindkey -e -setopt correct +typeset -A key -export HISTSIZE=2000 -export HISTFILE="$HOME/.history" -export SAVEHIST=$HISTSIZE -setopt hist_ignore_all_dups -setopt hist_ignore_space +key[Home]=${terminfo[khome]} +key[End]=${terminfo[kend]} +key[Insert]=${terminfo[kich1]} +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]} -setopt autocd -setopt extendedglob -setopt prompt_subst +# setup key accordingly +[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line +[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line +[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" overwrite-mode +[[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char +[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-history +[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-history +[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char +[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char -autoload -Uz vcs_info -zstyle ':vcs_info:git*' formats '[%b] ' +# Finally, make sure the terminal is in application mode, when zle is +# active. Only then are the values from $terminfo valid. +if [[ -n ${terminfo[smkx]} ]] && [[ -n ${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 + +zle -N fake-enter; bindkey "^X^H" fake-enter + +# colors +autoload -U colors +colors + +# aliases +alias mv='nocorrect mv' +alias cp='nocorrect cp' +alias rm='rm' +alias mkdir='nocorrect mkdir' + +alias ls="ls --color=auto" +alias ll="ls --color -l" +alias la="ls --color -la" +alias lt="ls --sort=time" +alias lat="ls --color -la --sort=time" + +alias rh='fc -R' + +autoload run-help + +# zsh parameters +typeset -U path +path+=(~/.local/bin) + +#cdpath=(. ~) +DIRSTACKSIZE=60 -bindkey "^[[1;5C" forward-word -bindkey "^[[1;5D" backward-word +# Autoload zsh functions. +fpath=(~/.zsh/functions $fpath) +autoload -U ~/.zsh/functions/*(:t) -precmd() { vcs_info } +fignore=(\~) -if [ $UID -eq 0 ]; then - local user_prompt=$'\U26A0\UFE0F'" %F{red}%n%f" +LISTMAX=0 +LOGCHECK=60 +HISTSIZE=20000 +HISTFILE=~/.zsh_history +MAILCHECK=1 +READNULLCMD=less +REPORTTIME=15 +SAVEHIST=30000000 +TIMEFMT='%J %*U user %*S system %P cpu (%*E wasted time).' +watch=(all) +WATCHFMT='%n %a %l from %m at %t.' +WORDCHARS="${WORDCHARS:s#/#}" + +# zsh options +setopt \ + auto_cd \ + auto_name_dirs \ + auto_pushd \ + auto_resume \ + no_beep \ + cdable_vars \ + csh_null_glob \ + correct \ + correct_all \ + extended_glob \ + extended_history \ + no_glob_dots \ + hist_allow_clobber \ + hist_find_no_dups \ + no_hist_ignore_all_dups \ + hist_ignore_dups \ + hist_reduce_blanks \ + no_hist_save_no_dups \ + inc_append_history \ + no_list_ambiguous \ + no_list_beep \ + long_list_jobs \ + magic_equal_subst \ + no_notify \ + prompt_subst \ + pushd_minus \ + pushd_silent \ + pushd_to_home \ + rc_quotes \ + no_share_history \ + shwordsplit \ + transient_rprompt \ + hist_ignore_space \ + no_equals \ + +# modules +autoload -U url-quote-magic bracketed-paste-magic +zle -N self-insert url-quote-magic +zle -N bracketed-paste bracketed-paste-magic + +# Enable auto-execution of functions. +unset preexec_functions +unset precmd_functions +unset chpwd_functions +typeset -ga preexec_functions +typeset -ga precmd_functions +typeset -ga chpwd_functions + +# Terminal title +if [[ "$TERM" == xterm* ]] ; then + preexec_functions+='preexec_term_title' + precmd_functions+='precmd_term_title' +fi + +# prompt +if [[ "$USER" == "root" ]] ; then + PROMPT=$'\U26A0\UFE0F ''%B%F{red}%n%b%F{default}@%B%F{cyan}%m%b%F{default}:%B%F{blue}%~%b%F{default}%F{default} %(?.-.%F{red}%?%F{default})%(!.%F{red}#%F{default}.%F{green}$%F{default}) ' else - local user_prompt="%F{green}%n%f" + preexec_functions+='preexec_update_git_vars' + precmd_functions+='precmd_update_git_vars' + chpwd_functions+='chpwd_update_git_vars' + PROMPT=$'%B%F{green}%n%b%F{default}@%B%F{cyan}%m%b%F{default}:%B%F{blue}%~%b%F{default}%F{yellow}$(prompt_git_info)%F{default} %(?.-.%F{red}%?%F{default})%(!.%F{red}#%F{default}.%F{green}$%F{default}) ' fi -export PS1='$user_prompt@%M %F{cyan}%2~%f ${vcs_info_msg_0_}%(?..%F{red}[%?]%f )%# ' +# tab-completion +autoload -Uz compinit +[[ -d "${ZDOTDIR:-$HOME}/.zcompdumps" ]] || mkdir -m 0700 -p "${ZDOTDIR:-$HOME}/.zcompdumps" +compinit -i -d "${ZDOTDIR:-$HOME}/.zcompdumps/${HOST%%.*}-$ZSH_VERSION" -alias l="ls -lah" -alias ll="ls -lh" -alias okular="setsid okular" +zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*' menu select=1 +zstyle ':completion::complete:cd::' tag-order '! users' - +zstyle ':completion::complete:-command-::' tag-order '! users' - -export PATH="$HOME/bin:$PATH" -export PATH="$HOME/.local/bin:$PATH" +zstyle ':completion:*:sudo:*' command-path /usr/local/sbin /usr/local/bin \ + /usr/sbin /usr/bin /sbin /bin /usr/X11R6/bin +zstyle -e ':completion:*:approximate:*' max-errors 'reply=( $(( ($#PREFIX + $#SUFFIX) / 3 )) )' +zstyle ':completion:*:descriptions' format "- %d -" +zstyle ':completion:*:corrections' format "- %d - (errors %e})" +zstyle ':completion:*:default' list-prompt '%S%M matches%s' +zstyle ':completion:*' group-name '' +zstyle ':completion:*:manuals' separate-sections true +zstyle ':completion:*:manuals.(^1*)' insert-sections true +zstyle ':completion:*' menu select +zstyle ':completion:*' verbose yes +zstyle ':completion:*:kill:*:processes' command "ps x" +zstyle ':completion:*' use-cache on +zstyle ':completion:*' cache-path ~/.zsh/cache +zstyle ':completion:*' special-dirs true -rh() { - exec zsh +# misc functions +stfu() { + "$@" &>/dev/null </dev/null } -bz() { - setsid "$@" &> /dev/null < /dev/null -} +_comp_options=("${(@)_comp_options:#NO_ignoreclosebraces}") + +[[ -e ~/.shfuncs ]] && source ~/.shfuncs + +setopt notify |
