zsh:ls-show-hidden: Bug fixes around -d flag
Fix behavior to match ls's when the -d flag but no files or directories were passed. Fix bug that the function thinks -d is passed when a long option that contains a 'd' (as --group-directories-first) is specified and thus just emulates plain `ls` in that case.
This commit is contained in:
@@ -29,16 +29,26 @@ done
|
|||||||
|
|
||||||
# Print working directory when only flags were given as arguments.
|
# Print working directory when only flags were given as arguments.
|
||||||
if ! (( ${#dirs} + ${#files} )); then
|
if ! (( ${#dirs} + ${#files} )); then
|
||||||
dirs+="$PWD"
|
dirs+=.
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Do not separate files and directories if -d flag was specified.
|
# Just pass everything to ls when the -d flag is given since then the -A flag
|
||||||
|
# makes no difference.
|
||||||
|
# Remove all long options because `getopts` cannot handle those and sees for
|
||||||
|
# example -d in --group-directories-first. Remove the resulting empty strings
|
||||||
|
# afterwards since that confuses `getopts` apparently.
|
||||||
|
builtin local -a all_opts empty
|
||||||
|
all_opts=("$@")
|
||||||
|
empty=("")
|
||||||
|
set -- "${(@)${(@)all_opts//--*}:|empty}"
|
||||||
while getopts d flag 2>/dev/null; do
|
while getopts d flag 2>/dev/null; do
|
||||||
if [[ "$flag" = "d" ]]; then
|
[[ "$flag" = "d" ]] || continue
|
||||||
command ls "$@" -- "${files[@]}" "${dirs[@]}"
|
command ls "${all_opts[@]}" -- "${files[@]}" "${dirs[@]}"
|
||||||
return
|
return
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
# Restore options.
|
||||||
|
set -- "${all_opts[@]}"
|
||||||
|
unset all_opts empty
|
||||||
|
|
||||||
builtin local separator=""
|
builtin local separator=""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user