Guest User

Bash prompt: http://i.imgur.com/Iji6yeN.png

a guest
Feb 1st, 2015
843
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.48 KB | None | 0 0
  1. set_prompt () {
  2.     lastreturn=$?
  3.  
  4.     Reset='\[\e[0m\]'
  5.     White='\[\e[1;37m\]'
  6.     #White=$Reset #Trying stuff
  7.     Green='\[\e[1;32m\]'
  8.     Red='\[\e[1;31m\]'
  9.     Yellow='\[\e[0;33m\]'
  10.     Blue='\[\e[1;34m\]'
  11.  
  12.     # "Light" line drawing characters
  13.     Startline='\342\224\214'
  14.     Middleline='\342\224\234'
  15.     Lastline='\342\224\224'
  16.     Horizontal='\342\224\200'
  17.     Vertical='\342\224\202'
  18.  
  19.     # "Heavy" line drawing characters
  20.     #Startline='\342\224\217'
  21.     #Middleline='\342\224\243'
  22.     #Lastline='\342\224\227'
  23.     #Horizontal='\342\224\201'
  24.     #Vertical='\342\224\203'
  25.  
  26.     Leftgrouper='('
  27.     Rightgrouper=')'
  28.  
  29.     # Adjust prompt symbol according to current vi mode
  30.     Promptsymbol='>'
  31.     #[[ $(bind -v | grep "set keymap vi") = "set keymap vi-insert" ]] && Promptsymbol=i # shit's not working
  32.  
  33.  
  34.     JumpToStart='\[\e[0G\]'
  35.     SavePos='\[\e[s\]'
  36.     RestorePos='\[\e[u\]'
  37.     MoveUp='\[\e[1A\]'
  38.     MoveLeft='\[\e[1D\]'
  39.    
  40.     userhost="$Green$(whoami)@$(hostname)"
  41.     #userhost="${Green}user@hostname"
  42.  
  43.     terminal="$Yellow$(tty | sed 's!^/dev/!!')"
  44.  
  45.     if [[ $lastreturn -eq 0 ]]; then lastreturn=""; else lastreturn="$Red$lastreturn"; fi
  46.  
  47.     currentdir="$Blue$(pwd | sed "s!^$HOME!~!")"
  48.  
  49.     wrap "$userhost" "$terminal" "$currentdir" "$lastreturn"
  50.  
  51.     PS1+="\n$Lastline$Horizontal$Leftgrouper$Promptsymbol$Rightgrouper $Reset"
  52. }
  53.  
  54. # TODO Clean up the mess, first argument will never be properly linebroken at the moment
  55. wrap () {
  56.     width=$(tput cols)
  57.     firstline=true
  58.     restlength=$width
  59.     PS1="$Reset$White"
  60.     while [[ $# -ne 0 ]]; do   
  61.         colourless=$(echo -E "$1" | cut -c 13-)
  62.         length=${#colourless}
  63.         ((length += 3))
  64.         if [[ -z "$1" ]]; then shift; continue
  65.         elif [[ $restlength -eq $width ]]; then
  66.             if [[ $firstline == "true" ]]; then PS1+="$Startline"; else PS1+="$Middleline"; fi
  67.             PS1+="$Leftgrouper$1$White$Rightgrouper"
  68.             ((restlength -= length))
  69.             shift
  70.         elif [[ $restlength -ge $length ]]; then
  71.             PS1+="$Horizontal$Leftgrouper$1$White$Rightgrouper"
  72.             ((restlength -= length))
  73.             shift
  74.         elif [[ $length -gt $width ]]; then
  75.             textcolour=$(echo $1 | cut -c -12)
  76.             text=$(echo -ne "$colourless" | sed 's/.\{'$(($width - 2))'\}/&\n| /g')
  77.             linestofix=$(($(echo -n "$text" | wc -l) - 1))
  78.             PS1+="\n$Middleline$Leftgrouper$textcolour$text$White$Rightgrouper$SavePos$JumpToStart"
  79.             while [[ $linestofix -ge 0 ]]; do
  80.                 PS1+="$Vertical$MoveUp$MoveLeft"
  81.                 ((linestofix -= 1))
  82.             done
  83.             PS1+="$RestorePos"
  84.             shift
  85.         else
  86.             PS1+="\n"
  87.             restlength=$width
  88.         fi
  89.         firstline=false
  90.     done
  91. }
  92.  
  93. PROMPT_COMMAND='set_prompt'
Add Comment
Please, Sign In to add comment