diff --git a/docs/example.Xresources b/docs/example.Xresources index 5449afb..e944e82 100644 --- a/docs/example.Xresources +++ b/docs/example.Xresources @@ -118,6 +118,7 @@ spmenu.hideimage: 0 !! Text spmenu.prompt: +spmenu.input: spmenu.normtext: Normal spmenu.instext: Insert spmenu.password: * diff --git a/libs/argv.c b/libs/argv.c index b3e77aa..0ac3344 100644 --- a/libs/argv.c +++ b/libs/argv.c @@ -352,6 +352,10 @@ readargs(int argc, char *argv[]) fstrncmp = strncasecmp; fstrstr = cistrstr; } + + // initial text + if (input) + insert(input, strlen(input)); } void diff --git a/libs/xresources.h b/libs/xresources.h index 7805af9..7f526a5 100644 --- a/libs/xresources.h +++ b/libs/xresources.h @@ -62,7 +62,6 @@ ResourcePref resources[] = { { "minwidth", INTEGER, &minwidth }, { "preselected", INTEGER, &preselected }, { "password", STRING, &password }, - { "prompt", STRING, &prompt }, { "class", STRING, &class }, { "normtext", STRING, &normtext }, { "instext", STRING, &instext }, diff --git a/options.h b/options.h index c25b1bd..7319f38 100644 --- a/options.h +++ b/options.h @@ -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 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 *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 *prompt = NULL; /* Default prompt */ +static char *input = NULL; /* Default input text */ /* Match options */ 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 */ static int indentitems = 1; /* Indent items to prompt width? (0/1) */ -static char *prompt = NULL; /* Default prompt, set to NULL (nothing) */ /* Hide options */ static int hideinput = 0; /* Hide input (0/1) */ diff --git a/scripts/spmenu_profile b/scripts/spmenu_profile index d5767c0..1445b31 100755 --- a/scripts/spmenu_profile +++ b/scripts/spmenu_profile @@ -1,32 +1,35 @@ #!/bin/sh # spmenu_profile +CONFDIR="${XDG_CONFIG_HOME:-$HOME/.config}" +PREFIX="${PREFIX:-/usr}" + 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" } set_profile() { pgrep -x spmenu && pkill -x spmenu - profiles="$(find "$HOME/.config/spmenu/profiles" -type f)" - profilec="$(find "$HOME/.config/spmenu/profiles" -type f | wc -l)" + profiles="$(find "${CONFDIR}/spmenu/profiles" -type f)" + 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 } 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')" - [ -f "/usr/share/spmenu/example.Xresources" ] && cp "/usr/share/spmenu/example.Xresources" "$HOME/.config/spmenu/profiles/$selprofile" + 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 "${DESTDIR}${PREFIX}/share/spmenu/example.Xresources" ] && cp "${DESTDIR}${PREFIX}/share/spmenu/example.Xresources" "${CONFDIR}/spmenu/profiles/$selprofile" set_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')" - [ ! -f "$HOME/.config/spmenu/profiles/$selprofile" ] && return - rm -f "$HOME/.config/spmenu/profiles/$selprofile" "$HOME/.config/spmenu/.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 --normal | sed -e 's/\x1b\[[0-9;]*m//g')" + [ ! -f "${CONFDIR}/spmenu/profiles/$selprofile" ] && return + rm -f "${CONFDIR}/spmenu/profiles/$selprofile" "${CONFDIR}/spmenu/.profile" set_profile } @@ -35,7 +38,7 @@ check() { case "$sel" in "Add") add_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 ;; *) profile="$sel" && write_profile && set_profile ;; esac @@ -44,16 +47,16 @@ check() { } write_profile() { - printf "%s/%s\n" "$HOME/.config/spmenu/profiles/" "$profile" > "$HOME/.config/spmenu/.profile" - [ ! -f "$HOME/.config/spmenu/profiles/$profile" ] && rm -f "$HOME/.config/spmenu/.profile" + printf "%s/%s\n" "${CONFDIR}/spmenu/profiles/" "$profile" > "${CONFDIR}/spmenu/.profile" + [ ! -f "${CONFDIR}/spmenu/profiles/$profile" ] && rm -f "${CONFDIR}/spmenu/.profile" load_profile } list_profiles() { - profiles="$(find "$HOME/.config/spmenu/profiles" -type f)" - profilec="$(find "$HOME/.config/spmenu/profiles" -type f | wc -l)" + profiles="$(find "${CONFDIR}/spmenu/profiles" -type f)" + 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 curprofile="$(basename "$(printf "%s" "$profiles" | sed "${i}q;d")")" @@ -69,9 +72,9 @@ list_ex_options() { main() { command -v xrdb > /dev/null || exit 1 - [ ! -d "$HOME/.config/spmenu/profiles" ] && mkdir -p "$HOME/.config/spmenu/profiles" - [ ! -f "$HOME/.config/spmenu/spmenurc" ] && [ -e "/usr/share/spmenu/example.Xresources" ] && \ - cp "/usr/share/spmenu/example.Xresources" "$HOME/.config/spmenu/spmenurc" + [ ! -d "${CONFDIR}/spmenu/profiles" ] && mkdir -p "${CONFDIR}/spmenu/profiles" + [ ! -f "${CONFDIR}/spmenu/spmenurc" ] && [ -e "${DESTDIR}${PREFIX}/share/spmenu/example.Xresources" ] && \ + cp "${DESTDIR}${PREFIX}/share/spmenu/example.Xresources" "${CONFDIR}/spmenu/spmenurc" [ "$1" = "--spmenu-load-default-profile" ] && load_profile [ "$1" = "--spmenu-set-profile" ] && set_profile diff --git a/scripts/spmenu_run b/scripts/spmenu_run index fb53e8d..135a2f5 100755 --- a/scripts/spmenu_run +++ b/scripts/spmenu_run @@ -7,6 +7,7 @@ [ -z "$HISTORY" ] && HISTORY="${XDG_CACHE_HOME:-$HOME/.cache/}/spmenu_run.hist" [ -z "$RUNLAUNCHER" ] && RUNLAUNCHER=spmenu [ -z "$RUNLAUNCHER_ARGS" ] && RUNLAUNCHER_ARGS="--insert --hist-file $HISTORY $*" +[ -z "$PREFIX" ] && PREFIX="/usr" check() { [ ! -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 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. +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. - If the entry selected starts with 'www', it will instead be treated as a link and spawned in a web browser (\$BROWSER) diff --git a/scripts/spmenu_test b/scripts/spmenu_test index 9bbadb1..e456877 100755 --- a/scripts/spmenu_test +++ b/scripts/spmenu_test @@ -1,6 +1,8 @@ #!/bin/sh # spmenu test script +PREFIX="${PREFIX:-/usr}" + # reset sequence reset='\033[0m' @@ -40,8 +42,8 @@ b14='\033[1;45m' b15='\033[1;46m' b16='\033[1;47m' -IMAGE="/usr/share/spmenu/preview.png" -cp $IMAGE /tmp/image.png +IMAGE="${DESTDIR}${PREFIX}/share/spmenu/preview.png" +cp "$IMAGE" /tmp/image.png command -v maim > /dev/null && maim -uB > /tmp/image.png IMAGE="/tmp/image.png"