blob: c0d98f359ad36707f7e82b5a3534137b10f2f878 (
plain) (
tree)
|
|
#!/bin/bash
WEB_BROWSER=brave
EMAIL_CLIENT=claws-mail
if test -x /usr/bin/terminator; then
TERMINAL=terminator
elif test -x /usr/bin/st; then
TERMINAL=st
else
TERMINAL=xterm
fi
sel="$(xclip -o)"
url="$(printf '%s' "$sel" | tr -d '\n')"
file="$(printf '%s' "$sel" | tr -d '\n')"
if test -z "$sel"; then
exit 0
fi
cd -- "$(readlink "/proc/$(pstree -lpA "$(xprop -id "$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')" | grep PID | head -n 1 | cut -d ' ' -f 3)" | awk -F--- '{print $NF}' | tail -n1 | tr -Cd '[0-9]')/cwd")"
functions=""
if test -d "$sel" || test -d "$(printf '%s\n' "$sel" | sed 's|^~/|'"${HOME}|")"; then
functions="$functions caja terminal"
caja () {
exec c "$sel";
}
terminal () {
cd -- "$sel"
exec $TERMINAL;
}
elif test -e "$sel"; then
functions="$functions open"
open () {
exec xdg-open -- "$url";
}
fi
if printf '%s\n' "$url" | grep '^\(https\?://\|www\.\)[^[:space:]./]\+\.[^[:space:]/]*\(/\S*\)\?$' > /dev/null; then
if printf '%s\n' "$url" | grep '^\(https\?://\)\?\(www\.\)\?spreaker\.com/.*/.*/.*' > /dev/null; then
functions="$functions spreaker-dl"
spreaker-dl () {
cd ~/next/new
exec spreaker-dl "$url";
}
fi
functions="$functions web-browser"
web-browser () {
exec $WEB_BROWSER -- "$url";
}
fi
if printf '%s\n' "$url" | grep '^\(mailto:\)\?\("[^"]\+"\|[a-zA-Z0-9!#$%&'\''*+/=?^_`{|}~-]\+\(\.[a-zA-Z0-9!#$%&'\''*+/=?^_`{|}~-]\)*\)@[^[:space:]./]\+\.[^[:space:]/]*$' > /dev/null; then
functions="$functions email-client"
email-client () {
exec $EMAIL_CLIENT -- "$url";
}
fi
if test -r "$file" && file "$file" | grep '\(PNG\|JPEG\) image' > /dev/null; then
functions="$functions xwallpaper"
xwallpaper () {
exec xwallpaper --zoom "$file";
}
fi
functions="$functions wiktionary.en"
wiktionary.en () {
exec $WEB_BROWSER "https://en.wiktionary.org/wiki/$sel";
}
functions="$functions wiktionary.sv"
wiktionary.sv () {
exec $WEB_BROWSER "https://sv.wiktionary.org/wiki/$sel";
}
functions="$functions wikipedia.en"
wikipedia.en () {
exec $WEB_BROWSER "https://en.wikipedia.org/wiki/$sel";
}
functions="$functions wikipedia.sv"
wikipedia.sv () {
exec $WEB_BROWSER "https://sv.wikipedia.org/wiki/$sel";
}
functions="$functions duckduckgo"
duckduckgo () {
exec $WEB_BROWSER "https://duckduckgo.com/?q=$sel";
}
# TODO add other search engines
if (( $(printf '%s' "$sel" | wc -m) > 100 )); then
sel='selected text'
fi
function="$(printf '%s\n' $functions | dmenu -i -p "Plumb $sel to:" -l 50)"
if test -n "$function"; then
"$function"
fi
|