diff options
author | Stephen Zhuang <stephen.zhuang@gmail.com> | 2013-01-06 14:10:42 +0800 |
---|---|---|
committer | Stephen Zhuang <stephen.zhuang@gmail.com> | 2013-01-06 14:10:42 +0800 |
commit | 914c47b3473b000288c693523f83fde998282a81 (patch) | |
tree | a29cf3d796544a3b2807e26812011cda51f644a9 /plugins/terminalapp | |
parent | 692dca07158413ae27b2064c303240f5b9621cff (diff) | |
parent | 80a603259657acab97badbae20003b5a34c901f9 (diff) | |
download | zsh-914c47b3473b000288c693523f83fde998282a81.tar.gz zsh-914c47b3473b000288c693523f83fde998282a81.tar.bz2 zsh-914c47b3473b000288c693523f83fde998282a81.zip |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'plugins/terminalapp')
-rw-r--r-- | plugins/terminalapp/terminalapp.plugin.zsh | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/plugins/terminalapp/terminalapp.plugin.zsh b/plugins/terminalapp/terminalapp.plugin.zsh index 4695ad055..2249b1e2f 100644 --- a/plugins/terminalapp/terminalapp.plugin.zsh +++ b/plugins/terminalapp/terminalapp.plugin.zsh @@ -1,11 +1,39 @@ # Set Apple Terminal.app resume directory # based on this answer: http://superuser.com/a/315029 +# 2012-10-26: (javageek) Changed code using the updated answer -function chpwd { - local SEARCH=' ' - local REPLACE='%20' - local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}" - printf '\e]7;%s\a' "$PWD_URL" -} +# Tell the terminal about the working directory whenever it changes. +if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then + update_terminal_cwd() { + # Identify the directory using a "file:" scheme URL, including + # the host name to disambiguate local vs. remote paths. -chpwd
\ No newline at end of file + # Percent-encode the pathname. + local URL_PATH='' + { + # Use LANG=C to process text byte-by-byte. + local i ch hexch LANG=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 + } + + local PWD_URL="file://$HOST$URL_PATH" + #echo "$PWD_URL" # testing + printf '\e]7;%s\a' "$PWD_URL" + } + + # Register the function so it is called whenever the working + # directory changes. + autoload add-zsh-hook + add-zsh-hook chpwd update_terminal_cwd + + # Tell the terminal about the initial directory. + update_terminal_cwd +fi |