commit 5c96b62f2b9737024f55e32d5de619553802bb42 Author: Seoxi Ryouko <3-seoxi@users.noreply.git.starbit.dev> Date: Sun May 4 21:22:13 2025 -0500 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..2cfbbd5 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +ls zero bash polyfill +===================== + +allows you to simulate the --zero option of ls from +gnu coreutils v9, in earlier versions + +relies on coreutils (ls and tr), and grep with +the -P option diff --git a/ls_zero.bash b/ls_zero.bash new file mode 100644 index 0000000..8a081bd --- /dev/null +++ b/ls_zero.bash @@ -0,0 +1,20 @@ + +_ls() { + env ls "$@" +} + +_lsp() { + printf "%s" "$*" | grep -qP '(\s|^)--zero(\s|$)' + 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