]> git.rmz.io Git - dotfiles.git/blob - zsh/plugins/terminalapp/terminalapp.plugin.zsh
add xbindkeysrc
[dotfiles.git] / zsh / plugins / terminalapp / terminalapp.plugin.zsh
1 # Set Apple Terminal.app resume directory
2 # based on this answer: http://superuser.com/a/315029
3 # 2012-10-26: (javageek) Changed code using the updated answer
4
5 # Tell the terminal about the working directory whenever it changes.
6 if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then
7 update_terminal_cwd() {
8 # Identify the directory using a "file:" scheme URL, including
9 # the host name to disambiguate local vs. remote paths.
10
11 # Percent-encode the pathname.
12 local URL_PATH=''
13 {
14 # Use LANG=C to process text byte-by-byte.
15 local i ch hexch LANG=C
16 for ((i = 1; i <= ${#PWD}; ++i)); do
17 ch="$PWD[i]"
18 if [[ "$ch" =~ [/._~A-Za-z0-9-] ]]; then
19 URL_PATH+="$ch"
20 else
21 hexch=$(printf "%02X" "'$ch")
22 URL_PATH+="%$hexch"
23 fi
24 done
25 }
26
27 local PWD_URL="file://$HOST$URL_PATH"
28 #echo "$PWD_URL" # testing
29 printf '\e]7;%s\a' "$PWD_URL"
30 }
31
32 # Register the function so it is called whenever the working
33 # directory changes.
34 autoload add-zsh-hook
35 add-zsh-hook chpwd update_terminal_cwd
36
37 # Tell the terminal about the initial directory.
38 update_terminal_cwd
39 fi