configuration/local/bin/delegator
2021-05-07 00:00:06 +02:00

69 lines
1.1 KiB
Bash
Executable File

#!/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
password
clipboard
selection
run
otp
student
curl
HERE
)"
case "$choice" in
'email address')
choice="$(khard email -p --remove-first-line | sed 's/\(.*\)\t\(.*\)\t\(.*\)/\2 <\1>/' | pick)"
inject "$choice"
;;
'password')
choice="$(cd ~/.password-store; find * -name '*.gpg' | sed 's/\.gpg$//' | sort -d | pick)"
inject "$(pass show "$choice" | head -1)"
;;
'clipboard')
inject "$(xclip -o -sel c)"
;;
'selection')
inject "$(xclip -o)"
;;
'run')
choice="$(dmenu_path | pick)"
exec "$choice"
;;
'otp')
choice="$(cd ~/.password-store/otp; find * -name '*.gpg' | sed 's/\.gpg$//' | sort -d | pick)"
inject "$(pass otp code otp/"$choice" | head -1)"
;;
'student')
choice="$(pick < /data/courses/students.csv)"
inject "$choice"
;;
'curl')
d="$(mktemp -d)"
trap "rm -r '$d'" EXIT KILL
cd "$d"
curl -OJ "$(xclip -o)"
rifle -fF *
esac