zsh:ls-show-hidden: Use short param expansion form

Use the short parameter expansion form where it leads to a better
readability in my eyes (e.g. "${dir:A}" -> "$dir:A" does not, I think.)
This commit is contained in:
2022-12-27 16:39:40 +01:00
parent c034191254
commit 9b0e49b319

View File

@@ -47,7 +47,7 @@ for arg in "$@"; do
done done
# Print working directory when only flags were given as arguments. # Print working directory when only flags were given as arguments.
if ! (( ${#dirs} + ${#files} + $non_existing )); then if ! (( $#dirs + $#files + $non_existing )); then
dirs+=. dirs+=.
fi fi
@@ -62,18 +62,18 @@ empty=("")
set -- "${(@)${(@)all_opts//--*}:|empty}" set -- "${(@)${(@)all_opts//--*}:|empty}"
while getopts d flag 2>/dev/null; do while getopts d flag 2>/dev/null; do
[[ "$flag" = "d" ]] || continue [[ "$flag" = "d" ]] || continue
command $LS_COMMAND "${all_opts[@]}" -- "${files[@]}" "${dirs[@]}" command $LS_COMMAND "$all_opts[@]" -- "$files[@]" "$dirs[@]"
return return
done done
# Restore options. # Restore options.
set -- "${all_opts[@]}" set -- "$all_opts[@]"
unset all_opts empty unset all_opts empty
builtin local separator="" builtin local separator=""
# Print files. # Print files.
if (( ${#files} )); then if (( $#files )); then
command $LS_COMMAND "$@" -- "${files[@]}" command $LS_COMMAND "$@" -- "$files[@]"
# Print a newline between files and folder segment. # Print a newline between files and folder segment.
separator="\n" separator="\n"
fi fi
@@ -85,14 +85,14 @@ for dir in ${(@f)dirs}; do
content=( "$dir"/* ) content=( "$dir"/* )
# If the directory contains no visible files or it matches a pattern, then # If the directory contains no visible files or it matches a pattern, then
# show hidden files when listing # show hidden files when listing
if (( ! ${#content} )) || [[ "${dir:A}" =~ "${LS_SHOW_ALL_DIRS:-^$}" ]]; then if (( ! $#content )) || [[ "${dir:A}" =~ "${LS_SHOW_ALL_DIRS:-^$}" ]]; then
all_flag="-A" all_flag="-A"
else else
all_flag= all_flag=
fi fi
# If there are multiple items to list, print a newline (if ls was already # If there are multiple items to list, print a newline (if ls was already
# executed) followed by the dir-name. # executed) followed by the dir-name.
! (( ${#dirs} + ${#files} + ${non_existing} - 1 )) || echo "$separator$dir:" ! (( $#dirs + $#files + $non_existing - 1 )) || echo "$separator$dir:"
# Print directory. $all_flag has to be unquoted else ls will fail. # Print directory. $all_flag has to be unquoted else ls will fail.
command $LS_COMMAND "$@" $all_flag -- "$dir" command $LS_COMMAND "$@" $all_flag -- "$dir"
separator="\n" separator="\n"