diff --git a/README.md b/README.md index 656447d..936f6ea 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,13 @@ Note: Pass the environment variable `PROVIDERS_FILE` to read custom providers fr The path in `PROVIDERS_FILE` can either be absolute or relative to `${HOME}/.config/sway-launcher-desktop/`. +## Launcher history file + +By default, `sway-launcher-desktop` stores a history of commands to make frequently used entries available more quickly. +This history is stored in a file in `~/.cache/` (or `$XDG_CACHE_HOME`, if that environment variable is set). +You may change the file path and name by setting the environment variable `HIST_FILE` to the desired path. +Setting the variable to an empty value disables the history feature entirely. + ## Troubleshooting Debug information is directed to file descriptor `3` and can be dumped using `./sway-launcher-desktop.sh 3>> ~/sway-launcher-desktop.log` diff --git a/sway-launcher-desktop.sh b/sway-launcher-desktop.sh index 5ea97b2..a8ee3dc 100755 --- a/sway-launcher-desktop.sh +++ b/sway-launcher-desktop.sh @@ -41,15 +41,21 @@ if [ -f "${PROVIDERS_FILE}" ]; then print "PROVIDERS[\x27" key "\x27]=\x27" providers[key]["list_cmd"] "\034" providers[key]["preview_cmd"] "\034" providers[key]["launch_cmd"] "\x27\n" } }' "${PROVIDERS_FILE}")" - HIST_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/${0##*/}-${PROVIDERS_FILE##*/}-history.txt" + if [[ ! -v HIST_FILE ]]; then + HIST_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/${0##*/}-${PROVIDERS_FILE##*/}-history.txt" + fi else PROVIDERS['desktop']="${0} list-entries${DEL}${0} describe-desktop \"{1}\"${DEL}${0} run-desktop '{1}' {2}" PROVIDERS['command']="${0} list-commands${DEL}${0} describe-command \"{1}\"${DEL}${TERMINAL_COMMAND} {1}" - HIST_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/${0##*/}-history.txt" + if [[ ! -v HIST_FILE ]]; then + HIST_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/${0##*/}-history.txt" + fi fi -mkdir -p "${HIST_FILE%/*}" && touch "$HIST_FILE" -readarray HIST_LINES <"$HIST_FILE" +if [[ -n "${HIST_FILE}" ]]; then + mkdir -p "${HIST_FILE%/*}" && touch "$HIST_FILE" + readarray HIST_LINES <"$HIST_FILE" +fi function describe() { # shellcheck disable=SC2086 @@ -258,20 +264,22 @@ COMMAND_STR=$( [ -z "$COMMAND_STR" ] && exit 1 -# update history -for i in "${!HIST_LINES[@]}"; do - if [[ "${HIST_LINES[i]}" == *" $COMMAND_STR"$'\n' ]]; then - HIST_COUNT=${HIST_LINES[i]%% *} - HIST_LINES[$i]="$((HIST_COUNT + 1)) $COMMAND_STR"$'\n' - match=1 - break +if [[ -n "${HIST_FILE}" ]]; then + # update history + for i in "${!HIST_LINES[@]}"; do + if [[ "${HIST_LINES[i]}" == *" $COMMAND_STR"$'\n' ]]; then + HIST_COUNT=${HIST_LINES[i]%% *} + HIST_LINES[$i]="$((HIST_COUNT + 1)) $COMMAND_STR"$'\n' + match=1 + break + fi + done + if ! ((match)); then + HIST_LINES+=("1 $COMMAND_STR"$'\n') fi -done -if ! ((match)); then - HIST_LINES+=("1 $COMMAND_STR"$'\n') -fi -printf '%s' "${HIST_LINES[@]}" | sort -nr >"$HIST_FILE" + printf '%s' "${HIST_LINES[@]}" | sort -nr >"$HIST_FILE" +fi # shellcheck disable=SC2086 readarray -d $'\034' -t PARAMS <<<${COMMAND_STR}