mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-19 21:41:07 +01:00
Updated code from answer URL
This commit is contained in:
parent
c2ae9e09ca
commit
4d8fe543ff
1 changed files with 35 additions and 7 deletions
|
@ -1,11 +1,39 @@
|
||||||
# Set Apple Terminal.app resume directory
|
# Set Apple Terminal.app resume directory
|
||||||
# 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
|
||||||
|
|
||||||
function chpwd {
|
# Tell the terminal about the working directory whenever it changes.
|
||||||
local SEARCH=' '
|
if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then
|
||||||
local REPLACE='%20'
|
update_terminal_cwd() {
|
||||||
local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
|
# 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=''
|
||||||
|
{
|
||||||
|
# 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"
|
printf '\e]7;%s\a' "$PWD_URL"
|
||||||
}
|
}
|
||||||
|
|
||||||
chpwd
|
# 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
|
||||||
|
|
Loading…
Reference in a new issue