mirror of
https://github.com/itme-brain/nixos.git
synced 2026-03-24 08:39:42 -04:00
Update promptooor
This commit is contained in:
parent
2a67b95d79
commit
1cf1cdf1cd
2 changed files with 48 additions and 47 deletions
|
|
@ -2,6 +2,8 @@
|
||||||
export EDITOR=nvim
|
export EDITOR=nvim
|
||||||
export DIRENV_LOG_FORMAT=
|
export DIRENV_LOG_FORMAT=
|
||||||
|
|
||||||
|
eval "$(direnv hook bash)"
|
||||||
|
|
||||||
function cdg() {
|
function cdg() {
|
||||||
if [[ $1 == "--help" ]]; then
|
if [[ $1 == "--help" ]]; then
|
||||||
echo "A simple utility for navigating to the root of a git repo"
|
echo "A simple utility for navigating to the root of a git repo"
|
||||||
|
|
|
||||||
|
|
@ -1,60 +1,59 @@
|
||||||
''
|
''
|
||||||
eval "$(direnv hook bash)"
|
check_ssh() {
|
||||||
|
|
||||||
is_ssh_session() {
|
|
||||||
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
||||||
return 0
|
ssh_PS1="\n\[\033[01;37m\]\u@\h:\[\033[00m\]"
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_ps1_prompt() {
|
function check_venv() {
|
||||||
local git_branch=""
|
if [ -n "''${IN_NIX_SHELL}" ]; then
|
||||||
local flake_icon=""
|
if [ -n "$VIRTUAL_ENV" ]; then
|
||||||
local python_icon=""
|
python_icon="\[\033[01;33m\] \[\033[00m\]"
|
||||||
local cur_dir=""
|
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
|
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||||
git_branch="$(git symbolic-ref --short HEAD 2>/dev/null)"
|
local git_branch=$(git branch --show-current)
|
||||||
|
if [ -z "$git_branch" ]; then
|
||||||
if [ $? -ne 0 ]; then
|
git_branch=$(git rev-parse --short HEAD)
|
||||||
git_branch="$(git rev-parse --short HEAD 2>/dev/null)"
|
|
||||||
fi
|
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
|
set_git_dir
|
||||||
# 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
|
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