configuration/local/bin/delegator

89 lines
1.6 KiB
Plaintext
Raw Normal View History

2021-01-23 22:46:24 +01:00
#!/bin/sh
set -e
if [ -t 1 ]; then
pick() {
sk
}
inject() {
echo "$@"
}
else
window="$(xdotool getwindowfocus)"
pick() {
dmenu -i -l 10
}
inject() {
xdotool type --clearmodifiers --window "$window" "$*"
xdotool windowfocus "$window"
}
fi
choice="$(pick <<HERE
email address
pass
lpass
2021-01-23 22:46:24 +01:00
clipboard
selection
run
2021-03-16 10:50:03 +01:00
otp
student
curl
2021-06-16 11:30:34 +02:00
clipmenu
yubikey
emoji
2021-01-23 22:46:24 +01:00
HERE
)"
case "$choice" in
'email address')
choice="$(khard email -p --remove-first-line | sed 's/\(.*\)\t\(.*\)\t\(.*\)/\2 <\1>/' | pick)"
inject "$choice"
;;
'pass')
2021-01-23 22:46:24 +01:00
choice="$(cd ~/.password-store; find * -name '*.gpg' | sed 's/\.gpg$//' | sort -d | pick)"
2021-03-16 10:50:03 +01:00
inject "$(pass show "$choice" | head -1)"
2021-01-23 22:46:24 +01:00
;;
'lpass')
choice="$(lpass ls --format '%an' --color=never | grep -v '^$' | pick)"
inject "$(lpass show --password "$choice" | head -1)"
;;
2021-01-23 22:46:24 +01:00
'clipboard')
inject "$(xclip -o -sel c)"
;;
'selection')
inject "$(xclip -o)"
;;
'run')
choice="$(dmenu_path | pick)"
exec "$choice"
;;
2021-03-16 10:50:03 +01:00
'otp')
choice="$(cd ~/.password-store/otp; find * -name '*.gpg' | sed 's/\.gpg$//' | sort -d | pick)"
inject "$(pass otp code otp/"$choice" | head -1)"
;;
'student')
2021-09-23 19:46:39 +02:00
choice="$(pick < ~/.local/share/students.list)"
2021-03-16 10:50:03 +01:00
inject "$choice"
;;
'curl')
d="$(mktemp -d)"
trap "rm -r '$d'" EXIT KILL
cd "$d"
2022-01-04 00:24:36 +01:00
curl -LOJ "$(xclip -o)"
rifle -fF *
2021-06-16 11:30:34 +02:00
;;
'clipmenu')
exec clipmenu
;;
'yubikey')
choice="$(ykman oath accounts list | pick)"
inject "$(ykman oath accounts code -s "$choice")"
;;
'emoji')
choice="$(uni emoji all -f '%(name), %(cldr_full), %(emoji)' | awk -F', ' '{ i=1; while($i != $NF && $i != "") { print($i, $NF); i++ }}' | pick)"
inject "${choice##* }"
;;
2021-01-23 22:46:24 +01:00
esac