Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (34 sloc) 1.25 KB
# function to update terminal title bar current working dir
# (borrowed from /etc/bashrc_Apple_Terminal)
update_terminal_cwd() {
# 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 LC_CTYPE=C to process text byte-by-byte. Ensure that
# LC_ALL isn't set, so it doesn't interfere.
local i ch hexch LC_CTYPE=C LC_ALL=
for (( i = 1; i <= ${#PWD}; ++i)); do
if [[ "$ch" =~ [/._~A-Za-z0-9-] ]]; then
printf -v hexch "%02X" "'$ch"
# printf treats values greater than 127 as
# negative and pads with "FF", so truncate.
url_path+="%${hexch: -2:2}"
printf '\e]7;%s\a' "file://$HOST$url_path"
# this updates just the window title
update_terminal_window_title() { printf "\e]0;$@\a" }
# add a function to update window title cwd on dir change
autoload add-zsh-hook
add-zsh-hook chpwd update_terminal_cwd
# since the function will run on _changing_ the dir
# it won't run automatically at shell start
# so, run it once now, to update:
You can’t perform that action at this time.