-
Notifications
You must be signed in to change notification settings - Fork 16
/
install-settings.sh
executable file
·104 lines (90 loc) · 2.54 KB
/
install-settings.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
#!/usr/bin/env bash
# shellcheck disable=SC2059
main() {
set -eu
if [ -n "${DEBUG:-}" ]; then set -x; fi
need_cmd curl
need_cmd plutil
check_for_iterm
local repo="https://raw.githubusercontent.com/fnichol/macosx-iterm2-settings"
local plist="com.googlecode.iterm2.plist"
local plist_url="$repo/master/$plist"
local new_plist="/tmp/${plist}-$$"
local installed_plist="$HOME/Library/Preferences/$plist"
header "Downloading plist from $plist_url"
if curl -sSf "$plist_url" | plutil -convert binary1 -o "$new_plist" -; then
cp -f "$new_plist" "$installed_plist"
rm -f "$new_plist"
info "iTerm preferences installed or updated in $installed_plist."
else
warn "A failure occured when downloading or converting from XML."
warn "Your current preferences have not been changed."
exit_with "Installation failed" 5
fi
}
check_for_iterm() {
need_cmd pgrep
if [ "${TERM_PROGRAM:-}" = "iTerm.app" ]; then
warn "You appear to be running this script from within iTerm.app which"
warn "could overwrite your new preferences on quit."
warn "Please quit iTerm and run this from Terminal.app or an SSH session."
exit_with "Cannot run program using iTerm.app" 3
fi
if pgrep -q iTerm2; then
warn "You appear to have iTerm.app currently running. Please quit the"
warn "application so your updates won't get overridden on quit."
exit_with "iTerm.app cannot be running" 4
fi
}
exit_with() {
case "${TERM:-}" in
*term | xterm-* | rxvt | screen | screen-*)
printf -- "\n\033[1;31mERROR: \033[1;37m${1:-}\033[0m\n\n" >&2
;;
*)
printf -- "\nERROR: ${1:-}\n\n" >&2
;;
esac
exit "${2:-10}"
}
header() {
case "${TERM:-}" in
*term | xterm-* | rxvt | screen | screen-*)
printf -- "\033[1;36m-----> \033[1;37m\033[40m${*}\033[0m\n"
;;
*)
printf -- "-----> $*\n"
;;
esac
}
info() {
case "${TERM:-}" in
*term | xterm-* | rxvt | screen | screen-*)
printf -- " \033[1;37m\033[40m${*:-}\033[0m\n"
;;
*)
printf -- " ${*:-}\n"
;;
esac
}
need_cmd() {
if ! command -v "$1" > /dev/null 2>&1; then
exit_with "Required command '$1' not found on PATH" 127
fi
}
warn() {
case "${TERM:-}" in
*term | xterm-* | rxvt | screen | screen-*)
printf -- "\033[1;31m !!! \033[1;37m\033[40m${*:-}\033[0m\n" >&2
;;
*)
printf -- " !!! ${*:-}\n" >&2
;;
esac
}
# Only invoke `main()` if this file is the running program
case "$0" in
bash|sh|$BASH_SOURCE)
main "$@" || exit 99
;;
esac