Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set_prompt () {
- lastreturn=$?
- Reset='\[\e[0m\]'
- White='\[\e[1;37m\]'
- #White=$Reset #Trying stuff
- Green='\[\e[1;32m\]'
- Red='\[\e[1;31m\]'
- Yellow='\[\e[0;33m\]'
- Blue='\[\e[1;34m\]'
- # "Light" line drawing characters
- Startline='\342\224\214'
- Middleline='\342\224\234'
- Lastline='\342\224\224'
- Horizontal='\342\224\200'
- Vertical='\342\224\202'
- # "Heavy" line drawing characters
- #Startline='\342\224\217'
- #Middleline='\342\224\243'
- #Lastline='\342\224\227'
- #Horizontal='\342\224\201'
- #Vertical='\342\224\203'
- Leftgrouper='('
- Rightgrouper=')'
- # Adjust prompt symbol according to current vi mode
- Promptsymbol='>'
- #[[ $(bind -v | grep "set keymap vi") = "set keymap vi-insert" ]] && Promptsymbol=i # shit's not working
- JumpToStart='\[\e[0G\]'
- SavePos='\[\e[s\]'
- RestorePos='\[\e[u\]'
- MoveUp='\[\e[1A\]'
- MoveLeft='\[\e[1D\]'
- userhost="$Green$(whoami)@$(hostname)"
- #userhost="${Green}user@hostname"
- terminal="$Yellow$(tty | sed 's!^/dev/!!')"
- if [[ $lastreturn -eq 0 ]]; then lastreturn=""; else lastreturn="$Red$lastreturn"; fi
- currentdir="$Blue$(pwd | sed "s!^$HOME!~!")"
- wrap "$userhost" "$terminal" "$currentdir" "$lastreturn"
- PS1+="\n$Lastline$Horizontal$Leftgrouper$Promptsymbol$Rightgrouper $Reset"
- }
- # TODO Clean up the mess, first argument will never be properly linebroken at the moment
- wrap () {
- width=$(tput cols)
- firstline=true
- restlength=$width
- PS1="$Reset$White"
- while [[ $# -ne 0 ]]; do
- colourless=$(echo -E "$1" | cut -c 13-)
- length=${#colourless}
- ((length += 3))
- if [[ -z "$1" ]]; then shift; continue
- elif [[ $restlength -eq $width ]]; then
- if [[ $firstline == "true" ]]; then PS1+="$Startline"; else PS1+="$Middleline"; fi
- PS1+="$Leftgrouper$1$White$Rightgrouper"
- ((restlength -= length))
- shift
- elif [[ $restlength -ge $length ]]; then
- PS1+="$Horizontal$Leftgrouper$1$White$Rightgrouper"
- ((restlength -= length))
- shift
- elif [[ $length -gt $width ]]; then
- textcolour=$(echo $1 | cut -c -12)
- text=$(echo -ne "$colourless" | sed 's/.\{'$(($width - 2))'\}/&\n| /g')
- linestofix=$(($(echo -n "$text" | wc -l) - 1))
- PS1+="\n$Middleline$Leftgrouper$textcolour$text$White$Rightgrouper$SavePos$JumpToStart"
- while [[ $linestofix -ge 0 ]]; do
- PS1+="$Vertical$MoveUp$MoveLeft"
- ((linestofix -= 1))
- done
- PS1+="$RestorePos"
- shift
- else
- PS1+="\n"
- restlength=$width
- fi
- firstline=false
- done
- }
- PROMPT_COMMAND='set_prompt'
Add Comment
Please, Sign In to add comment