-
Notifications
You must be signed in to change notification settings - Fork 0
/
append_me_to_bash_aliases
146 lines (121 loc) · 2.55 KB
/
append_me_to_bash_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
alias py2=python2.7
alias py3=python3
alias dk=docker
alias here="nohup nautilus -w . > /dev/null &"
alias cls=clear
alias another="gnome-terminal & disown"
alias pyenv="python3 -m venv"
alias calc="bc <<<"
alias ltr="ls -lhtr"
alias lt="ls -lht"
alias please="sudo"
# Bash only (not working with zsh)
function set-title() {
if [[ -z "$ORIG" ]]; then
ORIG=$PS1
fi
TITLE="\[\e]2;$*\a\]"
PS1=${ORIG}${TITLE}
}
function bashreload() {
source ~/.bashrc
if [ $? -eq 0 ]; then
echo "bashrc reloaded"
fi
}
function wait_msg {
seconds=$(( $1 - 1 ))
message=$2
for (( i=$seconds; i>=0; i-- ))
do
echo -en "\r\033[2K$message [$i s]"
sleep 1
done
echo ""
}
function yes_or_no() {
if [ $# -ne 1 ]; then
echo "This function requires a question as a single argument"
echo "Return: { 1 yes | 0 no | -1 not valid }"
return -1
fi
question=$1
printf "$1 [y/N] "
read res
if [ "$res" = "y" ]; then
return 1
elif [ "$res" = "n" ]; then
return 0
else
return -1
fi
}
function empty() {
if [ $# -eq 0 ]; then
echo "No filename specified"
return -1
elif [ $# -gt 1 ]; then
yes_or_no "This operation will affect more than one file. Proceed?"
elif [ $# -eq 1 ]; then
yes_or_no "Are you sure you want to clear this file contents?"
fi
if [ $? -eq 1 ]; then
for filetoremove in $@
do
if [ -e $filetoremove ]; then
echo -n "" > $filetoremove
else
echo "File '$filetoremove' does not exist"
fi
done
else
echo "Cancelled."
fi
}
function port() {
sudo lsof -i:$1
}
alias ports="netstat -tulpen"
alias curltime="curl -w \"@$HOME/.curl-format.txt\" -o /dev/null -s "
alias ncsv="nc -l -p"
function silent() { command $@ > /dev/null 2>&1 & }
function silent_debug() { command $@ 1> /dev/null & }
function swap() {
local TMPFILE=tmp.$$
mv "$1" $TMPFILE && mv "$2" "$1" && mv $TMPFILE "$2"
}
# Location
function setloc() {
export savedloc=$(pwd)
}
function goback() {
if [ -n "$savedloc" ]; then
export secondloc=$(pwd)
cd $savedloc
else
echo "No location set"
fi
}
function andforth() {
if [ -n "$secondloc" ]; then
cd $secondloc
unset secondloc
else
echo "Must first use goback"
fi
}
function clearloc() {
unset savedloc
unset secondloc
}
function showloc() {
if [ -n "$savedloc" ]; then
echo "Checkpoint location: $savedloc"
else
echo "No location set. Use setloc"
fi
echo "Current location: $(pwd)"
if [ -n "$secondloc" ]; then
echo "Coming from: $secondloc"
fi
}