Info

  • PROMPT_COMMAND and is execed right in front of the PS1
  • PS1 specifies the format of your regular prompt that appears to the left of every new command you type    
  • PS2 defines the continuation prompt: It appears when you enter a line ending with a backslash to continue input on the next line.

A real good page about all kinds of options

THE Prompt

export PS1='\[\e[1;33m\]\u@\h\[\e[0m\]:\[\e[1;34m\]\W\[\e[0m\] \e]2;\u@\H:\w - susp:\j\a$( RET=$?; if [ $RET != 0 ] ; then echo "\[\e[1;31m\]rc:$RET\[\e[00m\] "; fi )\$ '

for synology without the \[ and \]

export PS1='\e[1;33m\u@\h\e[0m:\e[1;34m\W\e[0m \e]2;\u@\H:\w - susp:\j\a$( RET=$?; if [ $RET != 0 ] ; then echo "\e[1;31mrc:$RET\e[00m "; fi )\$ '

(to make it permanent put this in ~/.bash_profile or ~/.bashrc)

CodeExplained
'\[\e[1;33m\]'Bold Yellow text (0;33 would be dark yellow)
'\u@\h'\u for username, fixed '@', \h for first part of hostname
'\[\e[0m\]'reset foreground, background, and boldness settings to their default values
':'fixed ':'
'\[\e[01;34m\]'Bold Blue text
\WThe "basename of the current netowkr directory (drobbins from /home/frobbins)

 

 
'\[\e[0m\]' 
' \$ 'If you are not root, inserts a "$"; if you are root, you get a "#"
'\e]2;\u@\H:$( pwd )- susp: \j\a'

text within \e2; and \a will be put into the titlebar of the X terminal:
\u for username, fixed '@', \H for full hostname, fixed':',

Would like to use $( pwd ) for current working dir since \w shows ~, but then RET doesn't work on syno

fixed '- susp: ', \j for number of suspended processes

  
'$( RET=$?; if [ $RET != 0 ] ; then echo "\[\e[1;31m\]rc:$RET\[\e[00m\] "; fi )\$ '
show (red) return code if not 0
$( pwd )
execute bash command (like pwd)

The location

devicelocation
Synology/etc/profile
CentOS/etc/profile.d/localbashrc.sh

Collored command input

 

Just end with the color you want to give your command and add: 

~/.bashrc
 trap 'echo -ne "\e[0m"' DEBUG

 

Extra info 

 Color chart

 

ANSI Escape sequences

See: Good complete link

 

SequenceDescription
\aThe ASCII bell character (you can also type \007)
\dDate in "Wed Sep 06" format
\eASCII escape character (you can also type \033)
\hFirst part of hostname (such as "mybox")
\HFull hostname (such as "mybox.mydomain.com")
\jThe number of processes you've suspended in this shell by hitting ^Z
\lThe name of the shell's terminal device (such as "ttyp4")
\nNewline
\rCarriage return
\sThe name of the shell executable (such as "bash")
\tTime in 24-hour format (such as "23:01:01")
\TTime in 12-hour format (such as "11:01:01")
\@Time in 12-hour format with am/pm
\uYour username
\vVersion of bash (such as 2.04)
\VBash version, including patchlevel
\wCurrent working directory (such as "/home/drobbins")
\WThe "basename" of the current working directory (such as "drobbins")
\!Current command's position in the history buffer
\#Command number (this will count up at each prompt, as long as you type something)
\$If you are not root, inserts a "$"; if you are root, you get a "#"
\xxxInserts an ASCII character based on three-digit number xxx (replace unused digits with zeros, such as "\007")
\\A backslash
\[This sequence should appear before a sequence of characters that don't move the cursor (like color escape sequences). This allows bash to calculate word wrapping correctly.
\]This sequence should appear after a sequence of non-printing characters.

 

to my prompt that would be red and bold if its greater than zero and regular and white if it was zero. If this "if"  behavior is not possible, then I could just have it always white and regular text. Could anyone help me out with this? Below is the output of my PS1 variable.

PS1='...:\[$(((\j > 0))&&{ tput setaf 1;tput bold;})\]\j\[$(tput sgr0)\]...'

 

 the unicode symbol for a zero status and the unicode symbol for a nonzero status:
    FancyX='\342\234\227'
    Checkmark='\342\234\223'
but then you need to use unicode

 

 

 

On Synology probably from version 5 the \[ and \] should not be used, is't automatically subtracted from the visible character counter.

 

 

  • No labels