Fix #2416 in terminalapp plugin

This commit is contained in:
Alexander Madyankin 2014-07-05 20:28:45 +06:00
commit c34221e821

View file

@ -2,38 +2,45 @@
# based on this answer: http://superuser.com/a/315029 # based on this answer: http://superuser.com/a/315029
# 2012-10-26: (javageek) Changed code using the updated answer # 2012-10-26: (javageek) Changed code using the updated answer
# Tell the terminal about the working directory whenever it changes. # Run only on OS X < 10.9 because the whole functionality has been replaced by Mavericks natively.
if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then # https://github.com/robbyrussell/oh-my-zsh/issues/2416
update_terminal_cwd() { if [[ "$(uname)" == "Darwin" ]] && [[ "$(uname -r | cut -d . -f 1)" -lt 13 ]]; then
# Identify the directory using a "file:" scheme URL, including
# the host name to disambiguate local vs. remote paths.
# Percent-encode the pathname. # Tell the terminal about the working directory whenever it changes.
local URL_PATH='' if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then
{ update_terminal_cwd() {
# Use LANG=C to process text byte-by-byte. # Identify the directory using a "file:" scheme URL, including
local i ch hexch LANG=C # the host name to disambiguate local vs. remote paths.
for ((i = 1; i <= ${#PWD}; ++i)); do
ch="$PWD[i]" # Percent-encode the pathname.
if [[ "$ch" =~ [/._~A-Za-z0-9-] ]]; then local URL_PATH=''
URL_PATH+="$ch" {
else # Use LANG=C to process text byte-by-byte.
hexch=$(printf "%02X" "'$ch") local i ch hexch LANG=C
URL_PATH+="%$hexch" for ((i = 1; i <= ${#PWD}; ++i)); do
fi ch="$PWD[i]"
done 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"
} }
local PWD_URL="file://$HOST$URL_PATH" # Register the function so it is called whenever the working
#echo "$PWD_URL" # testing # directory changes.
printf '\e]7;%s\a' "$PWD_URL" autoload add-zsh-hook
} add-zsh-hook precmd update_terminal_cwd
# Register the function so it is called whenever the working # Tell the terminal about the initial directory.
# directory changes. update_terminal_cwd
autoload add-zsh-hook fi
add-zsh-hook precmd update_terminal_cwd
# Tell the terminal about the initial directory.
update_terminal_cwd
fi fi