-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions
128 lines (111 loc) · 3.35 KB
/
functions
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
function precmd() {
if [ "$(id -u)" -ne 0 ]; then
FULL_CMD_LOG="$HOME/.logs/zsh-history-$(date -u "+%Y-%m-%d").log"
echo "$USER@`hostname`:`pwd` [$(date -u)] `\history -1`" >> ${FULL_CMD_LOG}
fi
}
brew-cask-upgrade() {
if [ "$1" != '--continue' ]; then
echo "Removing brew cache"
rm -rf "$(brew --cache)"
echo "Running brew update"
brew update
fi
for c in $(brew list --cask); do
echo -e "\n\nInstalled versions of $c: "
ls $(brew --prefix)/Caskroom/$c
echo "Cask info for $c"
brew info --cask $c
select ynx in "Yes" "No" "Exit"; do
case $ynx in
"Yes") echo "Upgrading $c"; brew upgrade --cask "$c"; break;;
"No") echo "Skipping $c"; break;;
"Exit") echo "Exiting brew-cask-upgrade"; return;;
esac
done
done
}
brew-upgrade() {
if [ "$1" != '--continue' ]; then
echo "Removing brew cache"
rm -rf "$(brew --cache)"
echo "Running brew update"
brew update
brew upgrade
fi
for c in $(brew list --cask); do
read INSTALLED UPGRADE < <(brew info --cask --json=v2 $c | jq -r '.casks[] | "\(.installed) \(.version)"')
if [ $INSTALLED = $UPGRADE ]; then
continue
fi
echo "\n\nVersions of $c: "
echo "Installed : $INSTALLED"
echo "Upgrade to: $UPGRADE"
select ynx in "Yes" "No" "Exit"; do
case $ynx in
"Yes") echo "Upgrading $c"; brew upgrade --cask "$c"; break;;
"No") echo "Skipping $c"; break;;
"Exit") echo "Exiting brew-upgrade"; return;;
esac
done
done
}
function f() {
find . -name "$1" 2>&1 | grep -v 'Permission denied'
}
# Copy with progress
cp_p() {
rsync -WavP --human-readable --progress $1 $2
}
# direct it all to /dev/null
function nullify() {
"$@" > /dev/null 2>&1
}
# remove all comments and blank lines
function nocomments() {
grep -v ^# "$@" | grep -v ^$
}
# `shellswitch [bash|zsh]`
# Must be in /etc/shells
shellswitch() {
chsh -s $(brew --prefix)/bin/$1
}
# Start an HTTP server from a directory, optionally specifying the port
function server() {
local port="${1:-8000}";
sleep 1 && open "http://localhost:${port}/" &
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
# And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files)
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port";
}
# Run `dig` and display the most useful info
function digga() {
dig +nocmd "$1" any +multiline +noall +answer;
}
# Update mac-cli
function mac-cli() {
[ "$1" != "install" -a "$1" != "uninstall" -a "$1" != "update" ] || \
sh -c "$(curl -fsSL https://raw.githubusercontent.com/guarinogabriel/mac-cli/master/mac-cli/tools/$1)"
}
# Note taking hacks
n() {
$EDITOR ~/notes/"$*".txt
}
nls() {
ls -c ~/notes/ | grep -i "$*"
}
## INFO: FFMPEG WEBP CONVERTER
convert_webp() {
for i in *
do
if [[ "${i##*.}" == "webp" ]]; then
echo "WEBP FILE => $i"
# show filename
filename="${i%.*}"
# show Extension
extension="${i##*.}"
## webp converter
ffmpeg -i "$filename" "$filename.png"
fi
done
}