Guest User

Untitled

a guest
Feb 1st, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. # put this in your .bash_profile
  2. if [ $ITERM_SESSION_ID ]; then
  3. export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"; ':"$PROMPT_COMMAND";
  4. fi
  5.  
  6. # Piece-by-Piece Explanation:
  7. # the if condition makes sure we only screw with $PROMPT_COMMAND if we're in an iTerm environment
  8. # iTerm happens to give each session a unique $ITERM_SESSION_ID we can use, $ITERM_PROFILE is an option too
  9. # the $PROMPT_COMMAND environment variable is executed every time a command is run
  10. # see: ss64.com/bash/syntax-prompt.html
  11. # we want to update the iTerm tab title to reflect the current directory (not full path, which is too long)
  12. # echo -ne "\033;foo\007" sets the current tab title to "foo"
  13. # see: stackoverflow.com/questions/8823103/how-does-this-script-for-naming-iterm-tabs-work
  14. # the two flags, -n = no trailing newline & -e = interpret backslashed characters, e.g. \033 is ESC, \007 is BEL
  15. # see: ss64.com/bash/echo.html for echo documentation
  16. # we set the title to ${PWD##*/} which is just the current dir, not full path
  17. # see: stackoverflow.com/questions/1371261/get-current-directory-name-without-full-path-in-bash-script
  18. # then we append the rest of $PROMPT_COMMAND so as not to remove what was already there
  19. # voilà!
Add Comment
Please, Sign In to add comment