From 76e437cb4e48972d861575b8e7bcc754e89775e2 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Fri, 21 Oct 2022 16:33:53 -0500 Subject: [PATCH] Add basic iTerm2 integration --- dotlib/iterm2.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 dotlib/iterm2.sh diff --git a/dotlib/iterm2.sh b/dotlib/iterm2.sh new file mode 100644 index 0000000..2f6de0b --- /dev/null +++ b/dotlib/iterm2.sh @@ -0,0 +1,25 @@ +# Based on the iTerm2 Bash integration script + +if [[ $OSTYPE != darwin* ]]; then + return 0 +fi + +iterm2_write() { + local cmd=$1 fmt=$2 + shift 2 + printf "\033]1337;%s=$fmt\007" "$cmd" "$@" +} + +iterm2_write_state() { + iterm2_write RemoteHost %s@%s "$USER" "$iterm2_hostname" + iterm2_write CurrentDir %s "$PWD" +} + +iterm2_prompt_command() { + iterm2_write_state +} + +ITERM_SHELL_INTEGRATION_INSTALLED=Yes +ITERM_PREV_PS1=$PS1 +iterm2_hostname=${HOSTNAME-"$(hostname -f 2>/dev/null)"} +PROMPT_COMMAND+=(iterm2_prompt_command)