-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneral.sh
58 lines (55 loc) · 1.27 KB
/
general.sh
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
# Add value to PATH if it doesn't already exist
pathadd() {
DIR=$(realpath $1)
if [ ! -d "$DIR" ]; then
warning "$DIR is not a directory"
elif [[ ":$PATH:" != *":$DIR:"* ]]; then
export PATH="${PATH:+"$PATH:"}$DIR"
fi
}
# Me'aliases
alias srcme="source ~/.bashrc"
alias editme="vim ~/.bash_profile"
alias catme="cat ~/.bash_profile"
# alias expansion (allows watch to use other aliases)
alias watch='watch '
hammer() {
local TIMEOUT=1s
local COUNT=50
local DETACH
local COMMAND
while [ "$1" ]; do
case $1 in
-c | --count )
shift
COUNT=$1
;;
-t | --timeout )
shift
TIMEOUT=$1
;;
-d | --detach )
DETACH=true
;;
* )
COMMAND=$@
break
;;
esac
shift
done
if [ ! "$COMMAND" ]; then
echo "Missing command"
return 1
fi
while true; do
for i in $(seq $COUNT); do
timeout -k $TIMEOUT $TIMEOUT $COMMAND &
done
if [ ! "$DETACH" ]; then
for PID in $(jobs -p); do
wait $PID
done
fi
done
}