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 /zsh | |
| parent | bebf6d947abf4637e1239cd902572cd24945e7cc (diff) | |
| download | dotfiles-99b6971f62cdb02d52c3c4f15f84c97dccaeb344.tar.gz dotfiles-99b6971f62cdb02d52c3c4f15f84c97dccaeb344.tar.bz2 dotfiles-99b6971f62cdb02d52c3c4f15f84c97dccaeb344.zip | |
zsh: update rcs and functions
Diffstat (limited to 'zsh')
| -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 |
9 files changed, 87 insertions, 0 deletions
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 |
