Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #------------------------------------------------------------
- #------------------------------------------------------------
- #--------------------Custom bash prompt----------------------
- #------------------------------------------------------------
- #------------------------------------------------------------
- # you can copy all these lines directly to .bashrc but I recommend to
- # make a script file and call it from .bashrc like the below line
- # source ~/.my-scripts/bash-prompt.sh
- #colors
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # foreground background color
- # 30 - - - - - 40 - - - - - # black
- # 31 - - - - - 41 - - - - - # red
- # 32 - - - - - 42 - - - - - # green
- # 33 - - - - - 43 - - - - - # yellow
- # 34 - - - - - 44 - - - - - # blue
- # 35 - - - - - 45 - - - - - # magenta
- # 36 - - - - - 46 - - - - - # cyan
- # 37 - - - - - 47 - - - - - # white
- # 00 - - - - - # dark
- # 01 - - - - - # light
- # special characters
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # \a : an ASCII bell character (07)
- # \d : the date in "Weekday Month Date" format (e.g., "Tue May 26")
- # \D : \D{format} the format is passed to strftime(3) and the result is
- # inserted into the prompt string; an empty format results in a
- # locale-specific time representation. The braces are required
- # \e : an ASCII escape character (033)
- # \h : the host name up to the first '.'
- # \H : the host name
- # \j : the number of jobs currently managed by the shell
- # \l : the base name of the shell’s terminal device name
- # \n : newline
- # \r : carriage return
- # \s : the name of the shell, the base name of $0 (the portion following the final slash)
- # \t : the current time in 24-hour HH:MM:SS format
- # \T : the current time in 12-hour HH:MM:SS format
- # \@ : the current time in 12-hour am/pm format
- # \A : the current time in 24-hour HH:MM format
- # \u : the username of the current user
- # \v : the version of bash (e.g., 2.00)
- # \V : the release of bash, version + patch level (e.g., 2.00.0)
- # \w : the current working directory, with $HOME abbreviated with a tilde
- # \W : the base name of the current working directory, with $HOME abbreviated with a tilde
- # \! : the history number of this command
- # \# : the command number of this command
- # \$ : if the effective UID is 0, a #, otherwise a $
- # \\ : a backslash
- # \[ : begin a sequence of non-printing characters, which could be used to
- # embed a terminal control sequence into the prompt
- # \] : end a sequence of non-printing characters
- # \nnn : the character corresponding to the octal number nnn
- # Making a line of '-' character for separating prompts
- # "tput cols" returns width of command line window.
- _ps1_line() {
- echo -n $(
- for(( i=1; i<=$( tput cols ); i++))
- do
- echo -n "-"
- done
- )
- }
- # Colorizing Prompt
- # $1 for background, $3 for foreground and $2 for making colour light or dark
- _ps1_colour() {
- echo -n "\[\033[$1;$2;$3m\]"
- }
- # Clearing color to default
- _ps1_colour_clear() {
- echo -n "\[\033[00m\]"
- }
- # Making text bold
- _ps1_bold() {
- echo -n "\[$(tput bold)\]"
- }
- # Clearing tput format. here we use it for clearing bold.
- _ps1_bold_clear() {
- echo -n "\[$(tput sgr0)\]"
- }
- # Making an array of what will be printed in each line. (each element of array for 1 line)
- _update_ps1() {
- local parts=(
- "$(_ps1_colour 00 01 36)$(_ps1_line)"
- "$(_ps1_colour 00 01 34)USER$(_ps1_colour 00 01 33) ›››› $(_ps1_colour 00 01 34)\u"
- "$(_ps1_colour 00 01 34)HOST$(_ps1_colour 00 01 33) ›››› $(_ps1_colour 00 01 34)\h : $(_ps1_colour 00 01 33)\w"
- "$(_ps1_colour 00 01 36)››››$(_ps1_colour_clear)"
- )
- # After of generating array, it should be returned. it could be like this "echo -n "${parts[@]}"".
- # The problem is that it returns an space character between each element.
- # '\r' would be useful but it have side effect to prompt. it makes frozen characters.
- local length=${#parts[@]}
- length=$length-1
- echo -n $(
- for(( i=0; i<=$length; i++))
- do
- echo -n ${parts[$i]}
- # here we need to go to next line. but not for the last line.
- if (( $i < $length ))
- then
- echo -n "\n"
- fi
- done
- )
- }
- # initializing bash prompt variable
- export PS1="${debian_chroot:+($debian_chroot)}$(_update_ps1) "
- #------------------------------------------------------------
- #------------------------------------------------------------
- #-----------------End of Custom bash prompt------------------
- #------------------------------------------------------------
- #------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement