diff options
-rw-r--r-- | tag-zsh/config/zsh/zshrc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tag-zsh/config/zsh/zshrc b/tag-zsh/config/zsh/zshrc index d66b591..7b3d332 100644 --- a/tag-zsh/config/zsh/zshrc +++ b/tag-zsh/config/zsh/zshrc @@ -177,6 +177,46 @@ else setopt prompt_cr PROMPT='%F{blue}%~%f${prompt_pure_username} %(?.%F{magenta}.%F{red})>%f ' + + ## From https://github.com/robbyrussell/oh-my-zsh/blob/71deb74552d54630d99ae1db3647ebed7b3bc735/lib/termsupport.zsh + + # 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 + + if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then + # Emits the control sequence to notify Terminal.app of the cwd + # Identifies the directory using a file: URI scheme, including + # the host name to disambiguate local vs. remote paths. + function update_terminalapp_cwd() { + emulate -L zsh + + # Percent-encode the pathname. + # Percent-encode the pathname. + local URL_PATH='' + { + # Use LC_CTYPE=C to process text byte-by-byte. + local i ch hexch LC_CTYPE=C + for ((i = 1; i <= ${#PWD}; ++i)); do + ch="$PWD[i]" + if [[ "$ch" =~ [/._~A-Za-z0-9-] ]]; then + URL_PATH+="$ch" + else + hexch=$(printf "%02X" "'$ch") + URL_PATH+="%$hexch" + fi + done + } + [[ $? != 0 ]] && return 1 + + printf '\e]7;%s\a' "file://$HOST$URL_PATH" + } + + # 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 fi if zplug check clvv/fasd |