mirror of
https://github.com/itme-brain/nixos.git
synced 2026-03-24 00:29:43 -04:00
its time
This commit is contained in:
parent
cc18493707
commit
6fff6d1845
673 changed files with 1070 additions and 124971 deletions
55
homeConfig/modules/bash/config/prompt.nix
Normal file
55
homeConfig/modules/bash/config/prompt.nix
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
''
|
||||
eval "$(direnv hook bash)"
|
||||
|
||||
is_ssh_session() {
|
||||
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function set_ps1_prompt() {
|
||||
local git_branch=""
|
||||
local flake_icon=""
|
||||
local cur_dir=""
|
||||
|
||||
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
git_branch="$(git symbolic-ref --short HEAD 2>/dev/null)"
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
git_branch="$(git rev-parse --short HEAD 2>/dev/null)"
|
||||
fi
|
||||
|
||||
git_branch=" \[\033[01;31m\]$git_branch:\[\033[00m\]"
|
||||
|
||||
if [ -f "$(git rev-parse --show-toplevel)/flake.nix" ]; then
|
||||
# If it exists, set the flake icon and color it blue
|
||||
flake_icon="\[\033[01;34m\] \[\033[00m\]"
|
||||
fi
|
||||
|
||||
git_root="$(basename "$(git rev-parse --show-toplevel)")"
|
||||
|
||||
cur_dir=$(realpath --relative-to=$(git rev-parse --show-toplevel) .)
|
||||
if [ "$cur_dir" == "." ]; then
|
||||
cur_dir="\[\033[01;34m\] $git_root\[\033[00m\]"
|
||||
else
|
||||
cur_dir="\[\033[01;34m\] $git_root/$cur_dir\[\033[00m\]"
|
||||
fi
|
||||
else
|
||||
cur_dir="\[\033[01;34m\]\w\[\033[00m\]"
|
||||
fi
|
||||
|
||||
if [ -n "''${IN_NIX_SHELL:+x}" ]; then
|
||||
PS1="$cur_dir\n$flake_icon\[\033[01;32m\]nixShell>$git_branch\[\033[00m\]"
|
||||
else
|
||||
if ! is_ssh_session; then
|
||||
PS1="\n$cur_dir\n$flake_icon\[\033[01;32m\]>$git_branch\[\033[00m\]"
|
||||
else
|
||||
PS1="\n\[\033[01;34m\]\w\[\033[00m\]\n\[\033[01;32m\]\u@\h:\[\033[00m\] "
|
||||
fi
|
||||
fi
|
||||
unset flake_icon
|
||||
}
|
||||
PROMPT_COMMAND="set_ps1_prompt; $PROMPT_COMMAND"
|
||||
''
|
||||
Loading…
Add table
Add a link
Reference in a new issue