Some config file code cleanup

This commit is contained in:
speedie 2023-07-04 16:59:51 +02:00
parent 69d5ae6950
commit d750f3a78a

View file

@ -15,7 +15,7 @@ PLAYER="${PLAYER:-mpv}"
GENERIC="${GENERIC:-$TERMINAL -e $EDITOR}" GENERIC="${GENERIC:-$TERMINAL -e $EDITOR}"
WEB_GREP="${WEB_GREP:-http:|https:|www[.]}" WEB_GREP="${WEB_GREP:-http:|https:|www[.]}"
MAGNET_GREP="${MAGNET_GREP:-magnet:?}" MAGNET_GREP="${MAGNET_GREP:-magnet:?}"
HISTORY="${HISTORY:-${XDG_CACHE_HOME:-$HOME/.cache/}/spmenu_run.hist}" HISTORY="${HISTORY:-${XDG_CACHE_HOME:-$HOME/.cache/}/spmenu/spmenu_run.hist}"
RUNLAUNCHER="${RUNLAUNCHER:-spmenu}" RUNLAUNCHER="${RUNLAUNCHER:-spmenu}"
PREFIX="${PREFIX:-/usr}" PREFIX="${PREFIX:-/usr}"
DESTDIR="${DESTDIR:-}" DESTDIR="${DESTDIR:-}"
@ -36,21 +36,27 @@ DESCRIPTION_COLOR="${DESCRIPTION_COLOR:-#999888}"
DMENU_COMPAT="${DMENU_COMPAT:-false}" DMENU_COMPAT="${DMENU_COMPAT:-false}"
AUTOREFRESH="${AUTOREFRESH:-true}" AUTOREFRESH="${AUTOREFRESH:-true}"
MULTISELECT="${MULTISELECT:-true}" MULTISELECT="${MULTISELECT:-true}"
BOOKMARK_FILE="${BOOKMARK_FILE:-${XDG_CACHE_HOME:-$HOME/.cache/}/spmenu_run.bookmarks}" BOOKMARK_FILE="${BOOKMARK_FILE:-${XDG_CACHE_HOME:-$HOME/.cache/}/spmenu/spmenu_run.bookmarks}"
BOOKMARK_PROMPT="${BOOKMARK_PROMPT:-Bookmarks}" BOOKMARK_PROMPT="${BOOKMARK_PROMPT:-Bookmarks}"
PRINT_LOGS_STDERR="${PRINT_LOGS_STDERR:-true}" PRINT_LOGS_STDERR="${PRINT_LOGS_STDERR:-true}"
RUNLAUNCHER_RUN_ARGS=""
RUNLAUNCHER_BM_ARGS=""
RUNLAUNCHER_DESKTOP_ARGS=""
RUNLAUNCHER_FM_ARGS="--lines 40 --columns 2"
RUNLAUNCHER_HELP_ARGS=""
DESKTOP_DIR="${DESKTOP_DIR:-${DESTDIR}${PREFIX}/share/applications ${HOME}/.local/share/applications}" DESKTOP_DIR="${DESKTOP_DIR:-${DESTDIR}${PREFIX}/share/applications ${HOME}/.local/share/applications}"
ICON_DIR="${ICON_DIR:-${DESTDIR}${PREFIX}/share/icons/hicolor ${HOME}/.local/share/icons/hicolor ${DESTDIR}${PREFIX}/share/pixmaps}" ICON_DIR="${ICON_DIR:-${DESTDIR}${PREFIX}/share/icons/hicolor ${HOME}/.local/share/icons/hicolor ${DESTDIR}${PREFIX}/share/pixmaps}"
IMAGE="${IMAGE:-true}" IMAGE="${IMAGE:-true}"
LOGFILE="${LOGFILE:-/tmp/spmenu_run.log}" LOGFILE="${LOGFILE:-/tmp/spmenu_run.log}"
TITLEFILE="${TITLEFILE:-${XDG_CACHE_HOME:-$HOME/.cache}/.title}" TITLEFILE="${TITLEFILE:-${XDG_CACHE_HOME:-$HOME/.cache}/spmenu/.desktop_title}"
EXECFILE="${EXECFILE:-${XDG_CACHE_HOME:-$HOME/.cache}/.exec}" EXECFILE="${EXECFILE:-${XDG_CACHE_HOME:-$HOME/.cache}/spmenu/.desktop_exec}"
ICONFILE="${ICONFILE:-${XDG_CACHE_HOME:-$HOME/.cache}/.icon}" ICONFILE="${ICONFILE:-${XDG_CACHE_HOME:-$HOME/.cache}/spmenu/.desktop_icon}"
DESCFILE="${DESCFILE:-${XDG_CACHE_HOME:-$HOME/.cache}/.desc}" DESCFILE="${DESCFILE:-${XDG_CACHE_HOME:-$HOME/.cache}/spmenu/.desktop_desc}"
FILEFILE="${FILEFILE:-${XDG_CACHE_HOME:-$HOME/.cache}/.file}" FILEFILE="${FILEFILE:-${XDG_CACHE_HOME:-$HOME/.cache}/spmenu/.desktop_file}"
TERMFILE="${TERMFILE:-${XDG_CACHE_HOME:-$HOME/.cache}/.term}" TERMFILE="${TERMFILE:-${XDG_CACHE_HOME:-$HOME/.cache}/spmenu/.desktop_term}"
# arrays containing entries # arrays containing entries
declare -a it_title declare -a it_title
@ -75,18 +81,21 @@ declare -a uniq_args
declare -a desktopdir declare -a desktopdir
declare -a icondir declare -a icondir
fail_mac() { prepare_dirs() {
[ -f "/usr/local/share/spmenu/allowusageonmac" ] && return mkdir -p \
cat << EOF "$(dirname "$TITLEFILE")" \
spmenu_run does not support macOS due to the outdated Bash version. "$(dirname "$EXECFILE")" \
See https://spmenu.speedie.site/Using+spmenu+on+macOS for more information. "$(dirname "$ICONFILE")" \
"$(dirname "$DESCFILE")" \
If you wish to ignore this warning anyway, touch /usr/local/share/spmenu/allowusageonmac. "$(dirname "$FILEFILE")" \
EOF "$(dirname "$TERMFILE")" \
exit 1 "$(dirname "$LOGFILE")" \
"$(dirname "$HISTORY")" \
"$(dirname "$BOOKMARK_FILE")"
} }
check() { check() {
prepare_dirs
[ ! -d "$CONFDIR/spmenu/run" ] && mkdir -p "$CONFDIR/spmenu/run" [ ! -d "$CONFDIR/spmenu/run" ] && mkdir -p "$CONFDIR/spmenu/run"
if [ ! -f "$CONFDIR/spmenu/run/.first_run" ]; then if [ ! -f "$CONFDIR/spmenu/run/.first_run" ]; then
print_help print_help
@ -235,54 +244,55 @@ PDF_READER="\${PDF_READER:-zathura}" # PDF reader, for file management
EDITOR="\${EDITOR:-nvim}" # Editor, used to open documents EDITOR="\${EDITOR:-nvim}" # Editor, used to open documents
PLAYER="\${PLAYER:-mpv}" # Player, used to play audio/video PLAYER="\${PLAYER:-mpv}" # Player, used to play audio/video
GENERIC="\${GENERIC:-\$TERMINAL -e \$EDITOR}" # Generic, used to open unknown files GENERIC="\${GENERIC:-\$TERMINAL -e \$EDITOR}" # Generic, used to open unknown files
WEB_GREP="http:|https:|www[.]" # Needs to be in grep -E syntax WEB_GREP="$WEB_GREP" # Needs to be in grep -E syntax
MAGNET_GREP="magnet:?" # Needs to be in grep -E syntax MAGNET_GREP="$MAGNET_GREP" # Needs to be in grep -E syntax
HISTORY="\${XDG_CACHE_HOME:-\$HOME/.cache/}/spmenu_run.hist" # History file, spmenu (meaning your user) must have permission to read and write to it. HISTORY="\${XDG_CACHE_HOME:-\$HOME/.cache/}/spmenu/spmenu_run.hist" # History file, spmenu (meaning your user) must have permission to read and write to it.
BOOKMARK_FILE="\${BOOKMARK_FILE:-\${XDG_CACHE_HOME:-\$HOME/.cache/}/spmenu_run.bookmarks}" # Bookmark file, spmenu_run must have permission to read and write to it. BOOKMARK_FILE="\${BOOKMARK_FILE:-\${XDG_CACHE_HOME:-\$HOME/.cache/}/spmenu/spmenu_run.bookmarks}" # Bookmark file, spmenu_run must have permission to read and write to it.
BOOKMARK_PROMPT="Bookmarks" # Bookmark prompt (-p) BOOKMARK_PROMPT="$BOOKMARK_PROMPT" # Bookmark prompt (-p)
# Run launcher argument options # Run launcher argument options
RUNLAUNCHER="\${RUNLAUNCHER:-spmenu}" # Run launcher to use RUNLAUNCHER="\${RUNLAUNCHER:-spmenu}" # Run launcher to use
RUNLAUNCHER_RUN_ARGS="" # Extra arguments passed to \$RUNLAUNCHER when using the run launcher RUNLAUNCHER_RUN_ARGS="$RUNLAUNCHER_RUN_ARGS" # Extra arguments passed to \$RUNLAUNCHER when using the run launcher
RUNLAUNCHER_BM_ARGS="" # Extra arguments passed to \$RUNLAUNCHER when using the bookmark menu RUNLAUNCHER_BM_ARGS="$RUNLAUNCHER_BM_ARGS" # Extra arguments passed to \$RUNLAUNCHER when using the bookmark menu
RUNLAUNCHER_DESKTOP_ARGS="" # Extra rguments passed to \$RUNLAUNCHER when using the .desktop launcher RUNLAUNCHER_DESKTOP_ARGS="$RUNLAUNCHER_DESKTOP_ARGS" # Extra rguments passed to \$RUNLAUNCHER when using the .desktop launcher
RUNLAUNCHER_FM_ARGS="--lines 40 --columns 2" # Extra arguments passed to \$RUNLAUNCHER when using the file manager RUNLAUNCHER_FM_ARGS="${RUNLAUCNHER_FM_ARGS}" # Extra arguments passed to \$RUNLAUNCHER when using the file manager
RUNLAUNCHER_HELP_ARGS="" # Extra arguments passed to \$RUNLAUNCHER when using the help RUNLAUNCHER_HELP_ARGS="${RUNLAUNCHER_HELP_ARGS}" # Extra arguments passed to \$RUNLAUNCHER when using the help
DMENU_COMPAT="false" # Enable dmenu compatibility (true/false) DMENU_COMPAT="$DMENU_COMPAT" # Enable dmenu compatibility (true/false)
# Sorting # Sorting
SORT_BY_NUMBER="true" # Sort by numbers SORT_BY_NUMBER="$SORT_BY_NUMBER" # Sort by numbers
SORT_IN_REVERSE="true" # Sort in reverse SORT_IN_REVERSE="$SORT_IN_REVERSE" # Sort in reverse
SORT_BY_RECENT="false" # Sort by recent SORT_BY_RECENT="$SORT_BY_RECENT" # Sort by recent
SORT_ARGS="" # Extra arguments passed to the sort command. SORT_ARGS="$SORT_ARGS" # Extra arguments passed to the sort command.
# Keywords # Keywords
HIDDEN_KEYWORDS="spmenu" # Keywords that will be ignored, needs to be in grep -vE syntax. HIDDEN_KEYWORDS="$HIDDEN_KEYWORDS" # 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" # Keywords that will be matched, needs to be in grep -E syntax.
# Miscellanious # Miscellanious
STDOUT="false" # Print to stdout and exit (true/false) STDOUT="$STDOUT" # Print to stdout and exit (true/false)
DISPLAY_DUPLICATES="false" # Display duplicates or not DISPLAY_DUPLICATES="$DISPLAY_DUPLICATES" # Display duplicates or not
DEFAULT_FEATURE="run" # spmenu_run default feature (run/fm/desktop/help) DEFAULT_FEATURE="$DEFAULT_FEATURE" # spmenu_run default feature (run/fm/desktop/help)
HELP_COLOR="#FFFF00" HELP_COLOR="$HELP_COLOR"
# .desktop entry options # .desktop entry options
DESKTOP_DIR="\${DESTDIR}\${PREFIX}/share/applications \${HOME}/.local/share/applications" # Directories for .desktop entries DESKTOP_DIR="$DESKTOP_DIR" # Directories for .desktop entries
ICON_DIR="\${DESTDIR}\${PREFIX}/share/icons/hicolor \${HOME}/.local/share/icons/hicolor \${DESTDIR}\${PREFIX}/share/pixmaps" # Directories for icons defined in the entries ICON_DIR="$ICON_DIR" # Directories for icons defined in the entries
HIDDEN_ENTRY_KEYWORDS="\$HIDDEN_KEYWORDS" # Keywords that will be ignored, needs to be in grep -vE syntax. HIDDEN_ENTRY_KEYWORDS="\$HIDDEN_KEYWORDS" # Keywords that will be ignored, needs to be in grep -vE syntax.
ENTRY_KEYWORDS="\$KEYWORDS" # Keywords that will be matched, needs to be in grep -E syntax. ENTRY_KEYWORDS="\$KEYWORDS" # Keywords that will be matched, needs to be in grep -E syntax.
AUTOREFRESH="true" # Refresh (clear) cache if there are more entries available than cached. May cause cache to be cleared every time in some cases. (true/false) AUTOREFRESH="$AUTOREFRESH" # Refresh (clear) cache if there are more entries available than cached. May cause cache to be cleared every time in some cases. (true/false)
MULTISELECT="true" # Allow handling multiple items, if set to false only the first line/selected item will be used. MULTISELECT="$MULTISELECT" # Allow handling multiple items, if set to false only the first line/selected item will be used.
IMAGE="true" # Display images (true/false) IMAGE="$IMAGE" # Display images (true/false)
DISPLAY_DESCRIPTION="true" # Display description (true/false)" DISPLAY_DESCRIPTION="$DISPLAY_DESCRIPTION" # Display description (true/false)"
DESCRIPTION_COLOR="#999888" # Description text color DESCRIPTION_COLOR="$DESCRIPTION_COLOR" # Description text color
LOGFILE="/tmp/spmenu_run.log" # Log file LOGFILE="$LOGFILE" # Log file
PRINT_LOGS_STDERR="true" # Print information (such as logs) to stderr (true/false) PRINT_LOGS_STDERR="$PRINT_LOGS_STDERR" # Print information (such as logs) to stderr (true/false)
TITLEFILE="\${TITLEFILE:-\${XDG_CACHE_HOME:-\$HOME/.cache}/.title}" # File containing the different titles to display. TITLEFILE="\${XDG_CACHE_HOME:-\$HOME/.cache}/spmenu/.desktop_title" # File containing the different titles to display.
DESCFILE="\${DESCFILE:-\${XDG_CACHE_HOME:-\$HOME/.cache}/.desc}" # File containing the description to display DESCFILE="\${XDG_CACHE_HOME:-\$HOME/.cache}/spmenu/.desktop_desc" # File containing the description to display
EXECFILE="\${EXECFILE:-\${XDG_CACHE_HOME:-\$HOME/.cache}/.exec}" # File containing the different executables to run. EXECFILE="\${XDG_CACHE_HOME:-\$HOME/.cache}/spmenu/.desktop_exec" # File containing the different executables to run.
ICONFILE="\${ICONFILE:-\${XDG_CACHE_HOME:-\$HOME/.cache}/.icon}" # File containing the paths to the icons to display. ICONFILE="\${XDG_CACHE_HOME:-\$HOME/.cache}/spmenu/.desktop_icon" # File containing the paths to the icons to display.
FILEFILE="\${FILEFILE:-\${XDG_CACHE_HOME:-\$HOME/.cache}/.file}" # File containing the path to the .desktop entries. FILEFILE="\${XDG_CACHE_HOME:-\$HOME/.cache}/spmenu/.desktop_file" # File containing the path to the .desktop entries.
TERMFILE="\${XDG_CACHE_HOME:-\$HOME/.cache}/spmenu/.desktop_term" # File containing the path to the terminal data
# File management # File management
DEFAULT_DIRECTORY="\$(pwd)" # Directory to start -fm if none is specified. DEFAULT_DIRECTORY="\$(pwd)" # Directory to start -fm if none is specified.
@ -730,7 +740,6 @@ clear_cache() {
} }
main() { main() {
[ -d "/System/Library/Extensions" ] && fail_mac
rm -f "$LOGFILE" rm -f "$LOGFILE"
print_config print_config
read_args "$@" read_args "$@"