configuration/local/bin/delegator

129 lines
2.4 KiB
Plaintext
Raw Normal View History

2021-01-23 22:46:24 +01:00
#!/bin/sh
set -e
2024-08-02 11:09:49 +02:00
if [ -t 1 -a "$1" != '-g' ]; then
2021-01-23 22:46:24 +01:00
pick() {
sk
}
inject() {
echo "$@"
}
else
pick() {
2024-08-02 11:09:49 +02:00
if pgrep wayland >/dev/null; then
skmenu
else
dmenu -i -l 10
fi
2021-01-23 22:46:24 +01:00
}
inject() {
2024-08-02 11:09:49 +02:00
if pgrep wayland >/dev/null; then
wtype -s 500 "$*"
else
window="$(xdotool getwindowfocus)"
xdotool type --clearmodifiers --window "$window" "$*"
xdotool windowfocus "$window"
fi
2021-01-23 22:46:24 +01:00
}
fi
2024-08-02 11:09:49 +02:00
if wl-paste -h >/dev/null; then
primary() { wl-paste --primary; }
clip() { wl-paste; }
else
primary() { xclip -o; }
clip() { xclip -o -sel c; }
fi
2021-01-23 22:46:24 +01:00
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
2022-05-16 15:47:50 +02:00
spotify-title
youtube-dl
audio-dl
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')
2024-08-02 11:09:49 +02:00
inject "$(clip)"
2021-01-23 22:46:24 +01:00
;;
'selection')
2024-08-02 11:09:49 +02:00
inject "$(primary)"
2021-01-23 22:46:24 +01:00
;;
'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"
2024-08-02 11:09:49 +02:00
curl -LOJ "$(primary)"
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##* }"
;;
2022-05-16 15:47:50 +02:00
'spotify-title')
2024-08-02 11:09:49 +02:00
inject "$(curl -L "$(clip)" | sed -n 's@.*<title>\(.*\) - song \(and lyrics \)\?by \(.*\) | Spotify</title>.*@\1 _van_ \3@p')"
;;
'youtube-dl')
d="$(mktemp -d)"
trap "rm -r '$d'" EXIT KILL
cd "$d"
2024-08-02 11:09:49 +02:00
yt-dlp "$(primary)"
if mplayer -v >/dev/null; then
exec st mplayer *
else
exec st mpv *
fi
;;
'audio-dl')
d="$(mktemp -d)"
trap "rm -r '$d'" EXIT KILL
cd "$d"
2024-08-02 11:09:49 +02:00
yt-dlp -x "$(primary)"
exec st mpv --no-video *
2022-05-16 15:47:50 +02:00
;;
2021-01-23 22:46:24 +01:00
esac