From 9a006883b8174c11ffce08a8bcf1dcbaae3a7121 Mon Sep 17 00:00:00 2001 From: fatalerrors Date: Wed, 15 Apr 2026 13:38:08 +0200 Subject: [PATCH] make defaults configurable --- profile.conf | 174 +++++++++++++++++++++++++++++++++++++++-- profile.d/compress.sh | 17 +++- profile.d/filefct.sh | 10 ++- profile.d/fun.sh | 4 +- profile.d/info.sh | 7 +- profile.d/net.sh | 43 +++++++--- profile.d/packages.sh | 4 +- profile.d/processes.sh | 6 +- profile.d/pwd.sh | 15 ++-- profile.d/rain.sh | 17 ++-- profile.d/ssh.sh | 12 ++- 11 files changed, 269 insertions(+), 40 deletions(-) diff --git a/profile.conf b/profile.conf index de3d827..4de128f 100755 --- a/profile.conf +++ b/profile.conf @@ -12,26 +12,71 @@ PAGER=less TERM=xterm-256color [compress] -# Section used by compress.sh +# Section used by compress.sh (taz and utaz functions). + +# taz: Default archive format when -f/--format is not specified. +# Supported values: lz (default), xz, bz2, gz, lzo, tar +#TAZ_DEFAULT_FORMAT=lz + +# taz: Default number of compression threads when -p/--parallel is not specified. +# Set to the number of CPU cores to use parallel compression where supported. +#TAZ_DEFAULT_THREADS=1 + +# taz: Default compression level when none is given (1=fast/big .. 9=slow/small). +#TAZ_DEFAULT_LEVEL=6 + +# utaz: Delete source archives after successful extraction (0=no, 1=yes). +#UTAZ_DEFAULT_DELETE=0 + +# utaz: Default directory creation mode when neither --create-dir nor --no-dir is given. +# Supported values: +# auto (default) — create a subdirectory only when the archive contains +# multiple top-level entries or a bare file +# always — always extract into a new subdirectory +# never — always flatten extraction into the current directory +#UTAZ_DEFAULT_DIR_MODE=auto [debug] -# Section used by debug.sh +# Section used by debug.sh (nothing yet) [disp] # Section used by disp.sh + # Set to any value to disable colors in internal profile output (not controling binary output) # NO_COLOR=1 [filefct] # Section used by filefct.sh +# expandlist: Default output separator between items (default: space). +# Use \n for newline, or any other character/string. +#EXPANDLIST_DEFAULT_SEPARATOR=" " + +# clean: Enable recursive mode by default (0=no, 1=yes). +#CLEAN_DEFAULT_RECURSIVE=0 + +# rmspc: Default character used to replace spaces in filenames (default: underscore). +# Set to empty to concatenate words without separator (equivalent to --subst-char with no value). +#RMSPC_DEFAULT_CHAR=_ + +# findbig: Default number of results to return (default: 10). +#FINDBIG_DEFAULT_LIMIT=10 + [fun] -# Section used by fun.sh +# Section used by fun.sh (busy function). + +# busy: Default hex pattern to search for in /dev/urandom hexdump (default: "ca fe"). +#BUSY_DEFAULT_PATTERN=ca fe + +# busy: Default delay between matched lines in milliseconds (default: 0 = no delay). +#BUSY_DEFAULT_DELAY=0 [info] # Section used by info.sh -# Default city for weather forcast and local news -DEFAULT_CITY="Toulouse" + +# meteo: Default city used when no city argument is given. +# Unset or empty disables the fallback and requires an explicit city argument. +METEO_DEFAULT_CITY="Toulouse" [lang] # Section used by lang.sh @@ -40,23 +85,136 @@ DEFAULT_CITY="Toulouse" SET_LOCALE="fr:fr_FR.UTF-8,us:en_US.UTF-8" [net] -# Section used by net.sh +# Section used by net.sh (dwl, myextip functions). + +# dwl: Force a specific download tool instead of auto-detecting (curl → wget → fetch). +# Supported values: curl, wget, fetch. Unset uses auto-detection (default). +#DWL_PREFERRED_TOOL=curl + +# myextip: API endpoint URL used to retrieve external IP information. +# Default: https://ip-api.com/json/ +# Compatible alternatives: https://ipinfo.io/json, https://ip-api.com/json/ +#MYEXTIP_DEFAULT_URL=https://ip-api.com/json/ [packages] # Section used by packages.sh +# pkgs: Enable case-insensitive search by default (1=yes, 0=no; default: 0). +#PKGS_DEFAULT_IGNORE_CASE=0 + +[processes] +# Section used by processes.sh + +# ppu: Output columns passed to ps -o when listing processes for a user. +# Comma-separated list of ps field names. Default: pid,user,%cpu,%mem,start,time,command +#PPU_DEFAULT_FORMAT=pid,user,%cpu,%mem,start,time,command + +# ku: Signal sent to processes when killing a user's session (default: TERM). +# Use signal names without the SIG prefix (e.g. TERM, KILL, HUP). +#KU_DEFAULT_SIGNAL=TERM + [prompt] # Section used by prompt.sh +# Name of the theme to load, or an explicit path to a .theme file. +# Bare names are resolved as $PROMPT_THEME_DIR/.theme. +# When unset, no theme is loaded and the hardcoded fallback colours are used. +#PROMPT_THEME=default + +# Directory that contains .theme files. Defaults to profile.d/themes/ inside +# the profile installation directory. +#PROMPT_THEME_DIR=/path/to/themes + +# Individual colour overrides. These always win over the loaded theme. +# Values must be valid ANSI escape sequences as exported by disp.sh, e.g.: +# \e[0;34m (Blue) \e[42m (On_Green) \e[1;32m (BGreen) +# All keys listed below correspond to variables exported by disp.sh. + +# Clock segment +#PROMPT_COLOR_TIME_FG=$Blue +#PROMPT_COLOR_TIME_BG=$On_IBlack + +# Main bar background (success and info) +#PROMPT_COLOR_BAR_BG=$On_Blue + +# Exit-code segment — success state +#PROMPT_COLOR_OK_FG=$White +#PROMPT_COLOR_OK_MARK=$Green + +# Exit-code segment — failure state +#PROMPT_COLOR_ERR_BG=$On_Red +#PROMPT_COLOR_ERR_FG=$White +#PROMPT_COLOR_ERR_MARK=$BYellow + +# User/host colours +#PROMPT_COLOR_ROOT_FG=$Red +#PROMPT_COLOR_USER_FG=$Green + +# Working directory +#PROMPT_COLOR_DIR_FG=$ICyan + [pwd] -# Section used by pwd.sh +# Section used by pwd.sh (genpwd and pwdscore functions). + +# genpwd: Default password length (default: 16). +#GENPWD_DEFAULT_LENGTH=16 + +# genpwd: Maximum occurrences of any single character (default: 2). +#GENPWD_DEFAULT_OCCURS=2 + +# genpwd: Number of passwords generated when no count argument is given (default: 1). +#GENPWD_DEFAULT_COUNT=1 + +# genpwd: Include symbols in the character pool (1=yes, 0=no; default: 1). +#GENPWD_DEFAULT_SYMBOLS=1 + +# genpwd: Include uppercase letters in the character pool (1=yes, 0=no; default: 1). +#GENPWD_DEFAULT_UPPERCASE=1 + +# genpwd: Include lowercase letters in the character pool (1=yes, 0=no; default: 1). +#GENPWD_DEFAULT_LOWERCASE=1 + +# genpwd: Include digits in the character pool (1=yes, 0=no; default: 1). +#GENPWD_DEFAULT_NUMBERS=1 + +# pwdscore: Show verbose breakdown by default (1=yes, 0=no; default: 0). +#PWDSCORE_DEFAULT_VERBOSE=0 [rain] -# Section used by rain.sh +# Section used by rain.sh (rain and matrix functions). + +# rain: Default speed value, using the /100 scale (5 => 0.050s, 10 => 0.100s). +# Values < 1 are interpreted as raw seconds. +#RAIN_DEFAULT_SPEED=5 + +# rain: Default color theme. +# Supported values: white (default), green, blue, red, yellow, cyan +#RAIN_DEFAULT_COLOR=white + +# matrix: Default speed value, using the /100 scale (3.5 => 0.035s). +#MATRIX_DEFAULT_SPEED=3.5 + +# matrix: Default color theme. +# Supported values: green (default), blue, red, yellow, cyan, white +#MATRIX_DEFAULT_COLOR=green + +# matrix: Default character set. +# Supported values: binary (default), kana, ascii +MATRIX_DEFAULT_CHARSET=kana [ssh] # Section used by ssh.sh +# ssr: Default SSH options prepended to every ssr invocation. +# Options are word-split, so space-separated flags are supported. +# The default behaviour without this key is equivalent to: SSH_DEFAULT_OPT=-Y +# Set to an empty value to pass no default options. +# Examples: +# SSH_DEFAULT_OPT=-Y # X11 forwarding (original default) +# SSH_DEFAULT_OPT=-Y -o StrictHostKeyChecking=accept-new +# SSH_DEFAULT_OPT= # no default options +#SSH_DEFAULT_OPT=-Y + [updates] # Section used by updates.sh diff --git a/profile.d/compress.sh b/profile.d/compress.sh index fa5b1b1..23fef55 100644 --- a/profile.d/compress.sh +++ b/profile.d/compress.sh @@ -204,6 +204,15 @@ utaz() local FILES=("$@") [[ ${#FILES[@]} -eq 0 ]] && FILES=(".") + # Apply defaults from [compress] configuration if not overridden by flags + [[ -z ${willrm+x} ]] && [[ ${UTAZ_DEFAULT_DELETE:-0} -eq 1 ]] && willrm=1 + if [[ -z ${createdir+x} && -z ${nodir+x} ]]; then + case "${UTAZ_DEFAULT_DIR_MODE:-auto}" in + always) createdir=1 ;; + never) nodir=1 ;; + esac + fi + [[ -n ${createdir} && -n ${nodir} ]] && \ disp E "The --create-dir and --no-dir options are mutually exclusive." @@ -565,9 +574,9 @@ taz() local FILES=("$@") [[ ${#FILES[@]} -eq 0 ]] && FILES=(".") - [[ ! $compform ]] && compform=lz # safe and efficient (unless data are already compressed) - [[ ! $nproc ]] && nproc=1 - [[ ! $complevel ]] && complevel=6 + [[ ! $compform ]] && compform=${TAZ_DEFAULT_FORMAT:-lz} + [[ ! $nproc ]] && nproc=${TAZ_DEFAULT_THREADS:-1} + [[ ! $complevel ]] && complevel=${TAZ_DEFAULT_LEVEL:-6} [[ $verbose -gt 1 && $quiet -gt 1 ]] && disp E "The --verbose and --quiet options can't be used together." @@ -619,4 +628,6 @@ export -f taz # ------------------------------------------------------------------------------ +load_conf "compress" + # EOF diff --git a/profile.d/filefct.sh b/profile.d/filefct.sh index e4dead5..6d571c0 100644 --- a/profile.d/filefct.sh +++ b/profile.d/filefct.sh @@ -39,7 +39,7 @@ # Usage: expandlist [options] expandlist() { - local separator=" " + local separator="${EXPANDLIST_DEFAULT_SEPARATOR:- }" local PARSED PARSED=$(getopt -o hs:n --long help,separator:,newline -n 'expandlist' -- "$@") @@ -122,7 +122,7 @@ export -f expandlist # -s, --shell: do nothing and display what will be executed clean() { - local recursive=0 force=0 outshell=0 + local recursive=${CLEAN_DEFAULT_RECURSIVE:-0} force=0 outshell=0 # Define short and long options local PARSED @@ -236,7 +236,7 @@ export -f mcd rmspc() { local recurs=0 verb=0 shell=0 - local substchar="_" substchar_set=0 + local substchar="${RMSPC_DEFAULT_CHAR:-_}" substchar_set=0 local mvopt=() local PARSED @@ -574,7 +574,7 @@ export -f file_stats # -l : limit : number of files to return (default is 10) findbig() { - local details=0 limit=10 one_fs=0 + local details=0 limit=${FINDBIG_DEFAULT_LIMIT:-10} one_fs=0 local PARSED PARSED=$(getopt -o hdl:x --long help,details,limit:,one-fs -n 'findbig' -- "$@") @@ -792,4 +792,6 @@ export -f finddead # ------------------------------------------------------------------------------ +load_conf "filefct" + # EOF diff --git a/profile.d/fun.sh b/profile.d/fun.sh index 33c75c8..e547ff8 100644 --- a/profile.d/fun.sh +++ b/profile.d/fun.sh @@ -42,7 +42,7 @@ # pattern : the string to search for in the hexdump output (default is "ca fe") busy() { - local pattern="ca fe" delay_ms=0 + local pattern="${BUSY_DEFAULT_PATTERN:-ca fe}" delay_ms="${BUSY_DEFAULT_DELAY:-0}" local PARSED # Short: h, p:, d: @@ -109,4 +109,6 @@ busy() # ------------------------------------------------------------------------------ +load_conf "fun" + # EOF diff --git a/profile.d/info.sh b/profile.d/info.sh index cf9768a..c610475 100644 --- a/profile.d/info.sh +++ b/profile.d/info.sh @@ -108,7 +108,12 @@ meteo() local cities=("$@") local city="" encoded="" - [[ $# -eq 0 ]] && cities=("$DEFAULT_CITY") + [[ $# -eq 0 ]] && cities=("${METEO_DEFAULT_CITY:-}") + + if [[ ${#cities[@]} -eq 0 || -z "${cities[0]}" ]]; then + disp E "No city given and METEO_DEFAULT_CITY is not set. Use 'meteo '." + return 1 + fi for city in "${cities[@]}"; do encoded=$(urlencode "$city") diff --git a/profile.d/net.sh b/profile.d/net.sh index 6d41434..5efb5db 100644 --- a/profile.d/net.sh +++ b/profile.d/net.sh @@ -67,16 +67,38 @@ dwl() local url="$1" local output="$2" - if command -v curl >/dev/null 2>&1; then - [ -z "$output" ] && curl -sL "$url" || curl -sL -o "$output" "$url" + # Honour preferred tool from configuration; fall back to auto-detection. + local preferred="${DWL_PREFERRED_TOOL:-}" + + _try_curl() { [ -z "$output" ] && curl -sL "$url" || curl -sL -o "$output" "$url"; } + _try_wget() { [ -z "$output" ] && wget -qO- "$url" || wget -q -O "$output" "$url"; } + _try_fetch() { [ -z "$output" ] && fetch -o - "$url" || fetch -o "$output" "$url"; } + + if [[ -n "$preferred" ]]; then + command -v "$preferred" >/dev/null 2>&1 || { + echo "Error: preferred download tool '$preferred' is not installed." >&2 + return 1 + } + case "$preferred" in + curl) _try_curl ;; + wget) _try_wget ;; + fetch) _try_fetch ;; + *) + echo "Error: DWL_PREFERRED_TOOL '$preferred' is not supported (use curl, wget or fetch)." >&2 + return 1 + ;; + esac + elif command -v curl >/dev/null 2>&1; then + _try_curl elif command -v wget >/dev/null 2>&1; then - [ -z "$output" ] && wget -qO- "$url" || wget -q -O "$output" "$url" + _try_wget elif command -v fetch >/dev/null 2>&1; then - [ -z "$output" ] && fetch -o - "$url" || fetch -o "$output" "$url" + _try_fetch else echo "Error: No download utility (curl, wget, or fetch) found." >&2 return 1 fi + unset -f _try_curl _try_wget _try_fetch } export -f dwl # ------------------------------------------------------------------------------ @@ -236,13 +258,12 @@ myextip() shift done - # Fetch data. Allow overriding endpoint via env var MYEXTIP_URL - local MYEXTIP_URL - MYEXTIP_URL=${MYEXTIP_URL:-https://ip-api.com/json/} + # Fetch data. Allow overriding endpoint via MYEXTIP_DEFAULT_URL config key. + local api_url="${MYEXTIP_DEFAULT_URL:-https://ip-api.com/json/}" local response - if ! response=$(dwl "$MYEXTIP_URL"); then - disp E "Failed to fetch external IP information from $MYEXTIP_URL" + if ! response=$(dwl "$api_url"); then + disp E "Failed to fetch external IP information from $api_url" return 2 fi @@ -272,3 +293,7 @@ export -f myextip # ------------------------------------------------------------------------------ # EOF + +load_conf "net" + +# EOF diff --git a/profile.d/packages.sh b/profile.d/packages.sh index b2e6ef5..811354e 100644 --- a/profile.d/packages.sh +++ b/profile.d/packages.sh @@ -39,7 +39,7 @@ # Usage: dpkgs pkgs() { - local ignore_case=0 + local ignore_case=${PKGS_DEFAULT_IGNORE_CASE:-0} local PARSED PARSED=$(getopt -o hi --long help,ignore-case -n 'pkgs' -- "$@") @@ -96,4 +96,6 @@ export -f pkgs # ------------------------------------------------------------------------------ +load_conf "packages" + # EOF diff --git a/profile.d/processes.sh b/profile.d/processes.sh index 193d060..4567e2e 100644 --- a/profile.d/processes.sh +++ b/profile.d/processes.sh @@ -95,7 +95,7 @@ ppu() # -u lists processes for a specific user # -o provides a clean, standard output format - ps -u "$1" -o pid,user,%cpu,%mem,start,time,command + ps -u "$1" -o "${PPU_DEFAULT_FORMAT:-pid,user,%cpu,%mem,start,time,command}" } export -f ppu # ------------------------------------------------------------------------------ @@ -206,7 +206,7 @@ ku() disp E "User '$u' does not exist." return 1 else - killall -u "$u" + killall ${KU_DEFAULT_SIGNAL:+-${KU_DEFAULT_SIGNAL}} -u "$u" fi done } @@ -249,5 +249,7 @@ export -f kt # ------------------------------------------------------------------------------ +load_conf "processes" + # EOF diff --git a/profile.d/pwd.sh b/profile.d/pwd.sh index 7b52b48..02e4071 100644 --- a/profile.d/pwd.sh +++ b/profile.d/pwd.sh @@ -52,10 +52,13 @@ # The function is very slow on Windows genpwd() { - local length=16 - local occurs=2 - local symb=1 maj=1 min=1 numb=1 - local nbpwd=1 + local length=${GENPWD_DEFAULT_LENGTH:-16} + local occurs=${GENPWD_DEFAULT_OCCURS:-2} + local symb=${GENPWD_DEFAULT_SYMBOLS:-1} + local maj=${GENPWD_DEFAULT_UPPERCASE:-1} + local min=${GENPWD_DEFAULT_LOWERCASE:-1} + local numb=${GENPWD_DEFAULT_NUMBERS:-1} + local nbpwd=${GENPWD_DEFAULT_COUNT:-1} local extcar="" local PARSED @@ -272,7 +275,7 @@ export -f genpwd # Usage: pwdscore [options] pwdscore() { - local verbose=0 + local verbose=${PWDSCORE_DEFAULT_VERBOSE:-0} local read_stdin=0 local password="" @@ -474,4 +477,6 @@ export -f pwdscore # ------------------------------------------------------------------------------ +load_conf "pwd" + # EOF diff --git a/profile.d/rain.sh b/profile.d/rain.sh index 4541151..706f39f 100644 --- a/profile.d/rain.sh +++ b/profile.d/rain.sh @@ -292,8 +292,10 @@ rain() printf "Example: rain --color green --speed 3\n" } - local step_duration=0.050 - local base_color="white" + local _raw_speed="${RAIN_DEFAULT_SPEED:-5}" + local step_duration + step_duration=$(_rain_normalize_speed "$_raw_speed") || step_duration=0.050 + local base_color="${RAIN_DEFAULT_COLOR:-white}" while [[ "$#" -gt 0 ]]; do case $1 in @@ -360,9 +362,11 @@ matrix() printf "Example: matrix -C kana -c green --speed 2\n" } - local step_duration=0.035 - local base_color="green" - local charset="binary" + local _raw_speed="${MATRIX_DEFAULT_SPEED:-3.5}" + local step_duration + step_duration=$(_rain_normalize_speed "$_raw_speed") || step_duration=0.035 + local base_color="${MATRIX_DEFAULT_COLOR:-green}" + local charset="${MATRIX_DEFAULT_CHARSET:-binary}" while [[ "$#" -gt 0 ]]; do case $1 in @@ -430,4 +434,7 @@ matrix() export -f matrix # ------------------------------------------------------------------------------ + +load_conf "rain" + # EOF diff --git a/profile.d/ssh.sh b/profile.d/ssh.sh index 89eb710..187b8ec 100644 --- a/profile.d/ssh.sh +++ b/profile.d/ssh.sh @@ -186,10 +186,20 @@ ssr() local srv=$1 shift - ssh -Y root@"$srv" "$@" + # Build default options array from config, falling back to -Y (X11 forwarding) + local -a ssh_default_opts=() + if [[ -n "${SSH_DEFAULT_OPT:-}" ]]; then + read -ra ssh_default_opts <<< "${SSH_DEFAULT_OPT}" + else + ssh_default_opts=(-Y) + fi + + ssh "${ssh_default_opts[@]}" root@"$srv" "$@" } export -f ssr # ------------------------------------------------------------------------------ +load_conf "ssh" + # EOF