zsh: Heavy improvements to ls_show_hidden

Autoload the function instead of declaring it directly.
Add functionality for multiple targets. It should now pretty much
perform like `command ls`.
Refactored code to use more zsh extensions like globbing instead of
parsing the output of `ls` making it a lot faster.
This commit is contained in:
2020-09-25 01:09:59 +02:00
parent b301cb5045
commit 11ec8b93fb
3 changed files with 63 additions and 26 deletions

View File

@@ -72,7 +72,7 @@ alias gdiff='git diff'
alias gd='git diff'
## Navigation
alias ls='_ls_show_hidden --color=auto --group-directories-first -p -v'
alias ls='ls --color=auto --group-directories-first -p -v'
alias sl='ls'
alias la='ls -A'
alias l='ls -lh --time-style=long-iso'

View File

@@ -18,28 +18,3 @@ function _nemo_wd_default() {
command nemo "$@"
fi
}
## ls function that prints hidden files when there are no regular files
## or if we are in a directory that matches the regex in LS_SHOW_ALL_DIRS
function _ls_show_hidden() {
# Can be overwritten by settings it before calling
local LS_SHOW_ALL_DIRS=${LS_SHOW_ALL_DIRS:-"dotfiles|\.config"}
# if a path is given, target will contain the given directory or the directory in which the
# given file is located
local target
for arg in "$@"; do
if [ -d "$arg" ]; then
target="$arg"
break
elif [ -d "${arg%/*}" ]; then
target="${arg%/*}"
break
fi
done
if [[ -z "$(command ls "$@")" || "$( (cd "$target"; pwd) )" =~ "${LS_SHOW_ALL_DIRS:-^$}" ]]; then
command ls -A "$@"
else
command ls "$@"
fi
}