dmenu-scripts/dmenu-link-handler
2023-11-04 22:03:43 +01:00

30 lines
731 B
Bash
Executable File

#!/bin/sh
# Feed this script a link or it will get it from your clipboard and it will give dmenu
# with some choice of programs to open the link with.
load_config() {
. $HOME/.config/dmenu/config
}
menu() {
case "$(printf "mpv\\nmpv audio\\nbrowser\\ncopy url [X11]\\ncopy url [Wayland]\\nw3m" | $DMENU -p "Open link with what program?")" in
mpv) start-program "$VIDEO" "$@" ;;
"mpv audio") "$VIDEO" "$@" --no-video ;;
browser) start-program "$BROWSER" "$@" ;;
"copy url [X11]") echo "$@" | xclip -selection clipboard ;;
"copy url [Wayland]") echo "$@" | wl-copy -n ;;
w3m) readable "$@" | w3m -T text/html ;;
esac
}
main() {
load_config
[ $# -eq 0 ] && link=$(xclip -sel c -o) || link="$@"
menu $link
}
main $@