about summary refs log tree commit diff stats
path: root/bin/pw
diff options
context:
space:
mode:
Diffstat (limited to 'bin/pw')
-rwxr-xr-xbin/pw14
1 files changed, 14 insertions, 0 deletions
diff --git a/bin/pw b/bin/pw
new file mode 100755
index 0000000..140f1dc
--- /dev/null
+++ b/bin/pw
@@ -0,0 +1,14 @@
+#!/bin/sh
+# generates a password of length $1, sends it to stdout if $2 isn't clip.
+# if it is clip, sends it to the X clipboard and clears it after 10 seconds.
+if [ "$1" = "-h" ]; then
+	printf 'usage: %s [-h]|LENGTH [clip]\n' "$(basename $0)">/dev/stderr&&return 1
+fi
+PW=$(tr -cd "[:alnum:][:punct:]"</dev/urandom|fold -w $1|head -1)
+if [ "$2" = "clip" ]; then
+	printf '%s' "$PW"|xclip -sel clip -i&&notify-send "Password Generated" "$1-character password generated. It will clear in 10 seconds."
+	sleep 10
+	printf "\0"|xclip -sel clip -i&&notify-send "Clipboard Cleared" "Generated password cleared from clipboard."
+else
+	printf '%s\n' "$PW"
+fi