From 10c8548d14e2349ff9bdcf0aa2f26b2e8eadd012 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Thu, 15 Dec 2016 16:45:01 +0100 Subject: zsh: Update macOS Terminal icon with cwd --- tag-zsh/config/zsh/zshrc | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tag-zsh/config/zsh/zshrc b/tag-zsh/config/zsh/zshrc index d66b5914..7b3d332f 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 -- cgit 1.4.1