Files
ls-zero-bash-polyfill/ls_zero.bash
Seoxi Ryouko 8784340e64 Added help message to Linux systems.
(Assuming Linux uses gnu coreutils with --help,
and non-Linux doesn't.)
2025-05-04 23:22:33 -04:00

36 lines
705 B
Bash

_ls() {
env ls "$@"
}
matchtest() {
printf "%s" "$1" | grep -qE "$2"
}
_lsp() {
if matchtest "$(uname)" "Linux" && matchtest "$*" '(^| )(-h|--help)( |$)'; then
_ls "$@"
local error=$?
test $error -eq 0 && cat <<- EOF
ls zero bash polyfill:
adds additional --zero option, which seperates
output with null characters rather than newlines
use _ls or env ls for default behavior
EOF
return $error
fi
matchtest "$*" '(^| )--zero( |$)'
local zero=$?
local args="$@"
declare -a args=(${args[@]/--zero/})
if test $zero -eq 0; then
output="$(_ls "${args[@]}")"
error=$?
printf "%s" "$output" | tr '\n' '\0'
return $error
fi
_ls "${args[@]}"
}
alias ls=_lsp