Bashrc.wiki: Updated notes regarding prompt, and removed code
This commit is contained in:
parent
615200446f
commit
257765cc22
34
Bashrc.wiki
34
Bashrc.wiki
|
@ -72,39 +72,9 @@ https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/12-prompt.bash
|
|||
|
||||
I originally built my prompt using http://bashrcgenerator.com and, while it's a nice tool for visually building a prompt, it has several limitations on what you're able to create with it. But more importantly to me, it generates a rediculously long string, defines and resets color for every single character, uses both a color and bold escape sequence to use light/bright colors, mixes raw escape sequences and subshells running tput, and as a result is utterly unreadable and unmaintainable.
|
||||
|
||||
So, I replaced it:
|
||||
So, I replaced it with my own setup that generates the needed color codes on the fly to improve readability. I intentionally put everything in a function and call it immediately so I may use local vars for the color definitions. I didn't really want to leave them around just in case.
|
||||
|
||||
{{{class="prettyprint"
|
||||
promptsetup() {
|
||||
# Color definitions for prompt
|
||||
local fg_brightred='\[$(tput setaf 9)\]'
|
||||
local fg_blue='\[$(tput setaf 4)\]'
|
||||
local fg_magenta='\[$(tput setaf 13)\]'
|
||||
local fg_cyan='\[$(tput setaf 6)\]'
|
||||
local fg_brightcyan='\[$(tput setaf 14)\]'
|
||||
local fg_green='\[$(tput setaf 2)\]'
|
||||
local reset='\[$(tput sgr0)\]'
|
||||
local hostname='\h'
|
||||
local mixin
|
||||
|
||||
# [hh:mm][username@hostname pwd]$
|
||||
|
||||
# Remotely, hostname is red.
|
||||
[ -n "$SSH_CLIENT" ] && hostname="${fg_brightred}\h${reset}"
|
||||
|
||||
# If in a python venv, add venv name in green.
|
||||
[ -n "$VIRTUAL_ENV" ] && mixin=" ${fg_green}$(basename "$VIRTUAL_ENV")${reset}"
|
||||
|
||||
# If in a vcsh repo env, add repo name in magenta.
|
||||
[ -n "$VCSH_REPO_NAME" ] && mixin=" ${fg_magenta}$VCSH_REPO_NAME${reset}"
|
||||
|
||||
PS1="${fg_blue}[\A]${fg_cyan}[${fg_brightcyan}\u${fg_cyan}@${hostname}${mixin} ${fg_cyan}\W]${reset}\$ "
|
||||
}
|
||||
|
||||
promptsetup
|
||||
}}}
|
||||
|
||||
I intentionally put everything in a function and call it immediately so I may use local vars for the color definitions. I didn't really want to leave them around just in case.
|
||||
I'm not completely happy with this solution because it causes each of the tput subshells to execute each time the prompt is printed. I would like to change this to quash the extra output this causes when using `bash -x`, but I would also like to find a solution that minimizes so many subshells just for a prompt, but avoid hard-coding colors so it can be general enough to support any env in which it may be used.
|
||||
|
||||
----
|
||||
|
||||
|
|
Loading…
Reference in New Issue