Added help message to Linux systems.
(Assuming Linux uses gnu coreutils with --help, and non-Linux doesn't.)
This commit is contained in:
19
ls_zero.bash
19
ls_zero.bash
@ -3,12 +3,27 @@ _ls() {
|
|||||||
env ls "$@"
|
env ls "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
matchtest() {
|
||||||
|
printf "%s" "$1" | grep -qE "$2"
|
||||||
|
}
|
||||||
|
|
||||||
_lsp() {
|
_lsp() {
|
||||||
printf "%s" "$*" | grep -qE '(^| )--zero( |$)'
|
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 zero=$?
|
||||||
local args="$@"
|
local args="$@"
|
||||||
declare -a args=(${args[@]/--zero/})
|
declare -a args=(${args[@]/--zero/})
|
||||||
if test "$zero" -eq 0; then
|
if test $zero -eq 0; then
|
||||||
output="$(_ls "${args[@]}")"
|
output="$(_ls "${args[@]}")"
|
||||||
error=$?
|
error=$?
|
||||||
printf "%s" "$output" | tr '\n' '\0'
|
printf "%s" "$output" | tr '\n' '\0'
|
||||||
|
|||||||
Reference in New Issue
Block a user