-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzsh-custom-functions.plugin.zsh
executable file
·138 lines (121 loc) · 4.34 KB
/
zsh-custom-functions.plugin.zsh
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
#!/bin/zsh
# Custom plugin for zsh
#
# Personal custom functions
#
# Author : Patrick Tavares <[email protected]>
#
### Commons ###
echoArg() {
echo "> $1"
}
### Command enhancement functions ###
.1() { cd ../ ; } # Go back 1 directory level
.2() { cd ../../ ; } # Go back 2 directory levels
.3() { cd ../../../ ; } # Go back 3 directory levels
.4() { cd ../../../../ ; } # Go back 4 directory levels
.5() { cd ../../../../../ ; } # Go back 5 directory levels
.6() { cd ../../../../../../ ; } # Go back 6 directory levels
root() { sudo su - ; } # root : Switch to root user using sudo
nHere() { nautilus . ; } # nHere : Opens current directory in Nautilus
n() { nautilus ; } # n : Opens a Nautilus
c() { clear ; } # c : Clear terminal display
path() { echo -e ${PATH//:/\\n} ; } # path : Echo all executable Paths
show_options() { shopt ; } # Show_options : Display bash options settings
ducks() { du -cksh * | sort -hr | head -n 15} # ducks : List by size directories
mkdirCd() { # mkdirCd : Makes new Dir and jumps inside
if (( $# != 1 ))
then
echoArg "Usage: $0 [dirName]"
else
mkdir -p "$1" && cd "$1" ;
fi
}
extract() { # extract : Extract common arch files
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 -v $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip -v $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress -v $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
### Functions (network) ###
# Public ip
myip() { curl -s ifconfig.me }
# Private ip
ipLocal() {
for i in $(hostname -I); do
name=$(ip a | grep $i | grep -oE '[^ ]+$')
mac=$(ip -o link | grep $name | awk '$2 != "lo:" {print $(NF-2)}')
echo "$name - ip : $i - mac : $mac"
done
}
httpDebug() { /usr/bin/curl $@ -o /dev/null -w "dns: %{time_namelookup} connect: %{time_connect} pretransfer: %{time_pretransfer} starttransfer: %{time_starttransfer} total: %{time_total}\n" ; }
### Functions (system) ###
my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,start,time,bsdtime,command ; }
infos() {
echo -e "Currently logged on : ${HOST}"
echo -e "Additional information: : $(uname -a)"
echo -e "Current date: : $(date)"
echo -e "Machine stats: : $(uptime)"
echo -e "Public facing IP Address : $(myip)"
echo -e "Users logged on: : \n$(w -h|sed "s/^/\t\t\t /")"
echo
}
### Functions (de/en)code ###
gpg_decode () {
echo "$1" | base64 --decode | gpg
}
### Functions (Git) ###
initialGitStoreCredentials() {
git config credential.helper store
}
initLocalGitConfig() {
if (( $# != 2 ))
then
echoArg "Usage: $0 [GitUserName] [GitUserMail]"
else
git config user.name $1 ; git config user.email $2;
fi
}
### Function to (re)install Golang ###
installGolang(){
if (( $# != 1 ))
then
echoArg "Usage: $0 GO_VERSION_TO_INSTALL"
else
wget -q -O - https://git.io/vQhTU | bash -s -- --remove && wget -q -O - https://git.io/vQhTU | bash -s -- --version $1
fi
}
### Function to run a dbus session - needed to use keyring in wsl session ##
init_dbus_session(){
if (( $# != 1 ))
then
echoArg "Usage: $0 [bash|zsh]"
else
dbus-run-session -- $1
fi
}
### Function to synctime ###
synctime(){
sudo hwclock -s
}
### Custom Alias
alias l.='/usr/bin/ls -d .*'
alias lsd='/usr/bin/ls -l | grep "^d"'
alias lr='/usr/bin/ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'''
### AWS alias
alias aws_sts_gci='aws sts get-caller-identity | jq'
alias aws_iam_laa='aws iam list-account-aliases | jq'