-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.zsh_aliases
executable file
·229 lines (205 loc) · 6.28 KB
/
.zsh_aliases
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
218
219
220
221
222
223
224
225
226
227
228
229
#######################################
#### Frequently used aliases ####
#######################################
alias clean='sed "s,\x1B\[[0-9;]*[a-zA-Z],,g"'
alias clr='clear'
alias cursor-hide="printf '\e[?25l'"
alias cursor-show="printf '\e[?25h'"
alias drive-speed='hdparam -Tt'
alias sudo='sudo '
alias termbin='nc termbin.com 9999'
alias xclip-i='xclip -i -selection clipboard'
alias xclip-o='xclip -o -selection clipboard'
#-- Global --#
alias -g L="| less"
alias -g H="| head"
alias -g T="| tail"
alias -g G="| grep --color=auto"
alias -g N=">/dev/null"
#-- Suffix --#
alias -s html='$BROWSER'
alias -s com='$BROWSER'
alias -s org='$BROWSER'
alias -s .git='git clone'
################################
#### Simple functions ####
################################
# Use curl and jq to search for packages in the Arch Linux AUR
aursearch () {
curl -sSL "https://aur.archlinux.org/rpc/?v=5&type=search&arg=$@" | jq -r '.results[]'
}
# Convert to and from binary
binary-convert () {
case $1 in
-b|b)
echo "$2" | perl -lpe '$_=join " ", unpack"(B8)*"'
;;
-a|a)
echo "$2" | perl -lape '$_=pack"(B8)*",@F'
;;
0*|1*)
echo "$@" | perl -lape '$_=pack"(B8)*",@F'
;;
*)
echo "$@" | perl -lpe '$_=join " ", unpack"(B8)*"'
;;
esac
}
# Use awk as a calculator
calc () {
awk "BEGIN {print $@}"
}
# Use owlbot.info to get definitions; requires jq
define () {
query="$(echo "$@" | jq -Rr '@uri')"
curl -sSL "https://api.datamuse.com/words?sp=$query&max=1&md=d" | jq '.'
}
# check Discord client versions
discord-versions () {
echo "Canary: $(curl -sSL -I -X GET "https://discord.com/api/download/canary?platform=linux&format=tar.gz" | grep -im1 '^location:' | rev | cut -f1 -d'/' | rev)"
echo "PTB: $(curl -sSL -I -X GET "https://discord.com/api/download/ptb?platform=linux&format=tar.gz" | grep -im1 '^location:' | rev | cut -f1 -d'/' | rev)"
echo "Stable: $(curl -sSL -I -X GET "https://discord.com/api/download?platform=linux&format=tar.gz" | grep -im1 '^location:' | rev | cut -f1 -d'/' | rev)"
}
# List size of directories
dirsize () { du -h --max-depth=0 "$@" | sort -h -r }
dirsize-a () { du -h "$@" | sort -h -r }
#Check to see if site is down for you or everyone
downforme () {
curl -sSLA "$RANDOM$RANDOM" "https://api-prod.downfor.cloud/httpcheck/$@" | jq '.'
}
# List size of file
filesize () { du -h -a --max-depth=1 "$@" | sort -h -r }
filesize-a () { du -h -a "$@" | sort -h -r }
# Output Github commits and messages for chosen repo; requires jq
gitcommits () {
curl -sSL "https://api.github.com/repos/$1/$2/commits" | jq -r '.[] | .sha, .commit.message' | paste -sd ' \n' | tail -n +2
}
# View info about a github repo; requires jq
gitinfo () {
curl -sSL "https://api.github.com/repos/$1" | jq -r ".$2"
}
# View latest github release; requires jq
gitrelease () {
curl -sSL "https://api.github.com/repos/$1/$2/releases" | jq -r ".[$3].assets[]"
}
# get google results
google () {
query="$(echo "$@" | jq -Rr '@uri')"
curl -sLA "$RANDOM" "https://www.w3.org/services/html2txt?url=https%3A%2F%2Fgoogle.com%2Fsearch%3Fq%3D$query&noinlinerefs=on&nonums=on&endrefs=on" | \
grep -Po 'https:\/\/www\.google\.com\/url\?q=\K.*' | \
perl -pe 's%&sa=.&ved=.*%%g' | \
head -n -2
}
# Use cht.sh to get simple help outputs for all sorts of Linux things
help () {
curl -sSL "https://cht.sh/$@"
}
# Output currently playing mpc song
mpc-current () {
printf '\e[?25l'
while true; do
echo
echo
echo "$(tput setaf 4)$(mpc current --wait -f "\n\nArtist: %artist%\nSong: %title%")"
done
}
# Show resource use for specific process
sps () {
ps -eLo pid,rss,%cpu,comm --sort -rss | grep -i "%CPU\|$@" | grep -v 'grep'
}
# Search for and play a youtube video
mpvyt () { mpv ytdl://ytsearch10:"$*" }
# decode url encoded strings using perl
urldecode () {
echo "$@" | perl -pe 's/\%([[:xdigit:]]{2})/chr hex $1/ge'
}
# url encode strings using jq
urlencode () {
echo "$@" | jq -Rr '@uri'
}
# get weather using openweathermap
weather () {
ipinfo="$(curl -sL "http://ipinfo.io/json" | jq -r '.loc | split(",")')"
lat="$(echo "$ipinfo" | jq -r '.[0]')"
lon="$(echo "$ipinfo" | jq -r '.[1]')"
units="${1:-imperial}"
curl -sSL "http://api.openweathermap.org/data/2.5/weather?lat=$lat&lon=$lon&APPID=0b86d85ffa87580e45aeded67fc9cc4b&units=$units" | jq '.'
}
# Use wttr.in to output weather
wttr (){
LOCATION="$1"
FLOCATION="$2"
case "$1" in
0*)
if [ -z "$FLOCATION" ]; then
FLOCATION="$location"
fi
tput reset
curl -sSL "wttr.in/$FLOCATION?0"
LOCATION=""
FLOCATION=""
;;
1*)
if [ -z "$FLOCATION" ]; then
FLOCATION="$location"
fi
tput reset
curl -sSL "wttr.in/$FLOCATION?1"
LOCATION=""
FLOCATION=""
;;
2*)
if [ -z "$FLOCATION" ]; then
FLOCATION="$location"
fi
tput reset
curl -sSL "wttr.in/$FLOCATION?2"
LOCATION=""
FLOCATION=""
;;
*)
if [ -z "$LOCATION" ]; then
LOCATION="$location"
fi
tput reset
curl -sSL "wttr.in/$LOCATION"
LOCATION=""
esac
}
# Decompress any archive type
x () {
if [ -f "$1" ] ; then
case "$1" in
*.tar.*|*.tar)
tar -xf "$1"
;;
*.bz2)
bunzip2 "$1"
;;
*.rar)
unrar x "$1"
;;
*.gz)
gunzip "$1"
;;
*.jar|*.zip)
unzip "$1"
;;
*.Z)
uncompress "$1"
;;
*.deb)
ar x "$1"
;;
*)
echo "'$1' cannot be extracted"
;;
esac
else
echo "'$1' is not a file"
fi
}
# Search for youtube videos
yt () {
curl -sL "https://vid.puffyan.us/api/v1/search?q=$(echo "$@" | jq -Rr '@uri')" | jq -r '"https://youtu.be/" + .[].videoId?'
}