]> git.armaanb.net Git - admone.git/commitdiff
change vcs function to use Zsh builtin
authorArmaan Bhojwani <3fb650a9-b47e-4604-a282-1dd91953b2ee@anonaddy.me>
Fri, 27 Nov 2020 20:00:05 +0000 (15:00 -0500)
committerArmaan Bhojwani <3fb650a9-b47e-4604-a282-1dd91953b2ee@anonaddy.me>
Fri, 27 Nov 2020 20:00:05 +0000 (15:00 -0500)
  * 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

LICENSE
README.md
admone.zsh

diff --git a/LICENSE b/LICENSE
index 69e17a33a2c36ff7ba0778357b485470323201ef..68ab45b0b9c2b7ceea0c3bd8acf81d5db2b43684 100644 (file)
--- 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:
index 7ab00fdf64750edc7cb2f5347af1934eab41cee1..0931a26ead6d44eb88813f2f71d1a142705018bd 100644 (file)
--- 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
index 9b5e9d4b33704fa8696a50c380c3057246d1ae45..a9f0781169f6a1bb67d772987064cab481888306 100644 (file)
@@ -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