diff --git a/scripts/spmenu_run b/scripts/spmenu_run index 5f9cef2..eb6004c 100755 --- a/scripts/spmenu_run +++ b/scripts/spmenu_run @@ -3,17 +3,50 @@ [ -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 $*" -path() { echo "$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; } +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" | spmenu --insert --hist-file "$HISTORY" "$@")" + 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" ] && \ @@ -23,6 +56,7 @@ parse() { } main() { + check "$@" parse "$@" rm -f "$HOME/.cache/spmenu_run" }