-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.functions
More file actions
217 lines (199 loc) · 6.68 KB
/
.functions
File metadata and controls
217 lines (199 loc) · 6.68 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/env zsh
# handle command not found by displaying packages that contain the command
function command_not_found_handler() {
# lazy load the proper handler on the first run
if has brew && brew command command-not-found-init >/dev/null; then
eval "$(brew command-not-found-init)"
command_not_found_handler "$@"
elif [[ -x /etc/zsh_command_not_found ]]; then
source /etc/zsh_command_not_found
command_not_found_handler "$@"
else
return 127
fi
}
# convenience to switch xcode versions
function xcswitch() {
sudo xcode-select -switch "/Applications/Xcode$1.app/Contents/Developer" && \
echo "Switched to $(xcode-select -print-path)"
}
# highlighted man pages!!
# http://boredzo.org/blog/archives/2016-08-15/colorized-man-pages-understood-and-customized
function man() {
env \
LESS_TERMCAP_mb=$'\e[1;31m' LESS_TERMCAP_md=$'\e[1;31m' \
LESS_TERMCAP_me=$'\e[0m' LESS_TERMCAP_se=$'\e[0m' \
LESS_TERMCAP_so=$'\e[1;44;33m' LESS_TERMCAP_ue=$'\e[0m' \
LESS_TERMCAP_us=$'\e[1;32m' \
man "$@"
}
function extract () {
if [ -f "$1" ] ; then
case $1 in
*.tar.bz2) tar xvjf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xvjf "$1" ;;
*.tgz) tar xvzf "$1" ;;
*.xip) xip -x "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
# function gem {
# if [[ $1 == "install" ]]; then
# gemargs="$@"
# command gem install --user-install ${gemargs:8}
# else
# command gem "$@"
# fi
# }
# Get software updates, and update installed Ruby gems, Homebrew, npm, and their installed packages.
function update {
case $(uname) in
Darwin)
echo "\n===[ Apple Software Update ]===============================" && \
sudo softwareupdate -i -a
echo "\n===[ App Store ]===========================================" && \
mas upgrade
echo "\n===[ Homebrew ]============================================" && \
brew update && \
brew upgrade && \
brew cleanup -s && \
if has port; then
echo "\n==[ MacPorts ]==========================================================" && \
sudo port selfupdate && \
sudo port outdated
sudo port upgrade outdated
echo "Cleaning up ..."
sudo port uninstall inactive
sudo port uninstall leaves
fi
echo "\n===[ npm ]=================================================" && \
npm update -g
echo "\n===[ Gems ]================================================" && \
gem update && \
gem cleanup
# echo "\n===[ pip ]=================================================" && \
# Disabled on macOS [TODO: Determine if brew install] (PEP 668)
# pip2 install --upgrade $(pip2 list --outdated | awk '/.*/ {print $1}') && \
# pip3 install -U $(pip3 list --outdated --format json | jq -r 'map(.name) | join(" ")')
echo "\n===[ Rust ] ===============================================" && \
rustup update
echo "\n===[ Swift ] ===============================================" && \
swiftly self-update
swiftly update
;;
Linux)
echo "===[ apt-get ]=============================================" && \
sudo apt-get update && \
sudo apt-get -y upgrade && \
sudo apt-get -y dist-upgrade && \
sudo apt-get -y autoremove && \
sudo apt-get -y remove (deborphan)
# echo "==[ npm ]==========================================================" && \
# sudo npm install npm -g && \
# sudo npm update -g
echo "===[ Gems ]================================================" && \
sudo gem update
echo "===[ pip ]================================================="
if [ $(cat /etc/issue) -eq "Ubuntu" ]
then
echo "pip updates not supported on Ubuntu as some packages are owned by the system."
else
sudo python -m pip install --upgrade (python -m pip list --outdated | awk '/.*/ {print $1}') && \
sudo python3 -m pip install --upgrade (python3 -m pip list --outdated | awk '/.*/ {print $1}')
fi
;;
FreeBSD)
echo "===[ System Software Update ]==============================" && \
freebsd-update fetch upgrade
echo "\n===[ Update Ports ]========================================" && \
portmaster -av
;;
*)
echo "Not supported on (uname)."
esac
}
#
# Opens man pages in Preview.app.
#
function manp {
local page
if (( $# > 0 )); then
for page in "$@"; do
man -t "$page" | open -f -a Preview
done
else
print 'What manual page do you want?' >&2
fi
}
# Run `dig` and display the most useful info
function digga() {
dig +nocmd "$1" any +multiline +noall +answer;
}
# Create a data URL from a file
function dataurl() {
local mimeType=$(file -b --mime-type "$1");
if [[ $mimeType == text/* ]]; then
mimeType="${mimeType};charset=utf-8";
fi
echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')";
}
function hextorgb() {
printf "%d %d %d\n" \
"0x${1:0:2}" \
"0x${1:2:2}" \
"0x${1:4:2}"
}
function rgbtohex() {
printf "%02X%02X%02X\n" "$@"
}
# display term colours
function c07() {
for i in 0 1 2 3 4 5 6 7; do
printf '\033[%sm \033[0m' "$1$i"
done; echo
}
function blocks() {
echo
c07 4
c07 10
echo
}
# preview hex colour
function prev() {
[ "$@" ] || { set -- "$(cat /dev/stdin)"; }
[ "$n" ] && [ "$n" -le 220 ] || n=30
for i; do
printf "\033]4;%s;#%s\007" "$n" "$i"
printf "\033[38;05;%sm%s\033[0m \033[48;05;%sm \033[0m\n" \
"$n" "$i" "$n"
n=$((n+1))
done
}
function flac2alac() {
if [ $# -ne 1 ]; then
print "input pls?" >&2
else
ffmpeg -i $1 -c:v copy -c:a alac $1:t:r.m4a
fi
}
function mp42gif() {
if [ $# -ne 1 ] && ![ -f "$1" ]; then
print "input?" >&2
else
ffmpeg -i $1 -y -vf 'fps=10,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse' -loop 0 $1:t:r:.gif
fi
}
function mktouch() {
mkdir -p "$(dirname "$1")" && touch "$1"
}