add the ability to run functions from the config file
This commit is contained in:
parent
074723ae51
commit
5deac136ce
4
Makefile
4
Makefile
|
@ -35,9 +35,7 @@ spmenu: spmenu.o libs/sl/draw.o libs/sl/main.o
|
||||||
$(CC) -o $@ spmenu.o draw.o main.o $(LDFLAGS)
|
$(CC) -o $@ spmenu.o draw.o main.o $(LDFLAGS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f spmenu *.o \
|
rm -f spmenu spmenu-$(VERSION).tar.gz spmenu-$(VERSION).PKGBUILD *.o *zst*
|
||||||
spmenu-$(VERSION).tar.gz \
|
|
||||||
*zst* spmenu-$(VERSION).PKGBUILD
|
|
||||||
|
|
||||||
dist: clean
|
dist: clean
|
||||||
mkdir -p spmenu-$(VERSION)
|
mkdir -p spmenu-$(VERSION)
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
[ -z "$SORT_ARGS" ] && SORT_ARGS=""
|
[ -z "$SORT_ARGS" ] && SORT_ARGS=""
|
||||||
[ -z "$HIDDEN_KEYWORDS" ] && HIDDEN_KEYWORDS="spmenu"
|
[ -z "$HIDDEN_KEYWORDS" ] && HIDDEN_KEYWORDS="spmenu"
|
||||||
[ -z "$KEYWORDS" ] && KEYWORDS=""
|
[ -z "$KEYWORDS" ] && KEYWORDS=""
|
||||||
|
[ -z "$DISPLAY_DUPLICATES" ] && DISPLAY_DUPLICATES="false"
|
||||||
|
|
||||||
check() {
|
check() {
|
||||||
[ ! -d "$HOME/.config/spmenu/run" ] && mkdir -p "$HOME/.config/spmenu/run"
|
[ ! -d "$HOME/.config/spmenu/run" ] && mkdir -p "$HOME/.config/spmenu/run"
|
||||||
|
@ -30,10 +31,11 @@ path() {
|
||||||
|
|
||||||
[ -z "$HIDDEN_KEYWORDS" ] && HIDDEN_KEYWORDS="NULL_ENTRY"
|
[ -z "$HIDDEN_KEYWORDS" ] && HIDDEN_KEYWORDS="NULL_ENTRY"
|
||||||
|
|
||||||
|
print_menu() {
|
||||||
print() {
|
print() {
|
||||||
printf "%s\n" "$PATH" | \
|
printf "%s\n" "$PATH" | \
|
||||||
tr ':' '\n' | \
|
tr ':' '\n' | \
|
||||||
uniq | sed 's#$#/#' | \
|
sed 's#$#/#' | \
|
||||||
xargs ls -lu --time-style=+%s 2>&1 | \
|
xargs ls -lu --time-style=+%s 2>&1 | \
|
||||||
grep -vE "$HIDDEN_KEYWORDS" | \
|
grep -vE "$HIDDEN_KEYWORDS" | \
|
||||||
grep -E "$KEYWORDS"
|
grep -E "$KEYWORDS"
|
||||||
|
@ -46,6 +48,16 @@ path() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# uniq
|
||||||
|
if [ "$DISPLAY_DUPLICATES" != "false" ]; then
|
||||||
|
print_menu
|
||||||
|
else
|
||||||
|
print_menu | uniq
|
||||||
|
fi
|
||||||
|
|
||||||
|
command -v pre_func && pre_func
|
||||||
|
}
|
||||||
|
|
||||||
print_help() {
|
print_help() {
|
||||||
cat << EOF | $RUNLAUNCHER $RUNLAUNCHER_ARGS --lines 20 --columns 1 --normal --sgr1 "#FFFF00" --hide-cursor --no-allow-typing --no-color-items --hide-prompt --hide-powerline --hide-input --hide-right-arrow --hide-left-arrow --hide-mode --hide-match-count > /dev/null
|
cat << EOF | $RUNLAUNCHER $RUNLAUNCHER_ARGS --lines 20 --columns 1 --normal --sgr1 "#FFFF00" --hide-cursor --no-allow-typing --no-color-items --hide-prompt --hide-powerline --hide-input --hide-right-arrow --hide-left-arrow --hide-mode --hide-match-count > /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.
|
Start typing in keywords to list out entries. Press Enter to select an entry. The selected entry will be run through a shell.
|
||||||
|
@ -65,20 +77,35 @@ print_config() {
|
||||||
mkdir -p "$HOME/.config/spmenu/run"
|
mkdir -p "$HOME/.config/spmenu/run"
|
||||||
cat << EOF > "$HOME/.config/spmenu/run/config"
|
cat << EOF > "$HOME/.config/spmenu/run/config"
|
||||||
# spmenu_run default configuration file
|
# spmenu_run default configuration file
|
||||||
TERMINAL="\${TERMINAL:-st -e}" # Terminal
|
#
|
||||||
BROWSER="\${BROWSER:-xdg-open}" # Web browser
|
# This is the configuration file for the run launcher spmenu comes with.
|
||||||
TORRENT="\${TORRENT:-qbittorrent}" # Torrent client
|
# It is not the configuration file for spmenu, see ~/.config/spmenu/spmenu.conf for that.
|
||||||
|
#
|
||||||
|
# spmenu_run runs function 'pre_func' before spawning spmenu, and 'post_func' after spawning spmenu.
|
||||||
|
# You may create those functions below. For 'post_func', the selected item is passed as an argument (\$1)
|
||||||
|
#
|
||||||
|
# For example, to implement a basic history file:
|
||||||
|
#
|
||||||
|
# post_func() {
|
||||||
|
# rm -f /tmp/spmenu_entryhist; printf "\$1\n" >> /tmp/spmenu_entryhist
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# You can use anything POSIX compliant shells support, as well as programs available on the system.
|
||||||
|
TERMINAL="\${TERMINAL:-st -e}" # Terminal commands are spawned in
|
||||||
|
BROWSER="\${BROWSER:-xdg-open}" # Web browser, for URLs
|
||||||
|
TORRENT="\${TORRENT:-qbittorrent}" # Torrent client, for magnet links
|
||||||
WEB_GREP="http:|https:|www[.]" # Needs to be in grep -E syntax
|
WEB_GREP="http:|https:|www[.]" # Needs to be in grep -E syntax
|
||||||
MAGNET_GREP="magnet:?" # 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
|
HISTORY="\${XDG_CACHE_HOME:-\$HOME/.cache/}/spmenu_run.hist" # History file, spmenu (meaning your user) must have permission to read and write to it.
|
||||||
RUNLAUNCHER="\${RUNLAUNCHER:-spmenu}" # Run launcher to use
|
RUNLAUNCHER="\${RUNLAUNCHER:-spmenu}" # Run launcher to use
|
||||||
RUNLAUNCHER_ARGS="--insert --hist-file \$HISTORY \$*"
|
RUNLAUNCHER_ARGS="--insert --hist-file \$HISTORY \$*" # Arguments passed to \$RUNLAUNCHER
|
||||||
SORT_BY_NUMBER="true" # Sort by numbers
|
SORT_BY_NUMBER="true" # Sort by numbers
|
||||||
SORT_IN_REVERSE="true" # Sort in reverse
|
SORT_IN_REVERSE="true" # Sort in reverse
|
||||||
SORT_BY_RECENT="false" # Sort by recent
|
SORT_BY_RECENT="false" # Sort by recent
|
||||||
SORT_ARGS="" # Extra arguments passed to the sort command.
|
SORT_ARGS="" # Extra arguments passed to the sort command.
|
||||||
HIDDEN_KEYWORDS="spmenu" # Keywords that will be ignored, needs to be in grep -vE syntax.
|
HIDDEN_KEYWORDS="spmenu" # Keywords that will be ignored, needs to be in grep -vE syntax.
|
||||||
KEYWORDS="" # Keywords that will be matched, needs to be in grep -E syntax.
|
KEYWORDS="" # Keywords that will be matched, needs to be in grep -E syntax.
|
||||||
|
DISPLAY_DUPLICATES="false" # Display duplicates or not
|
||||||
EOF
|
EOF
|
||||||
[ -f "$HOME/.config/spmenu/run/config" ] && . "$HOME/.config/spmenu/run/config" && return
|
[ -f "$HOME/.config/spmenu/run/config" ] && . "$HOME/.config/spmenu/run/config" && return
|
||||||
}
|
}
|
||||||
|
@ -99,11 +126,13 @@ parse() {
|
||||||
|
|
||||||
exec_cmd() {
|
exec_cmd() {
|
||||||
[ -z "$EXEC" ] && EXEC=shell
|
[ -z "$EXEC" ] && EXEC=shell
|
||||||
|
command -v post_func && post_func "$dout"
|
||||||
|
|
||||||
case "$EXEC" in
|
case "$EXEC" in
|
||||||
"shell") printf "%s" "$dout" | sed "s/#//g" | ${SHELL:-"/bin/sh"} & ;;
|
"shell") printf "%s" "$dout" | sed "s/#//g" | ${SHELL:-"/bin/sh"} & ;;
|
||||||
"term") $TERMINAL -e "$(printf "%s" "$dout" | sed "s/#//g")" & ;;
|
"term") $TERMINAL -e "$(printf "%s" "$dout" | sed "s/#//g")" & ;;
|
||||||
"web") $BROWSER "$(printf "$dout" | sed "s/www //g")" & ;;
|
"web") $BROWSER "$(printf "%s" "$dout" | sed "s/www //g")" & ;;
|
||||||
"torrent") $TORRENT "$(printf "$dout" | sed "s/magnet //g")" & ;;
|
"torrent") $TORRENT "$(printf "%s" "$dout" | sed "s/magnet //g")" & ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +141,6 @@ main() {
|
||||||
print_config "$@"
|
print_config "$@"
|
||||||
parse "$@"
|
parse "$@"
|
||||||
exec_cmd "$@"
|
exec_cmd "$@"
|
||||||
rm -f "$HOME/.cache/spmenu_run"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|
Loading…
Reference in a new issue