aboutsummaryrefslogtreecommitdiff
path: root/zsh/modules
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2023-08-30 22:33:43 +0200
committerRuben Beltran del Rio <ruben@unlimited.pizza>2023-08-30 22:33:43 +0200
commit6f7715ef506f39a0b0d9a5cd2afc7ed7a7202064 (patch)
treea300fa7421a2c6c2a6640dd404890f9cf95deeaf /zsh/modules
parent293e8758eaf227227c100bf4c4317888c1717617 (diff)
Use a lighter git info
Diffstat (limited to 'zsh/modules')
-rw-r--r--zsh/modules/prompt.zsh61
1 files changed, 33 insertions, 28 deletions
diff --git a/zsh/modules/prompt.zsh b/zsh/modules/prompt.zsh
index beeb85d..18e5cc4 100644
--- a/zsh/modules/prompt.zsh
+++ b/zsh/modules/prompt.zsh
@@ -13,14 +13,6 @@ if [[ "$TERM" == (dumb|linux|*bsd*) ]] || (( $#prompt_argv < 1 )); then
fi
#
-# Precmd
-#
-
-function prompt_precmd {
- git-info
-}
-
-#
# Functions
#
@@ -36,10 +28,10 @@ function python_info {
echo "%{%F{green}%}py%{%F{black}%} ${pythoninfo:-no}@${venv:-default}"
}
-function ruby_info {
- rubyinfo=`cat "$(tool_versions)" | rg ruby | cut -d ' ' -f 2`
- rubyinfo=${ASDF_RUBY_VERSION:-$rubyinfo}
- echo "%{%F{red}%}rb%{%F{black}%} ${rubyinfo:-no}"
+function rust_info {
+ rustinfo=`cat "$(tool_versions)" | rg rust | cut -d ' ' -f 2`
+ rustinfo=${ASDF_RUST_VERSION:-$rustinfo}
+ echo "%{%F{red}%}rs%{%F{black}%} ${rustinfo:-no}"
}
function node_info {
@@ -48,6 +40,32 @@ function node_info {
echo "%{%F{yellow}%}js%{%F{black}%} ${nodeinfo:-no}"
}
+function git_info {
+ branch=$(git branch --show-current 2> /dev/null)
+
+ if [ ! -z $branch ]; then
+ echo -n "@%F{cyan}$branch%f"
+
+ status_output=$(git status --short)
+
+ if echo "$status_output" | grep -q '^??'; then
+ echo -n "%{%F{magenta}%}?%f"
+ fi
+
+ if echo "$status_output" | grep -q '^ M'; then
+ echo -n "%{%F{magenta}%}!%f"
+ fi
+
+ if echo "$status_output" | grep -q '^ D'; then
+ echo -n "%{%F{magenta}%}×%f"
+ fi
+
+ if echo "$status_output" | grep -q '^A '; then
+ echo -n "%{%F{green}%}+%f"
+ fi
+ fi
+}
+
function box_name {
[ -f ~/.box-name ] && cat ~/.box-name || hostname -s
}
@@ -92,24 +110,11 @@ function prompt_setup {
# Load required functions.
autoload -Uz add-zsh-hook
- # Add hook for calling git-info before each command.
- add-zsh-hook precmd prompt_precmd
-
- # Set git-info parameters.
- zstyle ':git:info' verbose 'no'
- zstyle ':git:info:branch' format '@%F{cyan}%b%f'
- zstyle ':git:info:clean' format ''
- zstyle ':git:info:added' format '%{%F{green}%}!'
- zstyle ':git:info:modified' format '%{%F{green}%}?'
- zstyle ':git:info:untracked' format '%{%F{magenta}%}?'
- zstyle ':git:info:keys' format \
- 'prompt' '%b%a%m%u'
-
# Define prompts.
PROMPT='
-%{%F{black}%}$(env_info) $(node_info) $(ruby_info) $(python_info)
-%{%F{magenta}%}%n%{%f%}@%{%F{yellow}%}$(box_name)%{%f%} %{%B%F{green}%}${PWD/#$HOME/~}%{%f%b%}${git_info[prompt]} %{%f%}
-%(?,,%{${%B%F{white}%}[%?]%{%f%b%} )$ '
+%{%F{black}%}$(env_info) $(node_info) $(rust_info) $(python_info)
+%{%F{magenta}%}%n%{%f%}@%{%F{yellow}%}$(box_name)%{%f%} %{%B%F{green}%}${PWD/#$HOME/~}%{%f%b%}$(git_info)%{%f%}
+%(?,,%{${%B%F{white}%}[%?]%{%f%b%} )%% '
}
prompt_setup "$@"