Use a function to get the colour for the username part of prompt.
This commit is contained in:
parent
538425eeae
commit
b0af5d148b
1 changed files with 18 additions and 12 deletions
30
.bashrc
30
.bashrc
|
|
@ -28,6 +28,7 @@ __prompt_git_status() {
|
||||||
# Do nothing if there's an error.
|
# Do nothing if there's an error.
|
||||||
(( ERR >= 1 )) || { (( ERR == 128 )) && (( ${#GIT_REPO_INFO[@]} != 3 )); } && return "$RET"
|
(( ERR >= 1 )) || { (( ERR == 128 )) && (( ${#GIT_REPO_INFO[@]} != 3 )); } && return "$RET"
|
||||||
|
|
||||||
|
# FIXME: Move the git dir to status below.
|
||||||
# Generate the prompt.
|
# Generate the prompt.
|
||||||
if [[ "${GIT_REPO_INFO[2]}" == "true" ]]; then
|
if [[ "${GIT_REPO_INFO[2]}" == "true" ]]; then
|
||||||
# If in the git directory, use a special branch marker.
|
# If in the git directory, use a special branch marker.
|
||||||
|
|
@ -105,6 +106,21 @@ __prompt_git_status() {
|
||||||
return "$RET"
|
return "$RET"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__prompt_user_colour() {
|
||||||
|
# Determine the colour of the username in the prompt.
|
||||||
|
local RET="$?"
|
||||||
|
|
||||||
|
if [[ "$LOGNAME" == "root" ]]; then
|
||||||
|
printf "%s" "1" # Red
|
||||||
|
elif [[ "$LOGNAME" == "tadgy" ]]; then
|
||||||
|
printf "%s" "2" # Green
|
||||||
|
else
|
||||||
|
printf "%s" "6" # Cyan
|
||||||
|
fi
|
||||||
|
|
||||||
|
return "$RET"
|
||||||
|
}
|
||||||
|
|
||||||
__find_ssh_agent_sock() {
|
__find_ssh_agent_sock() {
|
||||||
# Find an *active* ssh agent socket.
|
# Find an *active* ssh agent socket.
|
||||||
# Returns: 0 = Found an active socket.
|
# Returns: 0 = Found an active socket.
|
||||||
|
|
@ -344,15 +360,6 @@ HISTSIZE=-1
|
||||||
HISTTIMEFORMAT="%d/%m/%y %H:%M:%S "
|
HISTTIMEFORMAT="%d/%m/%y %H:%M:%S "
|
||||||
history -r
|
history -r
|
||||||
|
|
||||||
# Determine the colour of the username in the prompt.
|
|
||||||
if [[ "$LOGNAME" == "root" ]]; then
|
|
||||||
COLOUR=1 # Red
|
|
||||||
elif [[ "$LOGNAME" == "tadgy" ]]; then
|
|
||||||
COLOUR=2 # Green
|
|
||||||
else
|
|
||||||
COLOUR=5 # Purple
|
|
||||||
fi
|
|
||||||
|
|
||||||
# The commands to execute before the prompt is displayed.
|
# The commands to execute before the prompt is displayed.
|
||||||
PROMPT_COMMAND="__ssh_agent_prompt_command"
|
PROMPT_COMMAND="__ssh_agent_prompt_command"
|
||||||
|
|
||||||
|
|
@ -373,14 +380,13 @@ if (( BASH_VERSINFO[0] >= 4 )); then
|
||||||
# Trim the path in the prompt.
|
# Trim the path in the prompt.
|
||||||
PROMPT_DIRTRIM=2
|
PROMPT_DIRTRIM=2
|
||||||
# Coloured username + host + directory:
|
# Coloured username + host + directory:
|
||||||
PS1='[\[$(tput bold)$(tput setaf "$COLOUR")\]\u\[$(tput sgr0)\]@\[$(tput bold)$(tput setaf 3)\]\h\[$(tput sgr0)\]] \[$(tput bold)$(tput setaf 4)\]\w\[$(tput sgr0)\]$(__prompt_git_status "\[\033[0;35;40m\] (%s)\[\033[0;37;40m\]") ->'
|
PS1='[\[$(tput bold)$(tput setaf "$(__prompt_user_colour)")\]\u\[$(tput sgr0)\]@\[$(tput bold)$(tput setaf 3)\]\h\[$(tput sgr0)\]] \[$(tput bold)$(tput setaf 4)\]\w\[$(tput sgr0)\]$(__prompt_git_status "\[\033[0;35;40m\] (%s)\[\033[0;37;40m\]") ->'
|
||||||
else
|
else
|
||||||
# Set the prompts.
|
# Set the prompts.
|
||||||
# Coloured username + host + directory:
|
# Coloured username + host + directory:
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
PS1="[\[$(tput bold)$(tput setaf "$COLOUR")\]\u\[$(tput sgr0)\]@\[$(tput bold)$(tput setaf 3)\]\h\[$(tput sgr0)\]] \[$(tput bold)$(tput setaf 4)\]\$(echo \"\${PWD/#\$HOME/~}\" | awk -F/ '{if (NF>3) {printf \".../\" \$(NF-1) \"/\" \$NF} else {printf \$0}}')\[$(tput sgr0)\]$(__prompt_git_status "\[\033[0;35;40m\] (%s)\[\033[0;37;40m\]") ->"
|
PS1='[\[$(tput bold)$(tput setaf "$(__prompt_user_colour)")\]\u\[$(tput sgr0)\]@\[$(tput bold)$(tput setaf 3)\]\h\[$(tput sgr0)\]] \[$(tput bold)$(tput setaf 4)\]\$(echo \"\${PWD/#\$HOME/~}\" | awk -F/ '\''{if (NF>3) {printf \".../\" \$(NF-1) \"/\" \$NF} else {printf \$0}}'\'')\[$(tput sgr0)\]$(__prompt_git_status "\[\033[0;35;40m\] (%s)\[\033[0;37;40m\]") ->'
|
||||||
fi
|
fi
|
||||||
unset COLOUR
|
|
||||||
|
|
||||||
# Set the debugger prompt.
|
# Set the debugger prompt.
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue