dot_bash_vterm 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #
  2. # Track directory.
  3. #
  4. vterm_printf()
  5. {
  6. if [ -n "$TMUX" ]; then
  7. # Tell tmux to pass the escape sequences through
  8. # (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324)
  9. printf "\ePtmux;\e\e]%s\007\e\\" "$1"
  10. elif [ "${TERM%%-*}" = "screen" ]; then
  11. # GNU screen (screen, screen-256color, screen-256color-bce)
  12. printf "\eP\e]%s\007\e\\" "$1"
  13. else
  14. printf "\e]%s\e\\" "$1"
  15. fi
  16. }
  17. vterm_prompt_end()
  18. {
  19. vterm_printf "51;A$(whoami)@$(hostname):$(pwd)"
  20. }
  21. PS1=$PS1'\[$(vterm_prompt_end)\]'
  22. export PS1
  23. #
  24. # Evaluate Emacs commands.
  25. #
  26. vterm_cmd()
  27. {
  28. if [ -n "$TMUX" ]; then
  29. # tell tmux to pass the escape sequences through
  30. # (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324)
  31. printf "\ePtmux;\e\e]51;E"
  32. elif [ "${TERM%%-*}" = "screen" ]; then
  33. # GNU screen (screen, screen-256color, screen-256color-bce)
  34. printf "\eP\e]51;E"
  35. else
  36. printf "\e]51;E"
  37. fi
  38. printf "\e]51;E"
  39. local r
  40. while [[ $# -gt 0 ]]; do
  41. r="${1//\\/\\\\}"
  42. r="${r//\"/\\\"}"
  43. printf '"%s" ' "$r"
  44. shift
  45. done
  46. if [ -n "$TMUX" ]; then
  47. # tell tmux to pass the escape sequences through
  48. # (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324)
  49. printf "\007\e\\"
  50. elif [ "${TERM%%-*}" = "screen" ]; then
  51. # GNU screen (screen, screen-256color, screen-256color-bce)
  52. printf "\007\e\\"
  53. else
  54. printf "\e\\"
  55. fi
  56. }
  57. find-file()
  58. {
  59. vterm_cmd find-file "$(realpath "$@")"
  60. }
  61. find-file-below()
  62. {
  63. vterm_cmd find-file-below "$(realpath "$@")"
  64. }