forked from speedie/spmenu
upgrade run launcher significantly
This commit is contained in:
parent
a257e61d90
commit
cf1b79008b
|
@ -82,6 +82,12 @@ You may use long, descriptive arguments or the shorter arguments.
|
|||
`-nip, --no-indent `
|
||||
: Don't indent items to prompt width
|
||||
|
||||
`-ci, --color-items `
|
||||
: Color items
|
||||
|
||||
`-nci, --no-color-items `
|
||||
: Don't color items
|
||||
|
||||
`-a, --alpha `
|
||||
: Enable alpha
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ spmenu.class: spmenu
|
|||
spmenu.fast: 0
|
||||
spmenu.managed: 0
|
||||
spmenu.mon: -1
|
||||
spmenu.coloritems: 1
|
||||
|
||||
!! Image
|
||||
spmenu.imagewidth: 86
|
||||
|
|
|
@ -134,6 +134,10 @@ readargs(int argc, char *argv[])
|
|||
indentitems = 1;
|
||||
} else if (!strcmp(argv[i], "-nip") || (!strcmp(argv[i], "--no-indent"))) { // don't indent to prompt width
|
||||
indentitems = 0;
|
||||
} else if (!strcmp(argv[i], "-ci") || (!strcmp(argv[i], "--color-items"))) { // color items
|
||||
coloritems = 1;
|
||||
} else if (!strcmp(argv[i], "-nci") || (!strcmp(argv[i], "--no-color-items"))) { // don't color items
|
||||
coloritems = 0;
|
||||
} else if (i + 1 == argc) {
|
||||
// any of the arguments we checked first
|
||||
if ((!strcmp(argv[i], "-xrdb")
|
||||
|
@ -358,6 +362,8 @@ usage(void)
|
|||
"spmenu -p, --prompt <text> Set spmenu prompt text to <text>\n"
|
||||
"spmenu -ip, --indent Indent items to prompt width\n"
|
||||
"spmenu -nip, --no-indent Don't indent items to prompt width\n"
|
||||
"spmenu -ci, --color-items Color items\n"
|
||||
"spmenu -nci, --no-color-items Don't color items\n"
|
||||
"spmenu -a, --alpha Enable alpha\n"
|
||||
"spmenu -na, --no-alpha Disable alpha\n"
|
||||
"spmenu -tp, --allow-typing Allow the user to type\n"
|
||||
|
|
|
@ -64,6 +64,9 @@ drawitemtext(struct item *item, int x, int y, int w)
|
|||
memcpy(scm, scheme[SchemeItemNormPri], sizeof(scm));
|
||||
}
|
||||
|
||||
// don't color
|
||||
if (!coloritems) memcpy(scm, scheme[SchemeItemNorm], sizeof(scm));
|
||||
|
||||
drw_setscheme(drw, scm); // set scheme
|
||||
|
||||
// parse item text
|
||||
|
|
|
@ -94,6 +94,7 @@ ResourcePref resources[] = {
|
|||
{ "color14", STRING, &col_sgrcolor14 },
|
||||
{ "color15", STRING, &col_sgrcolor15 },
|
||||
|
||||
{ "coloritems", INTEGER, &coloritems },
|
||||
{ "menuposition", INTEGER, &menuposition },
|
||||
{ "menupaddingv", INTEGER, &menupaddingv },
|
||||
{ "menupaddingh", INTEGER, &menupaddingh },
|
||||
|
|
|
@ -160,4 +160,5 @@ static int pango_password = 0; /* Enable support for pango markup f
|
|||
#define borderalpha opaque /* Border alpha */
|
||||
|
||||
/* Misc */
|
||||
static char worddelimiters[] = " "; /* Word delimiters, " " is default. */
|
||||
static int coloritems = 1; /* Color items or not */
|
||||
static char worddelimiters[] = " "; /* Word delimiters used for keybinds that change words, " " is default. */
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
[ -z "$TERMINAL" ] && TERMINAL="st -e"
|
||||
[ -z "$BROWSER" ] && BROWSER="xdg-open"
|
||||
[ -z "$TORRENT" ] && TORRENT="qbittorrent"
|
||||
[ -z "$WEB_GREP" ] && WEB_GREP="http:|https:|www[.]"
|
||||
[ -z "$MAGNET_GREP" ] && MAGNET_GREP="magnet:?"
|
||||
[ -z "$HISTORY" ] && HISTORY="${XDG_CACHE_HOME:-$HOME/.cache/}/spmenu_run.hist"
|
||||
[ -z "$RUNLAUNCHER" ] && RUNLAUNCHER=spmenu
|
||||
[ -z "$RUNLAUNCHER_ARGS" ] && RUNLAUNCHER_ARGS="--insert --hist-file $HISTORY $*"
|
||||
|
@ -25,7 +27,7 @@ path() {
|
|||
}
|
||||
|
||||
print_help() {
|
||||
cat << EOF | $RUNLAUNCHER $RUNLAUNCHER_ARGS --lines 20 --columns 1 --normal --sgr1 "#FFFF00" --hide-cursor --no-allow-typing > /dev/null
|
||||
cat << EOF | $RUNLAUNCHER $RUNLAUNCHER_ARGS --lines 20 --columns 1 --normal --sgr1 "#FFFF00" --hide-cursor --no-allow-typing --no-color-items --prompt "" > /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.
|
||||
|
@ -38,26 +40,52 @@ $(printf '\033[0;31m')Note: This may also be displayed if you deleted your spmen
|
|||
EOF
|
||||
}
|
||||
|
||||
# run spmenu and parse it
|
||||
print_config() {
|
||||
[ -f "$HOME/.config/spmenu/run/config" ] && . "$HOME/.config/spmenu/run/config" && return
|
||||
mkdir -p "$HOME/.config/spmenu/run"
|
||||
cat << EOF > "$HOME/.config/spmenu/run/config"
|
||||
# spmenu_run default configuration file
|
||||
TERMINAL="\${TERMINAL:-st -e}" # Terminal
|
||||
BROWSER="\${BROWSER:-xdg-open}" # Web browser
|
||||
TORRENT="\${TORRENT:-qbittorrent}" # Torrent client
|
||||
WEB_GREP="http:|https:|www[.]" # Needs to be in grep -E syntax
|
||||
MAGNET_GREP="magnet:?" # Needs to be in grep -E syntax
|
||||
HISTORY="\${XDG_CACHE_HOME:-\$HOME/.cache/}/spmenu_run.hist" # History file
|
||||
RUNLAUNCHER="\${RUNLAUNCHER:-spmenu}" # Run launcher to use
|
||||
RUNLAUNCHER_ARGS="--insert --hist-file \$HISTORY \$*"
|
||||
EOF
|
||||
[ -f "$HOME/.config/spmenu/run/config" ] && . "$HOME/.config/spmenu/run/config" && return
|
||||
}
|
||||
|
||||
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 '%c' "$dout")" = "#" ] && EXEC=term
|
||||
[ "$(printf "$dout" | awk '{ print $1 }')" = "magnet" ] && EXEC=torrent
|
||||
[ "$(printf "$dout" | awk '{ print $1 }')" = "www" ] && EXEC=web
|
||||
[ "$(printf "$dout" | awk '{ print $1 }')" = "?" ] && print_help && main && return
|
||||
|
||||
# terminal
|
||||
[ -z "$RUN_ARG" ] && \
|
||||
printf "%s" "$dout" | sed "s/#//g" | ${SHELL:-"/bin/sh"} &
|
||||
# check for keywords
|
||||
printf "%s" "$dout" | grep -qE "$WEB_GREP" && EXEC=web
|
||||
printf "%s" "$dout" | grep -qE "$MAGNET_GREP" && EXEC=torrent
|
||||
}
|
||||
|
||||
[ "$RUN_ARG" = "$TERMINAL" ] && $TERMINAL -e "$(printf "%s" "$dout" | sed "s/#//g")"; return
|
||||
exec_cmd() {
|
||||
[ -z "$EXEC" ] && EXEC=shell
|
||||
case "$EXEC" in
|
||||
"shell") printf "%s" "$dout" | sed "s/#//g" | ${SHELL:-"/bin/sh"} & ;;
|
||||
"term") $TERMINAL -e "$(printf "%s" "$dout" | sed "s/#//g")" & ;;
|
||||
"web") $BROWSER "$(printf "$dout" | sed "s/www //g")" & ;;
|
||||
"torrent") $TORRENT "$(printf "$dout" | sed "s/magnet //g")" & ;;
|
||||
esac
|
||||
}
|
||||
|
||||
main() {
|
||||
check "$@"
|
||||
print_config "$@"
|
||||
parse "$@"
|
||||
exec_cmd "$@"
|
||||
rm -f "$HOME/.cache/spmenu_run"
|
||||
}
|
||||
|
||||
|
|
8
spmenu.1
8
spmenu.1
|
@ -1,4 +1,4 @@
|
|||
.\" Automatically generated by Pandoc 3.1
|
||||
.\" Automatically generated by Pandoc 3.0.1
|
||||
.\"
|
||||
.\" Define V font for inline verbatim, using C font in formats
|
||||
.\" that render this, and otherwise B font.
|
||||
|
@ -98,6 +98,12 @@ Indent items to prompt width
|
|||
\f[V]-nip, --no-indent\f[R]
|
||||
Don\[cq]t indent items to prompt width
|
||||
.TP
|
||||
\f[V]-ci, --color-items\f[R]
|
||||
Color items
|
||||
.TP
|
||||
\f[V]-nci, --no-color-items\f[R]
|
||||
Don\[cq]t color items
|
||||
.TP
|
||||
\f[V]-a, --alpha\f[R]
|
||||
Enable alpha
|
||||
.TP
|
||||
|
|
Loading…
Reference in a new issue