-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_shell_integration_and_utilities.sh
executable file
·145 lines (133 loc) · 4.25 KB
/
install_shell_integration_and_utilities.sh
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
function die() {
echo "${1}"
exit 1
}
function join {
local IFS="$1";
shift;
echo "$*"
}
which printf > /dev/null 2>&1 || die "Shell integration requires the printf binary to be in your path."
UTILITIES=(imgcat imgls it2attention it2check it2copy it2dl it2getvar it2git it2setcolor it2setkeylabel it2ul it2universion)
SHELL=${SHELL##*/}
URL=""
HOME_PREFIX='${HOME}'
SHELL_AND='&&'
QUOTE=''
if [ "${SHELL}" = tcsh ]
then
URL="https://iterm2.com/shell_integration/tcsh"
SCRIPT="${HOME}/.login"
QUOTE='"'
ALIASES_ARRAY=()
for U in "${UTILITIES[@]}"
do
ALIASES_ARRAY+=("alias $U ~/.iterm2/$U")
done
ALIASES=$(join "; " "${ALIASES_ARRAY[@]}")
fi
if [ "${SHELL}" = zsh ]
then
URL="https://iterm2.com/shell_integration/zsh"
SCRIPT="${HOME}/.zshrc"
QUOTE='"'
ALIASES_ARRAY=()
for U in "${UTILITIES[@]}"
do
ALIASES_ARRAY+=("alias $U=~/.iterm2/$U")
done
ALIASES=$(join "; " "${ALIASES_ARRAY[@]}")
fi
if [ "${SHELL}" = bash ]
then
URL="https://iterm2.com/shell_integration/bash"
test -f "${HOME}/.bash_profile" && SCRIPT="${HOME}/.bash_profile" || SCRIPT="${HOME}/.profile"
QUOTE='"'
ALIASES_ARRAY=()
for U in "${UTILITIES[@]}"
do
ALIASES_ARRAY+=("alias $U=~/.iterm2/$U")
done
ALIASES=$(join "; " "${ALIASES_ARRAY[@]}")
fi
if [ "${SHELL}" = fish ]
then
echo "Make sure you have fish 2.3 or later. Your version is:"
fish -v
URL="https://iterm2.com/shell_integration/fish"
mkdir -p "${HOME}/.config/fish"
SCRIPT="${HOME}/.config/fish/config.fish"
HOME_PREFIX='{$HOME}'
SHELL_AND='; and'
ALIASES_ARRAY=()
for U in "${UTILITIES[@]}"
do
ALIASES_ARRAY+=("alias $U=~/.iterm2/$U")
done
ALIASES=$(join "; " "${ALIASES_ARRAY[@]}")
fi
if [ "${URL}" = "" ]
then
die "Your shell, ${SHELL}, is not supported yet. Only tcsh, zsh, bash, and fish are supported. Sorry!"
exit 1
fi
FILENAME="${HOME}/.iterm2_shell_integration.${SHELL}"
RELATIVE_FILENAME="${HOME_PREFIX}/.iterm2_shell_integration.${SHELL}"
echo "Downloading script from ${URL} and saving it to ${FILENAME}..."
curl -SsL "${URL}" > "${FILENAME}" || die "Couldn't download script from ${URL}"
chmod +x "${FILENAME}"
echo "Checking if ${SCRIPT} contains iterm2_shell_integration..."
if ! grep iterm2_shell_integration "${SCRIPT}" > /dev/null 2>&1; then
echo "Appending source command to ${SCRIPT}..."
cat <<-EOF >> "${SCRIPT}"
test -e ${QUOTE}${RELATIVE_FILENAME}${QUOTE} ${SHELL_AND} source ${QUOTE}${RELATIVE_FILENAME}${QUOTE}
EOF
fi
test -d ~/.iterm2 || mkdir ~/.iterm2
for U in "${UTILITIES[@]}"
do
echo "Downloading $U..."
curl -SsL "https://iterm2.com/utilities/$U" > ~/.iterm2/$U && chmod +x ~/.iterm2/$U
done
echo "Adding aliases..."
echo "$ALIASES" >> "${FILENAME}"
echo "Done."
echo "--------------------------------------------------------------------------------"
echo ""
echo "The next time you log in, shell integration will be enabled."
echo ""
echo "You will also have these commands:"
echo "imgcat filename"
echo " Displays the image inline."
echo "imgls"
echo " Shows a directory listing with image thumbnails"
echo "it2attention start|stop|fireworks"
echo " Gets your attention"
echo "it2check"
echo " Checks if the terminal is iTerm2"
echo "it2copy [filename]"
echo " Copies to the pasteboard"
echo "it2dl filename"
echo " Downloads the specified file, saving it in your Downloads folder."
echo "it2setcolor ..."
echo " Changes individual color settings or loads a color preset"
echo "it2setkeylabel ..."
echo " Changes Touch Bar function key labels"
echo "it2ul"
echo " Uploads a file"
echo "it2universion"
echo " Sets the current unicode version"