# vim: ft=sh: # Create directory and change in to it mcd() { mkdir -p "$*" cd "$*" } # Run process in background tbg() { mkdir -p /tmp/tbg-log nohup "$@" >"/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 } # Clear all ssh control masters sshclear() { rm -rf ~/.cache/ssh mkdir -p ~/.cache/ssh } # 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 tmpfs="$(mktemp --tmpdir inrun.XXXXXXXX)" trap "rm '\$tmpfs'; trap '' EXIT; exit 0" EXIT INT QUIT TERM ABRT while [ $# -gt 0 ] && [ "$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 ) }