my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.1 KiB

3 years ago
  1. #####################################################
  2. # iTerm2 plugin for oh-my-zsh #
  3. # Author: Aviv Rosenberg (github.com/avivrosenberg) #
  4. #####################################################
  5. ###
  6. # This plugin is only relevant if the terminal is iTerm2 on OSX.
  7. if [[ "$OSTYPE" == darwin* ]] && [[ -n "$ITERM_SESSION_ID" ]] ; then
  8. ###
  9. # Executes an arbitrary iTerm2 command via an escape code sequence.
  10. # See https://iterm2.com/documentation-escape-codes.html for all supported commands.
  11. # Example: $ _iterm2_command "1337;StealFocus"
  12. function _iterm2_command() {
  13. local cmd="$1"
  14. # Escape codes for wrapping commands for iTerm2.
  15. local iterm2_prefix="\x1B]"
  16. local iterm2_suffix="\x07"
  17. # If we're in tmux, a special escape code must be prepended/appended so that
  18. # the iTerm2 escape code is passed on into iTerm2.
  19. if [[ -n $TMUX ]]; then
  20. local tmux_prefix="\x1BPtmux;\x1B"
  21. local tmux_suffix="\x1B\\"
  22. fi
  23. echo -n "${tmux_prefix}${iterm2_prefix}${cmd}${iterm2_suffix}${tmux_suffix}"
  24. }
  25. ###
  26. # iterm2_profile(): Function for changing the current terminal window's
  27. # profile (colors, fonts, settings, etc).
  28. # To change the current iTerm2 profile, call this function and pass in a name
  29. # of another existing iTerm2 profile (name can contain spaces).
  30. function iterm2_profile() {
  31. # Desired name of profile
  32. local profile="$1"
  33. # iTerm2 command for changing profile
  34. local cmd="1337;SetProfile=$profile"
  35. # send the sequence
  36. _iterm2_command "${cmd}"
  37. # update shell variable
  38. ITERM_PROFILE="$profile"
  39. }
  40. ###
  41. # iterm2_tab_color(): Changes the color of iTerm2's currently active tab.
  42. # Usage: iterm2_tab_color <red> <green> <blue>
  43. # where red/green/blue are on the range 0-255.
  44. function iterm2_tab_color() {
  45. _iterm2_command "6;1;bg;red;brightness;$1"
  46. _iterm2_command "6;1;bg;green;brightness;$2"
  47. _iterm2_command "6;1;bg;blue;brightness;$3"
  48. }
  49. ###
  50. # iterm2_tab_color_reset(): Resets the color of iTerm2's current tab back to
  51. # default.
  52. function iterm2_tab_color_reset() {
  53. _iterm2_command "6;1;bg;*;default"
  54. }
  55. fi