From: Armaan Bhojwani <3fb650a9-b47e-4604-a282-1dd91953b2ee@anonaddy.me> Date: Fri, 27 Nov 2020 20:00:05 +0000 (-0500) Subject: change vcs function to use Zsh builtin X-Git-Url: https://git.armaanb.net/?p=admone.git;a=commitdiff_plain;h=db2076f91e5de878e376a14b086416c5885c46fa change vcs function to use Zsh builtin * The admone-git function is now called admone-vcs and uses Zsh's builtin VCS information system * Did some refactoring of the for loop in the set-prompt function to potentially speed it up a bit * Added software description to license file * Removed some unecesary config variables at the start of the file --- diff --git a/LICENSE b/LICENSE index 69e17a3..68ab45b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,5 @@ +Admone - a tolerable Zsh prompt + Copyright © 2020 Armaan Bhojwani Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index 7ab00fd..0931a26 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # admone -A tolerable ZSH prompt +A tolerable Zsh prompt ![Screenshot](branding/screenshot.png) ## Installation -Source this script somewhere in your ZSHRC. Theoretically works with plugin managers as well, although this is untested +Source this script somewhere in your Zshrc. Theoretically works with plugin managers as well, although this is untested ## Configuration Configuration is done by modifying the variables set at the start of the script. Just get in there and mess around a bit, its not very difficult to understand diff --git a/admone.zsh b/admone.zsh index 9b5e9d4..a9f0781 100644 --- a/admone.zsh +++ b/admone.zsh @@ -1,5 +1,5 @@ ####################################################################### -# Admone ZSH prompt. Copyright Armaan Bhojwani. MIT licensed, see the # +# Admone Zsh prompt. Copyright Armaan Bhojwani. MIT licensed, see the # # LICENSE file or https://www.opensource.org/licenses/MIT for more # # information. Git repo at https://codeberg.org/armaan/admone # ####################################################################### @@ -23,26 +23,26 @@ ADMONE_BLOCK_SEPARATOR="─" # ADMONE_BLOCK_SEPARATOR="∙" ADMONE_BLOCK_LEFT="[" ADMONE_BLOCK_RIGHT="]" - # ADMONE_BLOCK_LEFT="{" - # ADMONE_BLOCK_RIGHT="}" # ADMONE_BLOCK_LEFT="(" # ADMONE_BLOCK_RIGHT=")" -ADMONE_VI_MODE_CURSOR="1" - # ADMONE_VI_MODE_CURSOR="1" ADMONE_SHOW_0_EXIT_CODE="0" -ADMONE_INCLUDE="admone-pwd;admone-git;admone-exit-code" +ADMONE_INCLUDE="admone-pwd;admone-vcs;admone-exit-code" ADMONE_FORMAT_LOWER="%B%F{%(?.cyan.red)}" +zstyle ':vcs_info:git:*' formats '%b%u%c' +zstyle ':vcs_info:git:*' actionformats '%b|%a%u%c' +zstyle ':vcs_info:*' unstagedstr ' *' +zstyle ':vcs_info:*' stagedstr ' +' + admone-pwd() { echo "%F{blue}%~%f" } -admone-git() { - git_branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)" - echo "%F{green}${git_branch}%f" +admone-vcs() { + echo "%F{green}${vcs_info_msg_0_}%f" } admone-exit-code() { ([[ $ADMONE_SHOW_0_EXIT_CODE == "1" ]] && echo "%(?,%F{cyan}%?%f,%F{red}%?%f)") || - echo "%(?,,%F{red}%?%f)" + echo "%(?,,%F{red}%?%f)" } admone-date() { echo $(date -I) @@ -66,20 +66,18 @@ admone-time() { # Cursor shape depends on vi mode function zle-keymap-select zle-line-init zle-line-finish { - if [[ $ADMONE_VI_MODE_CURSOR == "1" ]]; then - case $KEYMAP in - vicmd) - # Block - print -n -- "\E]50;CursorShape=0\C-G" - ;; - viins|main) - # Beam - print -n -- "\E]50;CursorShape=1\C-G" - ;; - esac - zle reset-prompt - zle -R - fi + case $KEYMAP in + vicmd) + # Block + print -n -- "\E]50;CursorShape=0\C-G" + ;; + viins|main) + # Beam + print -n -- "\E]50;CursorShape=1\C-G" + ;; + esac + zle reset-prompt + zle -R } set-prompt() { @@ -89,10 +87,13 @@ set-prompt() { # Add in functions as defined above NUM_FUNCS="$(echo $ADMONE_INCLUDE | grep -o ';' | wc -l)" - for (( i = 0; i <= $NUM_FUNCS; i++ )); do - THE_COMMAND="$(echo $ADMONE_INCLUDE | cut -d ';' -f $(($i + 1)))" - [[ $i == 0 ]] && upper+="$ADMONE_BLOCK_LEFT$($THE_COMMAND)$ADMONE_BLOCK_RIGHT" - [[ $i == 0 ]] || upper+="$ADMONE_BLOCK_SEPARATOR$ADMONE_BLOCK_LEFT$($THE_COMMAND)$ADMONE_BLOCK_RIGHT" + + THE_COMMAND="$(echo $ADMONE_INCLUDE | cut -d ';' -f 1)" + upper+="$ADMONE_BLOCK_LEFT$($THE_COMMAND)$ADMONE_BLOCK_RIGHT" + + for (( i = 0; i < $NUM_FUNCS; i++ )); do + THE_COMMAND="$(echo $ADMONE_INCLUDE | cut -d ';' -f $(($i + 2)))" + upper+="$ADMONE_BLOCK_SEPARATOR$ADMONE_BLOCK_LEFT$($THE_COMMAND)$ADMONE_BLOCK_RIGHT" done # Add line above @@ -102,8 +103,16 @@ set-prompt() { } # Set everything! +if [[ ! $(echo $ADMONE_INCLUDE | grep -q "vcs") ]]; then + zstyle ':vcs_info:*' check-for-changes true + autoload -Uz add-zsh-hook vcs-info + add-zsh-hook precmd vcs_info + add-zsh-hook precmd set-prompt +else + autoload -Uz add-zsh-hook + add-zsh-hook precmd set-prompt +fi + zle -N zle-line-init zle -N zle-line-finish zle -N zle-keymap-select -autoload -Uz add-zsh-hook -add-zsh-hook precmd set-prompt