Bash PS1 Generator
51–60 of 146 posts
Re: Bash PS1 Generator
#52current git branch is missing (helps me to avoid working on the wrong branch). (tried to do it with colors, but things got too messy). I never managed to work with colors in bash propmts; they look different on each environment. parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' } PS1="[\u@\h \W\$(parse_git_branch)]\$ "
Re: Bash PS1 Generator
#53On the site all prompt variables end in "tput sgr0". I haven't seen that before. What does that do and why is it needed?
tput is a neat command that I wish got used more! I also use `tput cnorm` to ensure the cursor is visible.
Re: Bash PS1 Generator
#54On the site all prompt variables end in "tput sgr0". I haven't seen that before. What does that do and why is it needed?
You can see what each tput commands are doing by running infocmp. Most TERM implement ANSI-compatible escape codes, but may prefer other escape codes for the same effect (e.g. try comparing `infocmp -1 ansi` and `infocmp -1 xterm` and `infocmp -1 screen`). You can see the entire list of these commands in terminfo(5) (`man 5 terminfo`) in Predefined Capabilities section.
Re: Bash PS1 Generator
#55current git branch is missing (helps me to avoid working on the wrong branch). (tried to do it with colors, but things got too messy). I never managed to work with colors in bash propmts; they look different on each environment. parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' } PS1="[\u@\h \W\$(parse_git_branch)]\$ "
You might want to use `git rev-parse --abbrev-ref HEAD` or `git name-rev --name-only HEAD` instead of `git branch`. Plumbing commands (such as rev-parse or name-ref) are generally more interface-stable to use in a script than porcelain commands (such as git branch) which are designed for interactive use where output may change depending on user environment and configuration.
Re: Bash PS1 Generator
#56current git branch is missing (helps me to avoid working on the wrong branch). (tried to do it with colors, but things got too messy). I never managed to work with colors in bash propmts; they look different on each environment. parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' } PS1="[\u@\h \W\$(parse_git_branch)]\$ "
if [ "$color_prompt" = yes ]; then
PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\
[\033[0;36m\] @ \[\033[0;36m\]\h \w\
[\033[0;32m\]$(__git_ps1)\n\[\033[0;32m\]└─\
[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]
AWS:${AWS_PROFILE} ▶\[\033[0m\] '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fiRe: Bash PS1 Generator
#57Re: Bash PS1 Generator
#58 [\e[1;33m\u\e[1;32m@\e[1;31m\H \e[1;36m\t\e[0m]
[\e[1;35m\w\e[0m](\e[1;32m\#\e[0m
)\n$
which presents as: [User@HOST 10:21:07][~](2)
$
(Username, hostname, 24 hour local time, CWD, history count, newline, prompt)More detail from my .bashrc:
# Define some colors first:
red='\e[0;31m'
RED='\e[1;31m'
blue='\e[0;34m'
BLUE='\e[1;34m'
cyan='\e[0;36m'
CYAN='\e[1;36m'
green='\e[0;32m'
GREEN='\e[1;32m'
NC='\e[0m' # No Color
yellow='\e[0;33m'
magenta='\e[0;35m'
YELLOW='\e[1;33m'
MAGENTA='\e[1;35m'
export PS1="[${YELLOW}\u${GREEN}@${RED}\H ${CYAN}
\t$NC][${MAGENTA}\w$NC](${GREEN}\#$NC)\n\$ "
I define the colors as it makes it easier to modify PS1 when the spirit moves me.I guess using a generator or toolkit could be useful, but I tweaked mine over the years and prefer it just this way.
Edit: I forgot to mention that I use different colors for user vs. root prompts, as that gives immediate visual confirmation of privilege level.
Re: Bash PS1 Generator
#59I love the irony of using a GUI tool to create a prompt for a shell.
Re: Bash PS1 Generator
#60I think the drag-n-drop UI is less intuitive. Wasted a few minutes trying to click these items as "buttons" and wondering if there's something wrong because of the http-onlyness of the site (console gives a lot of warning).
Yea, why not just have "double-click" as "add this element to the end of input".