diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2024-01-29 16:41:49 +0000 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2024-01-29 16:41:49 +0000 |
| commit | 9f9934bad16668fcf0a768cdaa03383d73780e15 (patch) | |
| tree | eb813c56d8d0a1b8cfa176e5d32adfcb64e0db40 /zsh/functions | |
| parent | 44d3b9991efdf49979ec18a676be26c54a0b737e (diff) | |
| parent | 7af82a5580235a7acbaea446192247c3171c6ec3 (diff) | |
Merge branch 'main' of git.sr.ht:~rbdr/dotfiles
Diffstat (limited to 'zsh/functions')
| -rw-r--r-- | zsh/functions/status.zsh | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/zsh/functions/status.zsh b/zsh/functions/status.zsh new file mode 100644 index 0000000..3da8977 --- /dev/null +++ b/zsh/functions/status.zsh @@ -0,0 +1,61 @@ +function tool_versions() { + if [[ -s ".tool-versions" ]]; then + echo '.tool-versions' + return + fi + echo "${HOME}/.tool-versions" +} + +function env_info_provider() { echo "%{%F{green}%}n/a"; } +function env_info { + echo "[%{%F{cyan}%}ENV%{%F{black}%} $(env_info_provider)%{%F{black}%}]" +} + +function python_info { + pythoninfo=`cat "$(tool_versions)" | rg python | cut -d ' ' -f 2` + pythoninfo=${ASDF_PYTHON_VERSION:-$pythoninfo} + venv="${VIRTUAL_ENV##*/}" + echo "%{%F{green}%}py%{%F{black}%} ${pythoninfo:-no}@${venv:-default}" +} + +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 { + nodeinfo=`cat "$(tool_versions)" | rg nodejs | cut -d ' ' -f 2` + nodeinfo=${ASDF_NODEJS_VERSION:-$nodeinfo} + 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" | rg -q '^??'; then + echo -n "%{%F{magenta}%}?%f" + fi + + if echo "$status_output" | rg -q '^ M'; then + echo -n "%{%F{magenta}%}!%f" + fi + + if echo "$status_output" | rg -q '^ D'; then + echo -n "%{%F{magenta}%}×%f" + fi + + if echo "$status_output" | rg -q '^A '; then + echo -n "%{%F{green}%}+%f" + fi + fi +} + +function status { + print -P '%{%F{black}%}$(env_info) $(node_info) $(rust_info) $(python_info)' +} |