Skip to content

Instantly share code, notes, and snippets.

@apjanke
Created December 21, 2014 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apjanke/5e0269b6bd286c698f4b to your computer and use it in GitHub Desktop.
Save apjanke/5e0269b6bd286c698f4b to your computer and use it in GitHub Desktop.
OS X Terminal.app escape sequence demo code
# osx_term_controls.zsh
#
# A collection of functions to demonstrate OS X Terminal control behaviors
function term_tell_n () {
n=$1
string=$2
printf '\e]%s;%s\a' $n "$string"
}
function term_window_title () {
term_tell_n 2 $1
}
function term_icon_title () {
term_tell_n 1 $1
}
function term_both_title () {
term_tell_n 0 $1
}
# Set the terminal current directory, converting path to a file URL
function term_pwd () {
local SEARCH=' '
local REPLACE='%20'
local PWD_URL="file://$HOSTNAME${1//$SEARCH/$REPLACE}"
term_tell_n 7 $PWD_URL
}
# Set the terminal current directory, without URL conversion
function term_pwd_raw () {
term_tell_n 7 $1
}
# Set current directory to the actual current directory
function term_current_pwd () {
term_pwd $PWD
}
function term_add_chpwd_hook () {
chpwd_functions+=(term_current_pwd)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment