blob: 06a36fde889925ecd5015fbbc483ee6123e47565 (
plain)
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
|
# vim: ft=sh:
# Run process in background
tbg() {
mkdir -p /tmp/tbg-log
nohup "$@" >/dev/null >/tmp/tbg-log/$0-$(date +%g%m%d%H%M%S%N) &
}
# Generate random password (optionally takes length of password as first argument)
genpasswd() {
local l=$1
[ -n "$l" ] || l=16
tr -dc A-Za-z0-9_ < /dev/urandom | head -c "$l" | xargs
}
# Generate random hex number of given lenght
genhex() {
if [ -z "$1" ]; then
echo "Size is required as first argument!" >&2
return 1
fi
tr -dc 0-9A-F < /dev/urandom | head -c "$1" | xargs
}
# Run given command every second
dorepeat() {
while true; do
"$@"
sleep 1
echo
done
}
# Clear all ssh control masters
ssh-clear() {
rm -rf ~/.cache/ssh
mkdir -p ~/.cache/ssh
}
# Chroot to bash to given path
chroot-bash() {
sudo chroot "$1" /bin/bash
}
# Run command with inotifywait
# First argument has to be files then -- is expected and everything else
# is command to be executed when file changes.
inrun () {
(
set -e
local TMPFS="$(mktemp --tmpdir inrun.XXXXXXXX)"
trap "rm '$TMPFS'; trap '' EXIT; exit 0" EXIT INT QUIT TERM ABRT
while [ $# -gt 0 -a "$1" != "--" ]; do
echo "$1" >> "$TMPFS"
shift
done
if [ $# -le 1 ]; then
echo "Usage: inrun FILE.. -- COMMAND"
return 1
fi
shift
while true; do
inotifywait -qe close_write --fromfile "$TMPFS" || true
"$@" || true
done
)
}
|