aboutsummaryrefslogtreecommitdiff
path: root/shellrc.d/function
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2018-08-12 18:37:31 +0200
committerKarel Kočí <cynerd@email.cz>2018-08-12 18:37:31 +0200
commita55cffa8b3cbc02e2b021ed25e67203d337c36bb (patch)
tree8ccc7d7fd3a8423af46a77c488511589142fc08b /shellrc.d/function
parent8720b8f7bb072a861dcc5b4be1c97b02f0912a9e (diff)
downloadshellrc-a55cffa8b3cbc02e2b021ed25e67203d337c36bb.tar.gz
shellrc-a55cffa8b3cbc02e2b021ed25e67203d337c36bb.tar.bz2
shellrc-a55cffa8b3cbc02e2b021ed25e67203d337c36bb.zip
Move some definitions around and add --desktop optionv0.5.2
Diffstat (limited to 'shellrc.d/function')
-rw-r--r--shellrc.d/function66
1 files changed, 66 insertions, 0 deletions
diff --git a/shellrc.d/function b/shellrc.d/function
new file mode 100644
index 0000000..56e648a
--- /dev/null
+++ b/shellrc.d/function
@@ -0,0 +1,66 @@
+# vim: ft=sh:
+
+# Run process in background
+tobg() {
+ "$@" >/dev/null 2>&1 &
+}
+
+# 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
+ )
+}