Skip to content

Commit b08f09c

Browse files
committed
feat: upgrade maxdepth, m1m1 function output
Signed-off-by: Lucas Larson <LucasLarson@riseup.net>
1 parent 5f5d933 commit b08f09c

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

custom/aliases.sh

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6614,15 +6614,22 @@ markdownlint_r() {
66146614
# not defined by POSIX, but these are equivalent
66156615
maxdepth() {
66166616
# instead of `find . -maxdepth 2 -print`, use `find . -path './*/*/*' -prune -o -print`
6617-
path_argument='./*'
6618-
depth="${1:-0}"
6619-
while command -p -- test "${depth-}" -gt 0; do
6620-
path_argument="${path_argument-}"'/*' &&
6621-
depth="$((depth - 1))"
6617+
set -- "${1:-0}" './*'
6618+
while command -p -- test "${1-}" -gt 0; do
6619+
set -- "$((${1-} - 1))" "${2-}"'/*'
66226620
done
6623-
command -p -- printf -- '#!/usr/bin/env sh\ncommand -p -- find -- . -path \047%s\047 -prune -o -print\n' "${path_argument-}"
6624-
unset path_argument >/dev/null 2>&1 || path_argument=''
6625-
unset depth >/dev/null 2>&1 || depth=''
6621+
command -p -- printf -- '#!/usr/bin/env sh\ncommand -p -- find -- . -path \047%s\047 -prune -o -print\n' "${2-}" | {
6622+
command bat \
6623+
--color=auto \
6624+
--decorations=never \
6625+
--language=sh \
6626+
--paging=never \
6627+
-- \
6628+
- 2>/dev/null ||
6629+
command -p -- cat \
6630+
-- \
6631+
-
6632+
}
66266633
}
66276634
mindepth() {
66286635
# instead of `find . -mindepth 2 -print`, use `find . -path './*/*' -print`
@@ -6644,19 +6651,18 @@ mindepth() {
66446651
}
66456652
}
66466653
m1m1() {
6647-
{
6648-
command -p -- printf -- '#!/usr/bin/env sh\n'
6649-
command -p -- printf -- 'command -p -- find -- . -path \047./*/*\047 -prune -o -path \047./*\047 -print\n'
6650-
} | command bat \
6651-
--color=auto \
6652-
--decorations=never \
6653-
--language=sh \
6654-
--paging=never \
6655-
-- \
6656-
- 2>/dev/null ||
6657-
command -p -- cat \
6654+
command -p -- printf -- '#!/usr/bin/env sh\ncommand -p -- find -- . -path \047./*/*\047 -prune -o -path \047./*\047 -print\n' | {
6655+
command bat \
6656+
--color=auto \
6657+
--decorations=never \
6658+
--language=sh \
6659+
--paging=never \
66586660
-- \
6659-
-
6661+
- 2>/dev/null ||
6662+
command -p -- cat \
6663+
-- \
6664+
-
6665+
}
66606666
}
66616667

66626668
# https://unix.stackexchange.com/a/30950

0 commit comments

Comments
 (0)