forked from speedie/spmenu
65 lines
2.5 KiB
Bash
Executable file
65 lines
2.5 KiB
Bash
Executable file
#!/bin/sh
|
|
[ -z "$TERMINAL" ] && TERMINAL="st -e"
|
|
[ -z "$BROWSER" ] && BROWSER="xdg-open"
|
|
[ -z "$TORRENT" ] && TORRENT="qbittorrent"
|
|
[ -z "$HISTORY" ] && HISTORY="${XDG_CACHE_HOME:-$HOME/.cache/}/spmenu_run.hist"
|
|
[ -z "$RUNLAUNCHER" ] && RUNLAUNCHER=spmenu
|
|
[ -z "$RUNLAUNCHER_ARGS" ] && RUNLAUNCHER_ARGS="--insert --hist-file $HISTORY $*"
|
|
|
|
check() {
|
|
[ ! -d "$HOME/.config/spmenu/run" ] && mkdir -p "$HOME/.config/spmenu/run"
|
|
if [ ! -f "$HOME/.config/spmenu/run/.first_run" ]; then
|
|
print_help
|
|
touch "$HOME/.config/spmenu/run/.first_run"
|
|
fi
|
|
}
|
|
|
|
path() {
|
|
printf "%s\n" "$PATH" | \
|
|
tr ':' '\n' | \
|
|
uniq | sed 's#$#/#' | \
|
|
xargs ls -lu --time-style=+%s 2>&1 | \
|
|
awk '/^(-|l)/ { print $6, $7 }' | \
|
|
sort -rn | \
|
|
cut -d' ' -f 2 2>&1
|
|
}
|
|
|
|
print_help() {
|
|
cat << EOF | $RUNLAUNCHER $RUNLAUNCHER_ARGS --lines 20 --columns 1 --normal --sgr1 "#FFFF00" --hide-cursor --no-allow-typing > /dev/null
|
|
Start typing in keywords to list out entries. Press Enter to select an entry. The selected entry will be run through a shell.
|
|
To set spmenu options, you pass arguments to 'spmenu_run' directly. See 'spmenu --help' for a list of valid arguments.
|
|
To configure spmenu, you may also copy /usr/share/spmenu/example.Xresources to $HOME/.config/spmenu/spmenurc and edit that.
|
|
|
|
- Type in '?' to show this help screen at any time.
|
|
- If the entry selected starts with 'www', it will instead be treated as a link and spawned in a web browser (\$BROWSER)
|
|
- If the entry selected starts with 'magnet', it will instead be treated as a magnet link and spawned in a torrent client (\$TORRENT)
|
|
|
|
$(printf '\033[0;31m')Note: This may also be displayed if you deleted your spmenu configuration directory.
|
|
EOF
|
|
}
|
|
|
|
# run spmenu and parse it
|
|
parse() {
|
|
dout="$(path | sed "s/\&/\&/g" | $RUNLAUNCHER $RUNLAUNCHER_ARGS)"
|
|
|
|
# parse
|
|
[ "$(printf '%c' "$dout")" = "#" ] && RUN_ARG="$TERMINAL"
|
|
[ "$(printf "$dout" | awk '{ print $1 }')" = "magnet" ] && "$TORRENT" "$(printf "$dout" | sed "s/magnet //")"
|
|
[ "$(printf "$dout" | awk '{ print $1 }')" = "www" ] && "$BROWSER" "$(printf "$dout" | sed "s/www //")"
|
|
[ "$(printf "$dout" | awk '{ print $1 }')" = "?" ] && print_help && main && return
|
|
|
|
# terminal
|
|
[ -z "$RUN_ARG" ] && \
|
|
printf "%s" "$dout" | sed "s/#//g" | ${SHELL:-"/bin/sh"} &
|
|
|
|
[ "$RUN_ARG" = "$TERMINAL" ] && $TERMINAL -e "$(printf "%s" "$dout" | sed "s/#//g")"; return
|
|
}
|
|
|
|
main() {
|
|
check "$@"
|
|
parse "$@"
|
|
rm -f "$HOME/.cache/spmenu_run"
|
|
}
|
|
|
|
main "$@"
|