1
1
Fork 0
nixos-configs/modules/bashrc

38 lines
996 B
Bash
Raw Normal View History

2024-01-27 19:10:46 +00:00
# Set the title bar to user@host: pwd
_TITLE_BAR="\u@\h: \w"
_SET_TITLE_BAR="\[\e]0;$_TITLE_BAR\a\]"
2024-04-16 15:39:26 +00:00
# Shorten $HOME to ~ in PWD and shorten other path dir names to one letter
_pwd() {
if [[ "$PWD" =~ ^"$HOME"($) ]]; then
printf "~"
elif [[ "$PWD" = "/" ]]; then
printf "/"
2024-01-27 19:10:46 +00:00
else
2024-04-16 15:39:26 +00:00
if [[ "$PWD" =~ ^"$HOME"/ ]]; then
printf "~"
DIR="${PWD#$HOME}"
else
DIR="$PWD"
fi
for path_elem in $(dirname "$DIR" | tr / '\n' | grep . | cut -c-1); do
printf '/%s' $path_elem
done
printf "/$(basename "$DIR")"
2024-01-27 19:10:46 +00:00
fi
}
_DIR='$(_pwd)'
# Color codes
_GREEN="\[\033[32;1m\]"
_DIM="\[\e[32;2m\]"
_OLIVE="\[\e[33;2m\]"
2024-01-27 19:10:46 +00:00
_RESET="\[\e[0m\]"
_HOST=$(if [ -z "$SSH_CLIENT" ]; then echo $_DIM; else echo $_OLIVE; fi)
2024-01-27 19:10:46 +00:00
# Nested shell level
_SHLVL=$(printf '\$%.0s' $(seq 1 $SHLVL))
# SSH detection
_SSH='$([ ! -z "$SSH_CLIENT" ] && echo "=>")'
2024-01-27 19:10:46 +00:00
# Build prompt
export PS1="$_SET_TITLE_BAR$_DIM[\A \u@$_RESET$_HOST\h$_DIM:$_RESET$_GREEN$_DIR$_RESET$_DIM]$_SHLVL$_RESET "
2024-02-01 01:37:25 +00:00
export HISTCONTROL=ignoreboth