add ${PREFIX} to scripts, may improve compatibility with for example

NixOS
This commit is contained in:
speedie 2023-04-03 14:54:44 +02:00
parent 13b4c95982
commit c44333b3ce
7 changed files with 35 additions and 24 deletions

View file

@ -118,6 +118,7 @@ spmenu.hideimage: 0
!! Text !! Text
spmenu.prompt: spmenu.prompt:
spmenu.input:
spmenu.normtext: Normal spmenu.normtext: Normal
spmenu.instext: Insert spmenu.instext: Insert
spmenu.password: * spmenu.password: *

View file

@ -352,6 +352,10 @@ readargs(int argc, char *argv[])
fstrncmp = strncasecmp; fstrncmp = strncasecmp;
fstrstr = cistrstr; fstrstr = cistrstr;
} }
// initial text
if (input)
insert(input, strlen(input));
} }
void void

View file

@ -62,7 +62,6 @@ ResourcePref resources[] = {
{ "minwidth", INTEGER, &minwidth }, { "minwidth", INTEGER, &minwidth },
{ "preselected", INTEGER, &preselected }, { "preselected", INTEGER, &preselected },
{ "password", STRING, &password }, { "password", STRING, &password },
{ "prompt", STRING, &prompt },
{ "class", STRING, &class }, { "class", STRING, &class },
{ "normtext", STRING, &normtext }, { "normtext", STRING, &normtext },
{ "instext", STRING, &instext }, { "instext", STRING, &instext },

View file

@ -43,10 +43,12 @@ static int borderwidth = 2; /* Width of the border */
static char font[] = "Noto Sans Mono 8"; /* Font to draw text and Pango markup with. */ static char font[] = "Noto Sans Mono 8"; /* Font to draw text and Pango markup with. */
static int textpadding = 0; /* Text padding (lrpad) */ static int textpadding = 0; /* Text padding (lrpad) */
/* Symbol options */ /* Text options */
static char *leftarrow = "<"; /* Left arrow, used to indicate you can move to the left */ static char *leftarrow = "<"; /* Left arrow, used to indicate you can move to the left */
static char *rightarrow = ">"; /* Right arrow, used to indicate you can move to the right */ static char *rightarrow = ">"; /* Right arrow, used to indicate you can move to the right */
static char password = '*'; /* Password character, when the -P argument is active this will replace all characters typed */ static char password = '*'; /* Password character, when the -P argument is active this will replace all characters typed */
static char *prompt = NULL; /* Default prompt */
static char *input = NULL; /* Default input text */
/* Match options */ /* Match options */
static int type = 1; /* Allow typing into spmenu or only allow keybinds. */ static int type = 1; /* Allow typing into spmenu or only allow keybinds. */
@ -67,7 +69,6 @@ static int histnodup = 1; /* If 0, record repeated histories *
/* Prompt options */ /* Prompt options */
static int indentitems = 1; /* Indent items to prompt width? (0/1) */ static int indentitems = 1; /* Indent items to prompt width? (0/1) */
static char *prompt = NULL; /* Default prompt, set to NULL (nothing) */
/* Hide options */ /* Hide options */
static int hideinput = 0; /* Hide input (0/1) */ static int hideinput = 0; /* Hide input (0/1) */

View file

@ -1,32 +1,35 @@
#!/bin/sh #!/bin/sh
# spmenu_profile # spmenu_profile
CONFDIR="${XDG_CONFIG_HOME:-$HOME/.config}"
PREFIX="${PREFIX:-/usr}"
load_profile() { load_profile() {
[ -f "$HOME/.config/spmenu/.profile" ] && PROFILE="$(cat "$HOME/.config/spmenu/.profile")" [ -f "${CONFDIR}/spmenu/.profile" ] && PROFILE="$(cat "${CONFDIR}/spmenu/.profile")"
[ -n "$PROFILE" ] && xrdb -override "$PROFILE" [ -n "$PROFILE" ] && xrdb -override "$PROFILE"
} }
set_profile() { set_profile() {
pgrep -x spmenu && pkill -x spmenu pgrep -x spmenu && pkill -x spmenu
profiles="$(find "$HOME/.config/spmenu/profiles" -type f)" profiles="$(find "${CONFDIR}/spmenu/profiles" -type f)"
profilec="$(find "$HOME/.config/spmenu/profiles" -type f | wc -l)" profilec="$(find "${CONFDIR}/spmenu/profiles" -type f | wc -l)"
sel="$(list_profiles list | spmenu --lines 20 --columns 1 --prompt "Profile settings" --hide-match-count --hide-left-arrow --hide-right-arrow --hide-input --hide-image --hide-mode --hide-cursor --hide-highlighting --normal --no-allow-typing | sed -e 's/\x1b\[[0-9;]*m//g')" sel="$(list_profiles list | spmenu --lines 20 --columns 1 --prompt "Profile settings" --hide-match-count --hide-left-arrow --hide-right-arrow --hide-input --hide-image --hide-mode --hide-cursor --hide-highlighting --normal | sed -e 's/\x1b\[[0-9;]*m//g')"
check check
} }
add_profile() { add_profile() {
selprofile="$(printf "" | spmenu --lines 20 --columns 1 --prompt "Enter a name for the profile:" --hide-mode --hide-match-count --hide-left-arrow --hide-right-arrow --hide-image --hide-cursor --hide-highlighting --insert | tr -d ' ' | sed -e 's/\x1b\[[0-9;]*m//g')" selprofile="$(printf "" | spmenu --lines 20 --columns 1 --prompt "Enter a name for the profile:" --hide-mode --hide-match-count --hide-left-arrow --hide-right-arrow --hide-image --hide-highlighting --insert | tr -d ' ' | sed -e 's/\x1b\[[0-9;]*m//g')"
[ -f "/usr/share/spmenu/example.Xresources" ] && cp "/usr/share/spmenu/example.Xresources" "$HOME/.config/spmenu/profiles/$selprofile" [ -f "${DESTDIR}${PREFIX}/share/spmenu/example.Xresources" ] && cp "${DESTDIR}${PREFIX}/share/spmenu/example.Xresources" "${CONFDIR}/spmenu/profiles/$selprofile"
set_profile set_profile
} }
remove_profile() { remove_profile() {
selprofile="$(list_profiles noopts | spmenu --lines 20 --columns 1 --prompt "Select a profile to remove" --hide-mode --hide-match-count --hide-left-arrow --hide-right-arrow --hide-image --hide-highlighting --insert | sed -e 's/\x1b\[[0-9;]*m//g')" selprofile="$(list_profiles noopts | spmenu --lines 20 --columns 1 --prompt "Select a profile to remove" --hide-mode --hide-match-count --hide-left-arrow --hide-right-arrow --hide-image --hide-highlighting --normal | sed -e 's/\x1b\[[0-9;]*m//g')"
[ ! -f "$HOME/.config/spmenu/profiles/$selprofile" ] && return [ ! -f "${CONFDIR}/spmenu/profiles/$selprofile" ] && return
rm -f "$HOME/.config/spmenu/profiles/$selprofile" "$HOME/.config/spmenu/.profile" rm -f "${CONFDIR}/spmenu/profiles/$selprofile" "${CONFDIR}/spmenu/.profile"
set_profile set_profile
} }
@ -35,7 +38,7 @@ check() {
case "$sel" in case "$sel" in
"Add") add_profile ;; "Add") add_profile ;;
"Remove") remove_profile ;; "Remove") remove_profile ;;
"Default") printf "%s/.config/spmenu/spmenurc\n" "$HOME" > "$HOME/.config/spmenu/.profile" && set_profile ;; "Default") printf "%s/.config/spmenu/spmenurc\n" "$HOME" > "${CONFDIR}/spmenu/.profile" && set_profile ;;
"") exit 0 ;; "") exit 0 ;;
*) profile="$sel" && write_profile && set_profile ;; *) profile="$sel" && write_profile && set_profile ;;
esac esac
@ -44,16 +47,16 @@ check() {
} }
write_profile() { write_profile() {
printf "%s/%s\n" "$HOME/.config/spmenu/profiles/" "$profile" > "$HOME/.config/spmenu/.profile" printf "%s/%s\n" "${CONFDIR}/spmenu/profiles/" "$profile" > "${CONFDIR}/spmenu/.profile"
[ ! -f "$HOME/.config/spmenu/profiles/$profile" ] && rm -f "$HOME/.config/spmenu/.profile" [ ! -f "${CONFDIR}/spmenu/profiles/$profile" ] && rm -f "${CONFDIR}/spmenu/.profile"
load_profile load_profile
} }
list_profiles() { list_profiles() {
profiles="$(find "$HOME/.config/spmenu/profiles" -type f)" profiles="$(find "${CONFDIR}/spmenu/profiles" -type f)"
profilec="$(find "$HOME/.config/spmenu/profiles" -type f | wc -l)" profilec="$(find "${CONFDIR}/spmenu/profiles" -type f | wc -l)"
[ "$1" != "noopts" ] && [ -f "$HOME/.config/spmenu/.profile" ] && printf "\033[1;33m%s\n" "Current profile: $(basename "$(cat "$HOME/.config/spmenu/.profile")")" | sed "s/spmenurc/Default/g" [ "$1" != "noopts" ] && [ -f "${CONFDIR}/spmenu/.profile" ] && printf "\033[1;33m%s\n" "Current profile: $(basename "$(cat "${CONFDIR}/spmenu/.profile")")" | sed "s/spmenurc/Default/g"
for i in $(seq "$profilec"); do for i in $(seq "$profilec"); do
curprofile="$(basename "$(printf "%s" "$profiles" | sed "${i}q;d")")" curprofile="$(basename "$(printf "%s" "$profiles" | sed "${i}q;d")")"
@ -69,9 +72,9 @@ list_ex_options() {
main() { main() {
command -v xrdb > /dev/null || exit 1 command -v xrdb > /dev/null || exit 1
[ ! -d "$HOME/.config/spmenu/profiles" ] && mkdir -p "$HOME/.config/spmenu/profiles" [ ! -d "${CONFDIR}/spmenu/profiles" ] && mkdir -p "${CONFDIR}/spmenu/profiles"
[ ! -f "$HOME/.config/spmenu/spmenurc" ] && [ -e "/usr/share/spmenu/example.Xresources" ] && \ [ ! -f "${CONFDIR}/spmenu/spmenurc" ] && [ -e "${DESTDIR}${PREFIX}/share/spmenu/example.Xresources" ] && \
cp "/usr/share/spmenu/example.Xresources" "$HOME/.config/spmenu/spmenurc" cp "${DESTDIR}${PREFIX}/share/spmenu/example.Xresources" "${CONFDIR}/spmenu/spmenurc"
[ "$1" = "--spmenu-load-default-profile" ] && load_profile [ "$1" = "--spmenu-load-default-profile" ] && load_profile
[ "$1" = "--spmenu-set-profile" ] && set_profile [ "$1" = "--spmenu-set-profile" ] && set_profile

View file

@ -7,6 +7,7 @@
[ -z "$HISTORY" ] && HISTORY="${XDG_CACHE_HOME:-$HOME/.cache/}/spmenu_run.hist" [ -z "$HISTORY" ] && HISTORY="${XDG_CACHE_HOME:-$HOME/.cache/}/spmenu_run.hist"
[ -z "$RUNLAUNCHER" ] && RUNLAUNCHER=spmenu [ -z "$RUNLAUNCHER" ] && RUNLAUNCHER=spmenu
[ -z "$RUNLAUNCHER_ARGS" ] && RUNLAUNCHER_ARGS="--insert --hist-file $HISTORY $*" [ -z "$RUNLAUNCHER_ARGS" ] && RUNLAUNCHER_ARGS="--insert --hist-file $HISTORY $*"
[ -z "$PREFIX" ] && PREFIX="/usr"
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,7 +31,7 @@ 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.
To set spmenu options, you pass arguments to 'spmenu_run' directly. See 'spmenu --help' for a list of valid arguments. 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. To configure spmenu, you may also copy ${DESTDIR}${PREFIX}/share/spmenu/example.Xresources to $HOME/.config/spmenu/spmenurc and edit that.
- Type in '?' to show this help screen at any time. - 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 'www', it will instead be treated as a link and spawned in a web browser (\$BROWSER)

View file

@ -1,6 +1,8 @@
#!/bin/sh #!/bin/sh
# spmenu test script # spmenu test script
PREFIX="${PREFIX:-/usr}"
# reset sequence # reset sequence
reset='\033[0m' reset='\033[0m'
@ -40,8 +42,8 @@ b14='\033[1;45m'
b15='\033[1;46m' b15='\033[1;46m'
b16='\033[1;47m' b16='\033[1;47m'
IMAGE="/usr/share/spmenu/preview.png" IMAGE="${DESTDIR}${PREFIX}/share/spmenu/preview.png"
cp $IMAGE /tmp/image.png cp "$IMAGE" /tmp/image.png
command -v maim > /dev/null && maim -uB > /tmp/image.png command -v maim > /dev/null && maim -uB > /tmp/image.png
IMAGE="/tmp/image.png" IMAGE="/tmp/image.png"