improved prompt logic

This commit is contained in:
Bryan Ramos 2024-01-29 16:10:51 -05:00
parent a4f852ec43
commit 45045ed065
Signed by: bryan
GPG key ID: 6ABDCD144D6643C8

View file

@ -38,23 +38,20 @@ set_git_dir() {
} }
check_in_project() { check_in_project() {
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then if git rev-parse --git-dir >/dev/null 2>&1; then
local git_branch=$(git branch --show-current) local git_branch=$(git branch --show-current 2>/dev/null)
local git_root=$(git rev-parse --show-toplevel) git_branch=''${git_branch:-$(git rev-parse --short HEAD)}
local git_dir=$(git rev-parse --git-dir)
local git_root=$(dirname "$(realpath "$git_dir")")
local git_curr_dir=$(realpath --relative-to="$git_root" .) local git_curr_dir=$(realpath --relative-to="$git_root" .)
local git_root_dir=$(basename "$git_root") local git_root_dir=$(basename "$git_root")
if [ -z "$git_branch" ]; then
git_branch=$(git rev-parse --short HEAD)
fi
git_branch_PS1="\[\033[01;31m\]$git_branch 󰘬:\[\033[00m\]" git_branch_PS1="\[\033[01;31m\]$git_branch 󰘬:\[\033[00m\]"
set_git_dir set_git_dir
check_venv check_venv
return 0
fi
} }
function set_prompt() { function set_prompt() {