Guest User

Untitled

a guest
Aug 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. How to show git status info on the right side of the terminal?
  2. PS1='$(printf "%*sr%s" $(( COLUMNS-1 )) "[$(git branch 2>/dev/null | grep '^*' | sed s/..//)] $(date +%H:%M:%S)" "heipei@wavefront:$PWD$ ")'
  3.  
  4. left="[${status}]u@h:w$ "
  5. right="$(git symbolic-ref HEAD) $(date +%T)"
  6. spaces="$(( $(tput cols) - ${#left} - ${#right} ))"
  7. export PS1="$(printf "%s%${spaces}sn" "$left" "$right")"
  8.  
  9. preprompt() {
  10. rc=$?
  11. c=31
  12. [ $rc -eq 0 ] && c=32
  13.  
  14. PS1="[$(color $c)]$rc[$(color 0)] t w $ "
  15. # right "prompt"
  16. # We cannot use $COLUMNS here, since in new shells the first prompt
  17. # will get garbled then. Seems like the correct value of COLUMNS is
  18. # in the shell init.
  19. printf "%`tput cols`s`tput cr`" "${USER}@${HOST}"
  20. }
  21.  
  22. PROMPT_COMMAND=preprompt
Add Comment
Please, Sign In to add comment