-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathiterm.zsh
More file actions
98 lines (60 loc) · 2.87 KB
/
iterm.zsh
File metadata and controls
98 lines (60 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
###########################################
# iTerm Tab and Title Customization #
###########################################
function set_title_tab {
function settab {
# file settab -- invoked only if iTerm or Konsole is running
# Set iterm window tab to current directory and penultimate directory if the
# shell process is running. Truncate to leave the rightmost $rlength characters.
#
# Use with functions settitle (to set iterm title bar to current directory)
# and chpwd
if [[ $TERM_PROGRAM == iTerm.app && -z "$KONSOLE_DCOP_SESSION" ]];then
# The $rlength variable prints only the 20 rightmost characters. Otherwise iTerm truncates
# what appears in the tab from the left.
# Chage the following to change the string that actually appears in the tab:
tab_label="$PWD:h:t/$PWD:t"
rlength="20" # number of characters to appear before truncation from the left
echo -ne "\e]1;${(l:rlength:)tab_label}\a"
else
# For KDE konsole tabs
# Chage the following to change the string that actually appears in the tab:
tab_label="$PWD:h:t/$PWD:t"
rlength="20" # number of characters to appear before truncation from the left
# If we have a functioning KDE console, set the tab in the same way
if [[ -n "$KONSOLE_DCOP_SESSION" && ( -x $(which dcop) ) ]];then
dcop "$KONSOLE_DCOP_SESSION" renameSession "${(l:rlength:)tab_label}"
else
: # do nothing if tabs don't exist
fi
fi
}
function settitle {
# Function "settitle" -- set the title of the iterm title bar. use with chpwd and settab
# Change the following string to change what appears in the Title Bar label:
title_lab=$HOST:r:r::$PWD
# Prints the host name, two colons, absolute path for current directory
# Change the title bar label dynamically:
echo -ne "\e]2;[zsh] $title_lab\a"
}
# Set tab and title bar dynamically using above-defined functions
function title_tab_chpwd { settab ; settitle }
# Now we need to run it:
title_tab_chpwd
# Set tab or title bar label transiently to the currently running command
if [[ "$TERM_PROGRAM" == "iTerm.app" ]];then
function title_tab_preexec { echo -ne "\e]1; $(history $HISTCMD | cut -b7- ) \a" }
function title_tab_precmd { settab }
else
function title_tab_preexec { echo -ne "\e]2; $(history $HISTCMD | cut -b7- ) \a" }
function title_tab_precmd { settitle }
fi
typeset -ga preexec_functions
preexec_functions+=title_tab_preexec
typeset -ga precmd_functions
precmd_functions+=title_tab_precmd
typeset -ga chpwd_functions
chpwd_functions+=title_tab_chpwd
}
####################
# set_title_tab