Skip to content

Instantly share code, notes, and snippets.

@Asenar
Last active October 11, 2015 16:07
Show Gist options
  • Save Asenar/3884602 to your computer and use it in GitHub Desktop.
Save Asenar/3884602 to your computer and use it in GitHub Desktop.
script for testing fancy prompt with 2 colors
#!/bin/bash
# list of colors, just what I use for test
txtrst=\[\033[00m\] # no color
txtred=\[\033[31m\] # Red
txtred=\[\033[32m\] # Green
txtblu=\[\033[34m\] # Blue
RANDOM_PROMPT()
{
# __git_ps1
bluepart=$RANDOM
redpart=$RANDOM
# 1st solution:
# the following will display extra brackets (and same bug as 2nd solution)
#printf '\[\033[34m\]%s\[\033[31m\]%s\[\033[00m\]' $bluepart $redpart
# 2nd solution : with the following, if I type a long command, the CRLF is replaced by a simple CR
# (that means the previous line is replaced, char by char)
printf " (\033[34m%s \033[31m%s\033[0m)" "$bluepart" "$redpart"
# 3rd solution : color handled elsewhere... but how ?
#printf "%s %s" "$bluepart" "$redpart"
}
PS1_base='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]'
# 1st and 2nd solution
PS1_custom_end='$(RANDOM_PROMPT "(%s)") \$ '
# 3rd solution : The following works, but there is only one color
#PS1_custom_end='\[\033[01;34m\] $(RANDOM_PROMPT "(%i)")\[\033[00m\] \$ '
PS1=$PS1_base$PS1_custom_end
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$txtblu$(RANDOM_PROMPT " (%s%s%s)")$txtrst\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment