mirror of
https://github.com/itme-brain/nixos.git
synced 2026-03-24 00:29:43 -04:00
Improved logic for prompt
This commit is contained in:
parent
303c22aca6
commit
7b63b3b04f
1 changed files with 34 additions and 16 deletions
|
|
@ -6,23 +6,38 @@ check_ssh() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_venv() {
|
add_icon() {
|
||||||
if [ -n "$VIRTUAL_ENV" ]; then
|
local icon=$1
|
||||||
local python_icon="\[\033[01;33m\] \[\033[00m\]"
|
if [[ ! $venv_icons =~ $icon ]]; then
|
||||||
venv_icons+="$python_icon"
|
venv_icons+="$icon"
|
||||||
elif [ -d "''${git_root}/node_modules" ]; then
|
|
||||||
local node_icon="\[\033[01;93m\] \[\033[00m\]"
|
|
||||||
venv_icons+="$node_icon"
|
|
||||||
fi
|
fi
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_nix() {
|
remove_icon() {
|
||||||
|
local icon=$1
|
||||||
|
venv_icons=''${venv_icons//$icon/}
|
||||||
|
}
|
||||||
|
|
||||||
|
python_icon="\[\033[01;33m\]\[\033[00m\]"
|
||||||
|
node_icon="\[\033[01;93m\]\[\033[00m\]"
|
||||||
|
nix_icon="\[\033[01;34m\]\[\033[00m\]"
|
||||||
|
|
||||||
|
check_venv() {
|
||||||
if [ -n "$IN_NIX_SHELL" ]; then
|
if [ -n "$IN_NIX_SHELL" ]; then
|
||||||
local nix_icon="\[\033[01;34m\] \[\033[00m\]"
|
add_icon "$nix_icon"
|
||||||
venv_icons+="$nix_icon"
|
if [ -n "$VIRTUAL_ENV" ]; then
|
||||||
|
add_icon "$python_icon"
|
||||||
else
|
else
|
||||||
unset venv_icons
|
remove_icon "$python_icon"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d "''${git_root}/node_modules" ]; then
|
||||||
|
add_icon "$node_icon"
|
||||||
|
else
|
||||||
|
remove_icon "$node_icon"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
remove_icon "$nix_icon"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
@ -37,8 +52,9 @@ set_git_dir() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_in_project() {
|
check_project() {
|
||||||
if git rev-parse --git-dir >/dev/null 2>&1; then
|
local git_dir=$(git rev-parse --git-dir 2>/dev/null)
|
||||||
|
if [ -n "$git_dir" ]; 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)}
|
git_branch=''${git_branch:-$(git rev-parse --short HEAD)}
|
||||||
|
|
||||||
|
|
@ -52,6 +68,9 @@ check_in_project() {
|
||||||
|
|
||||||
set_git_dir
|
set_git_dir
|
||||||
check_venv
|
check_venv
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_prompt() {
|
function set_prompt() {
|
||||||
|
|
@ -64,8 +83,7 @@ function set_prompt() {
|
||||||
local git_branch_PS1
|
local git_branch_PS1
|
||||||
|
|
||||||
check_ssh
|
check_ssh
|
||||||
check_nix
|
check_project
|
||||||
check_in_project
|
|
||||||
|
|
||||||
PS1="$ssh_PS1\n$working_dir\n$venv_icons$green_arrow$git_branch_PS1$white_text"
|
PS1="$ssh_PS1\n$working_dir\n$venv_icons$green_arrow$git_branch_PS1$white_text"
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue