diff options
Diffstat (limited to 'lib/termsupport.zsh')
-rw-r--r-- | lib/termsupport.zsh | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index babbaa957..4c5068e9b 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -33,6 +33,7 @@ fi # Runs before showing the prompt function omz_termsupport_precmd { + emulate -L zsh if [[ $DISABLE_AUTO_TITLE == true ]]; then return fi @@ -42,11 +43,11 @@ function omz_termsupport_precmd { # Runs before executing the command function omz_termsupport_preexec { + emulate -L zsh if [[ $DISABLE_AUTO_TITLE == true ]]; then return fi - emulate -L zsh setopt extended_glob # cmd name only, or if this is sudo or ssh, the next cmd @@ -60,14 +61,28 @@ precmd_functions+=(omz_termsupport_precmd) preexec_functions+=(omz_termsupport_preexec) -# Runs before showing the prompt, to update the current directory in Terminal.app -function omz_termsupport_cwd { - # Notify Terminal.app of current directory using undocumented OSC sequence - # found in OS X 10.9 and 10.10's /etc/bashrc - if [[ $TERM_PROGRAM == Apple_Terminal ]] && [[ -z $INSIDE_EMACS ]]; then - local PWD_URL="file://$HOSTNAME${PWD// /%20}" - printf '\e]7;%s\a' "$PWD_URL" - fi -} +# Keep Apple Terminal.app's current working directory updated +# Based on this answer: http://superuser.com/a/315029 +# With extra fixes to handle multibyte chars and non-UTF-8 locales -precmd_functions+=(omz_termsupport_cwd) +if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then + + # Emits the control sequence to notify Terminal.app of the cwd + function update_terminalapp_cwd() { + emulate -L zsh + # Identify the directory using a "file:" scheme URL, including + # the host name to disambiguate local vs. remote paths. + + # Percent-encode the pathname. + local URL_PATH="$(omz_urlencode -P $PWD)" + [[ $? != 0 ]] && return 1 + local PWD_URL="file://$HOST$URL_PATH" + # Undocumented Terminal.app-specific control sequence + printf '\e]7;%s\a' $PWD_URL + } + + # Use a precmd hook instead of a chpwd hook to avoid contaminating output + precmd_functions+=(update_terminalapp_cwd) + # Run once to get initial cwd set + update_terminalapp_cwd +fi |