-
Notifications
You must be signed in to change notification settings - Fork 2
/
.functs
163 lines (140 loc) · 5.04 KB
/
.functs
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
#!/bin/zsh
mymem() {
ps axu | awk '$11!~/\[*\]/ {print $6/1024" Mb\t>\t"$2"\t"$11,$12,$13,$14}'|sort -g
}
cpssh() {
[[ -z $@ ]] && echo -e "copy file to rhost over ssh tunnel\nusage: cpssh <rhost> <lfile> [rfile]" && return 1
_s="ssh -e none"
rh=$1
lf=$2
rf=${3:-$2}
cat $lf | eval $_s $rh cat > $rf
}
sshtun() {
[[ -z $@ ]] && echo -e "create an local ssh tunnel from your machine to another one\nusage: sshtun <rhost> <rport> [locport]" && return 1
rh=$1
rp=$2
lp=${3:-28112}
lh="localhost"
_cmd="ssh -f -g -N -L"
eval $_cmd $lp:$lh:$rp $rh
}
pstop(){
[[ -n $@ ]] && echo -e "find out the most ressources eating processes" && return 1
echo -ne "CpuTop:\t"
ps axu|awk '{print $3,$11}'|sort -n|tail -1
echo -ne "MemTop:\t"
ps axu|awk '{print $4,$11}'|sort -n|tail -1
}
psg(){
[[ -z $@ ]] && echo -e "ultimate pgrep function\nusage: psg <processname>" && return 1
pid=`pgrep -f $1`
ps up $(echo $pid) 2>/dev/null
}
chkhp() {
[[ -z $@ ]] && echo -e "check if homepage is up or down with downforeveryoneorjustme.com\nusage: chkhp <url>" && return 1
url=$1
wget -qO - "http://downforeveryoneorjustme.com/$url" | sed '/just you/!d;s/.*<a href[^>]*>//g;s/<[^>]*>//g'
}
dwnlft() {
[[ -z $@ ]] && echo -e "download a specific filetype from the whole homepage\nusage: dwnlft <filetype> <url>" && return 1
flt=$1
url=$2
wget -erobots=off -U "Mozilla/5.0" -H -r -l1 -w5 -t1 -N --random-wait -P/tmp/hpdwn -nd -np -A.$1 $url
}
expurl() {
[[ -z $@ ]] && echo -e "expand a url like is.gd or goo.gl\nusage: expurl <url>" && return 1
url=$1
curl -sIL $url &>/dev/null|egrep "^Location"
}
bak() {
[[ -z $@ ]] && echo -e "backup file with date\nusage: bak <filename>" && return 1
fl=$1
date=$(date +%Y%m%d)
cp $1{,.$date.bak}
}
tyurl() {
[[ -z $@ ]] && echo -e "tinyurl a url\nusage: tyurl <url>" && return 1
longurl=$1
shrturl=$(curl -s "http://tinyurl.com/create.php?url=$longurl" | sed -n 's/^copy.*\(http\:\/\/tinyurl\.com\/[a-z0-9]*\).*/\1/p')
echo -e "here you go, it was xclipped...\n\n---------------------------\n$shrturl\n---------------------------"
echo "$shrturl" | xclip -i -se c
}
secpwd(){
[[ -z $@ ]] && echo -e "get a secpwd from /dev/urandom\nusage: secpwd <number of characters>" && return 1
cat /dev/urandom | tr -dc "[A-Za-z0-9]^*#_+-=:.;,^!?$£€@"|fold -w $1|head -5
}
## good gotbletu rtmp functions
rtmp_sniff(){
[[ -n $@ ]] && echo -e "rtmp sniff w/ iptables rules to get rtmp url\nusage: rtmp_sniff" && return 1;
sudo iptables -t nat -A OUTPUT -p tcp --dport 1935 -m owner \! --uid-owner root -j REDIRECT
rtmpsrv
sudo iptables -t nat -D OUTPUT -p tcp --dport 1935 -m owner \! --uid-owner root -j REDIRECT
}
# transfer
transfer() {
if [ $# -eq 0 ]; then
echo "No arguments specified. Usage:"
echo "$ transfer /tmp/test.md"
echo "$ cat /tmp/test.md | transfer test.md"
return 1
fi
# write to output to tmpfile because of progress bar
tmpfile=$( mktemp -t transferXXX );
if tty -s; then
basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g');
curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile;
else
curl --progress-bar --upload-file "-" "https://transfer.sh/$1"
fi
cat $tmpfile; rm -f $tmpfile;
}
cmdfm(){
# taken from https://github.com/llaine/cmdfm
CLIENTID=2cd0c4a7a6e5992167a4b09460d85ece
# cmdfm api
APIURL="https://cmd.fm/api/tracks/search/"
# test chosen genre
test -z $1 && echo -e "Please select a genre\nexample: cmdfm minimal" && return 1
GENRE=$1
# play
while :
do STREAMURL=`curl -sk ${APIURL}\?genre=${GENRE}\&limit=1 | sed 's/.*stream_url\":\"\(http.*stream\)\",.*/\1/g'`
mplayer -quiet -nocache "${STREAMURL}?client_id=${CLIENTID}" &>/dev/null
done
}
0x0(){
if [[ $1 == "rmt" ]]
then
curl -F "url=$2" https://0x0.st
elif [[ $1 == "up" ]]
then
curl -F "file=@$2" https://0x0.st
else
curl -F "file=@$1" https://0x0.st
fi
}
# some fzf functions
# https://github.com/junegunn/fzf/wiki/examples
# v [FUZZY PATTERN] - Open the selected file with the default editor
# - Bypass fuzzy finder if there's only one match (--select-1)
# - Exit if there's no match (--exit-0)
v() {
IFS=$'\n' files=($(fzf --query="$1" +m --select-1 --exit-0))
[[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}"
}
# fcd - fuzzy search for all dirs and cd into them
fcd() {
IFS=$'\n' files=($(fd --type directory --follow --hidden --exclude .git | fzf --query="$1" -m --select-1 --exit-0))
[[ -n "$files" ]] && cd "${files[@]}"
}
# using ripgrep combined with preview
# find-in-file - usage: fif <searchTerm>
fif() {
if [ ! "$#" -gt 0 ]; then echo "Need a string to search for!"; return 1; fi
rg --files-with-matches --no-messages "$1" | fzf --preview "highlight -O ansi -l {} 2> /dev/null | rg --colors 'match:bg:yellow' --ignore-case --pretty --context 10 '$1' || rg --ignore-case --pretty --context 10 '$1' {}"
}
alias vfif="vi $(fif $1)"
fman() {
man -k . | fzf --prompt='Man> ' | awk '{print $1}' | xargs -r man
}