I am trying to find the documentation on what, exactly, the printf
command is doing in update_terminal_cwd
.
If you didn't know already, the update_terminal_cwd
function is defined (at least on Mac OS X 10.7.4) in /etc/bashrc
and in that same file the function is added to the $PROMPT_COMMAND
so that it runs every time you hit enter in the Terminal.
The text of the update_terminal_cwd
function itself is as follows:
update_terminal_cwd() {
# Identify the directory using a "file:" scheme URL,
# including the host name to disambiguate local vs.
# remote connections. Percent-escape spaces.
local SEARCH=' '
local REPLACE='%20'
local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
printf '\e]7;%s\a' "$PWD_URL"
}
This is a few steps down the rabbit hole from trying to set my Terminal tab names from the command line, which can be done rather easily, but the tab name gets reset when ssh
ing into a box.
This led me to How to stop automatic changing of iTerm titles? and the rather obscure list of control sequences on the Mac.
If you go to that last link and search for the string osc ps ; pt bel
, you will find the section which defines the escape character that makes tab renaming work. However, while that explains printf '\e]1;%s\a'
(note the "1"), it doesn't explain what the "7" does in the update_terminal_cwd
function I quoted above.
Where is this documented?? (And why does PWD_URL
include the prefix file://
?)
sleep 5
updates part of the tab and window title to besleep
, but I'm not sure how it is triggered.