fixed git module prompt

This commit is contained in:
Bryan Ramos 2024-02-28 09:02:03 -05:00
parent 38cc658ca0
commit 26e1521491
Signed by: bryan
GPG key ID: 6ABDCD144D6643C8

View file

@ -25,6 +25,10 @@ nix_icon="\[\033[01;34m\] \[\033[00m\]"
check_venv() { check_venv() {
if [ -n "$IN_NIX_SHELL" ]; then if [ -n "$IN_NIX_SHELL" ]; then
add_icon "$nix_icon" add_icon "$nix_icon"
else
remove_icon "$nix_icon"
fi
if [ -n "$VIRTUAL_ENV" ]; then if [ -n "$VIRTUAL_ENV" ]; then
add_icon "$python_icon" add_icon "$python_icon"
else else
@ -36,14 +40,16 @@ check_venv() {
else else
remove_icon "$node_icon" remove_icon "$node_icon"
fi fi
else
remove_icon "$nix_icon"
return 0
fi
} }
set_git_dir() { set_git_dir() {
if [ "$git_curr_dir" == "." ]; then local superproject_root=$(git rev-parse --show-superproject-working-tree 2>/dev/null)
if [[ -n "$superproject_root" ]]; then
# If inside a submodule, display only the root of the parent and the submodule name
local submodule_name=$(basename "$git_root")
working_dir="\[\033[01;34m\] ''${superproject_root##*/}/$submodule_name$git_curr_dir\[\033[00m\]"
elif [ "$git_curr_dir" == "." ]; then
working_dir="\[\033[01;34m\] $git_root_dir\[\033[00m\]" working_dir="\[\033[01;34m\] $git_root_dir\[\033[00m\]"
return 0 return 0
else else
@ -59,15 +65,12 @@ relative_path() {
} }
check_project() { check_project() {
local git_dir=$(git rev-parse --git-dir 2>/dev/null) local git_root=$(git rev-parse --show-toplevel 2>/dev/null)
if [ -n "$git_dir" ]; then if [ -n "$git_root" ]; then
local git_branch=$(git branch --show-current 2>/dev/null) local git_branch=$(git branch --show-current 2>/dev/null)
git_branch=''${git_branch:-$(git rev-parse --short HEAD 2>/dev/null)} git_branch=''${git_branch:-$(git rev-parse --short HEAD 2>/dev/null)}
local git_dir=$(git rev-parse --git-dir)
local git_root=$(dirname "$(readlink -f "$git_dir")")
local git_curr_dir=$(relative_path "." "$git_root") local git_curr_dir=$(relative_path "." "$git_root")
local git_root_dir=$(basename "$git_root") local git_root_dir=$(basename "$git_root")