Skip to content

Commit

Permalink
refactor: test find’s -type late for speed
Browse files Browse the repository at this point in the history
perform `find`’s `-name` test “before the `-type` test in order to avoid
having to call `stat(2)` on every file”
https://git.sv.gnu.org/cgit/findutils.git/commit/find/find.1?id=06887a6b8e

Signed-off-by: Lucas Larson <[email protected]>
  • Loading branch information
LucasLarson committed May 8, 2024
1 parent db45630 commit 2d31714
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions custom/aliases.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,14 @@ cleanup() {
# delete thumbnail cache files
# and hide `find: ‘./com...’: Operation not permitted` with `2>/dev/null`
command find -- . \
-type f \
'(' \
-name '.DS_Store' -o \
-name 'Desktop.ini' -o \
-name 'desktop.ini' -o \
-name 'Thumbs.db' -o \
-name 'thumbs.db' \
')' \
-type f \
-delete

# delete crufty Zsh files
Expand All @@ -330,17 +330,17 @@ cleanup() {
while test "$(
command find -- "${HOME%/}" \
-maxdepth 1 \
-type f \
! -name "$(printf -- "*\n*")" \
! -name '.zcompdump' \
-name '.zcompdump*'
-name '.zcompdump*' \
-type f
)" != ''; do
command find -- "${HOME%/}" \
-maxdepth 1 \
-type f \
! -name "$(printf -- "*\n*")" \
! -name '.zcompdump' \
-name '.zcompdump*' \
-type f \
-delete
done
fi
Expand Down Expand Up @@ -431,17 +431,17 @@ command rm -- "{}"' ';'

# swap each tab for two spaces each in `.git/config` and `$HOME/.gitconfig`
command find -- . \
-type f \
-path '*/.git/*' \
-name 'config' \
-type f \
-exec sed -i -e 's/\t/ /g' {} ';'
command sed -i -e 's/\t/ /g' "${HOME%/}"'/.gitconfig'

# remove Git sample hooks
command find -- . \
-type f \
-path '*/.git/*' \
-path '*/hooks/*.sample' \
-type f \
-delete

;;
Expand Down Expand Up @@ -730,8 +730,8 @@ alias fdf='find_duplicate_files'
find_files_with_no_extension() {
command find -- . \
-path '*/.git' -prune -o \
-type f \
! -name '*.*' \
-type f \
-print 2>/dev/null |
LC_ALL='C' command sort -u
}
Expand Down Expand Up @@ -773,7 +773,6 @@ find_shell_scripts() {
# all files with `linguist` Shell filename extensions
command find -- . \
-path '*/.git' -prune -o \
-type f \
'(' \
-name '.sh' -o \
-name '*.bash' -o \
Expand Down Expand Up @@ -833,7 +832,9 @@ find_shell_scripts() {
-name 'zprofile' -o \
-name 'zshenv' -o \
-name 'zshrc' \
')' 2>/dev/null
')' \
-type f \
-print 2>/dev/null

# files whose first line resembles those of shell scripts
# https://stackoverflow.com/a/9612232
Expand Down Expand Up @@ -2005,7 +2006,6 @@ yamllint_r() {
-path '*/Test*' -prune -o \
-path '*/test*' -prune -o \
-path '*vscode*' -prune -o \
! -type d \
'(' \
-name '*.yml' -o \
-name '*.CFF' -o \
Expand All @@ -2026,6 +2026,7 @@ yamllint_r() {
-name '.gemrc' -o \
-name '.yamllint' \
')' \
! -type d \
-print \
-exec sh -c 'command git ls-files --error-unmatch -- "{}" >/dev/null 2>&1 ||
! command git rev-parse --is-inside-work-tree >/dev/null 2>&1 &&
Expand Down

0 comments on commit 2d31714

Please sign in to comment.