mirror of
https://github.com/itme-brain/nixos.git
synced 2026-03-24 00:29:43 -04:00
Update promptooor
This commit is contained in:
parent
2a67b95d79
commit
1cf1cdf1cd
2 changed files with 48 additions and 47 deletions
|
|
@ -1,60 +1,59 @@
|
|||
''
|
||||
eval "$(direnv hook bash)"
|
||||
|
||||
is_ssh_session() {
|
||||
check_ssh() {
|
||||
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
ssh_PS1="\n\[\033[01;37m\]\u@\h:\[\033[00m\]"
|
||||
fi
|
||||
}
|
||||
|
||||
function set_ps1_prompt() {
|
||||
local git_branch=""
|
||||
local flake_icon=""
|
||||
local python_icon=""
|
||||
local cur_dir=""
|
||||
function check_venv() {
|
||||
if [ -n "''${IN_NIX_SHELL}" ]; then
|
||||
if [ -n "$VIRTUAL_ENV" ]; then
|
||||
python_icon="\[\033[01;33m\] \[\033[00m\]"
|
||||
else
|
||||
unset python_icon
|
||||
fi
|
||||
nix_icon="\[\033[01;34m\] \[\033[00m\]"
|
||||
else
|
||||
unset nix_icon
|
||||
fi
|
||||
}
|
||||
|
||||
function set_git_dir() {
|
||||
local git_curr_dir=$(realpath --relative-to="$git_root" .)
|
||||
if [ "$git_curr_dir" == "." ]; then
|
||||
working_dir="\[\033[01;34m\] $git_root_dir\[\033[00m\]"
|
||||
else
|
||||
working_dir="\[\033[01;34m\] $git_root_dir/$git_curr_dir\[\033[00m\]"
|
||||
fi
|
||||
}
|
||||
|
||||
function check_git() {
|
||||
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)"
|
||||
local git_branch=$(git branch --show-current)
|
||||
if [ -z "$git_branch" ]; then
|
||||
git_branch=$(git rev-parse --short HEAD)
|
||||
fi
|
||||
|
||||
git_branch="\[\033[01;31m\]$git_branch :\[\033[00m\]"
|
||||
local git_root=$(git rev-parse --show-toplevel)
|
||||
local git_root_dir=$(basename "$git_root")
|
||||
git_branch_PS1="\[\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\]"
|
||||
set_git_dir
|
||||
fi
|
||||
|
||||
if [[ -n "$VIRTUAL_ENV" ]]; then
|
||||
python_icon="\[\033[01;33m\] \[\033[00m\]"
|
||||
fi
|
||||
|
||||
if [ -n "''${IN_NIX_SHELL:+x}" ]; then
|
||||
PS1="$cur_dir\n$flake_icon$python_icon\[\033[01;32m\]nixShell>$git_branch\[\033[00m\]"
|
||||
else
|
||||
if ! is_ssh_session; then
|
||||
PS1="\n$cur_dir\n$flake_icon$python_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"
|
||||
|
||||
function set_prompt() {
|
||||
local working_dir="\[\033[01;34m\]\w\[\033[00m\]"
|
||||
local green_arrow="\[\033[01;32m\]>> "
|
||||
local white_text="\[\033[00m\]"
|
||||
|
||||
check_ssh
|
||||
check_venv
|
||||
check_git
|
||||
|
||||
PS1="$ssh_PS1\n$working_dir\n$nix_icon$python_icon$green_arrow$git_branch_PS1$white_text"
|
||||
unset git_branch_PS1
|
||||
}
|
||||
|
||||
PROMPT_COMMAND="set_prompt"
|
||||
''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue