make defaults configurable

This commit is contained in:
fatalerrors
2026-04-15 13:38:08 +02:00
parent 85f02f4498
commit 9a006883b8
11 changed files with 269 additions and 40 deletions

View File

@@ -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

View File

@@ -39,7 +39,7 @@
# Usage: expandlist [options] <item1 [item2 ... itemN]>
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

View File

@@ -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

View File

@@ -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 <city>'."
return 1
fi
for city in "${cities[@]}"; do
encoded=$(urlencode "$city")

View File

@@ -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

View File

@@ -39,7 +39,7 @@
# Usage: dpkgs <string>
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

View File

@@ -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

View File

@@ -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] <password>
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

View File

@@ -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

View File

@@ -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