-
Notifications
You must be signed in to change notification settings - Fork 17
/
utils.fish
77 lines (65 loc) · 2.3 KB
/
utils.fish
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
#################################
### Network Related
#################################
alias localip "ipconfig getifaddr en1"
alias ips "ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ and print $1'"
alias whois "whois -h whois-servers.net"
# View HTTP traffic
alias sniff "sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'"
alias httpdump "sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""
function server --description "Start an HTTP server from a directory"
open http://localhost:8080/
and python2 -m SimpleHTTPServer 8080
end
function digga --description "All the dig info"
dig +nocmd $argv[1] any +multiline +noall +answer
end
alias myip="curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'"
################################
### Unix Related
################################
# Trim new lines and copy to clipboard
alias c="tr -d '\n' | pbcopy"
# File size
alias fs="stat -f \"%z bytes\""
# ROT13-encode text. Works for decoding, too! ;)
alias rot13='tr a-zA-Z n-za-mN-ZA-M'
function randpw --description "generate a random password"
dd if=/dev/urandom bs=1 count=16 2>/dev/null | base64 | rev | cut -b 2- | rev
end
function cd --description "auto ls for each cd"
if [ -n $argv[1] ]
builtin cd $argv[1]
and ls -AF
else
builtin cd ~
and ls -AF
end
end
function rename --description "Rename a symbol recursively in a folder"
rg -l "$argv[1]" | xargs -I\{\} perl -i -pe "s/$argv[1]/$argv[2]/g" \{\}
end
# Taken from: https://github.com/dideler/dotfiles/blob/master/functions/extract.fish
function extract --description "Expand or extract bundled & compressed files"
set --local ext (echo $argv[1] | awk -F. '{print $NF}')
switch $ext
case tar # non-compressed, just bundled
tar -xvf $argv[1]
case gz
if test (echo $argv[1] | awk -F. '{print $(NF-1)}') = tar # tar bundle compressed with gzip
tar -zxvf $argv[1]
else # single gzip
gunzip $argv[1]
end
case tgz # same as tar.gz
tar -zxvf $argv[1]
case bz2 # tar compressed with bzip2
tar -jxvf $argv[1]
case rar
unrar x $argv[1]
case zip
unzip $argv[1]
case '*'
echo "unknown extension"
end
end