Trying to add dynamic root directory

This commit is contained in:
Bryan Ramos 2023-06-02 12:48:51 -04:00
parent a664f2bd62
commit 78fce82d78

View file

@ -17,8 +17,12 @@ is_ssh_session() {
#TODO: Change ps1 to project root in nix shells #TODO: Change ps1 to project root in nix shells
# PS1 Config # PS1 Config
# PS1 Config
function set_ps1_prompt() { function set_ps1_prompt() {
local git_branch="" local git_branch=""
local flake_icon=""
local cur_dir=""
# Check if we're inside a git repository # Check if we're inside a git repository
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
# If we are, get the current branch name # If we are, get the current branch name
@ -28,27 +32,39 @@ function set_ps1_prompt() {
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
git_branch="$(git rev-parse --short HEAD 2>/dev/null)" git_branch="$(git rev-parse --short HEAD 2>/dev/null)"
fi fi
# Wrap the branch name in braces and color it red
git_branch=" \[\033[01;31m\]$git_branch 󰘬:\[\033[00m\]"
# Wrap the branch name and : in braces and color it red
git_branch=" \[\033[01;31m\]{$git_branch}:\[\033[00m\]"
# Check if flake.nix file exists
if [ -f "$(git rev-parse --show-toplevel)/flake.nix" ]; then if [ -f "$(git rev-parse --show-toplevel)/flake.nix" ]; then
# If it exists, set the flake icon and color it blue # If it exists, set the flake icon and color it blue
flake_icon=" \[\033[01;34m\]\[\033[00m\]" flake_icon=" \[\033[01;34m\]\[\033[00m\]"
fi fi
# Get the current directory relative to the Git root
cur_dir=$(realpath --relative-to=$(git rev-parse --show-toplevel) .)
if [ "$cur_dir" == "." ]; then
cur_dir="\[\033[01;34m\]~\[\033[00m\]"
else
cur_dir="\[\033[01;34m\]~/$cur_dir\[\033[00m\]"
fi
else
# If not in a Git repository, just show the normal path
cur_dir="\[\033[01;34m\]\w\[\033[00m\]"
fi fi
if [ -n "${IN_NIX_SHELL:+x}" ]; then if [ -n "${IN_NIX_SHELL:+x}" ]; then
PS1="\[\033[01;34m\]\w\[\033[00m\]\n$flake_icon \[\033[01;32m\]nixShell>$git_branch\[\033[00m\]" PS1="$cur_dir\n$flake_icon \[\033[01;32m\]nixShell >$git_branch \[\033[00m\]"
else else
if ! is_ssh_session; then if ! is_ssh_session; then
PS1="\n\[\033[01;34m\]\w\[\033[00m\]\n$flake_icon \[\033[01;32m\]>$git_branch\[\033[00m\]" PS1="\n$cur_dir\n$flake_icon \[\033[01;32m\]> $git_branch\[\033[00m\]"
else else
PS1="\n\[\033[01;34m\]\w\[\033[00m\]\n\[\033[01;32m\]\u@\h:\[\033[00m\] " PS1="\n\[\033[01;34m\]\w\[\033[00m\]\n\[\033[01;32m\]\u@\h:\[\033[00m\] "
fi fi
fi fi
unset flake_icon unset flake_icon
} }
PROMPT_COMMAND="set_ps1_prompt; $PROMPT_COMMAND" PROMPT_COMMAND="set_ps1_prompt; $PROMPT_COMMAND"
# Locate and source the bash-completion scripts # Locate and source the bash-completion scripts