From d57ee922c9d1fbb4814940ca57c7a7151b7f7642 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Wed, 5 Feb 2025 16:48:10 +0100 Subject: [PATCH] zsh:funcs: Add find() wrapper analog to bfs() Only difference is that it places a trailing slash behind (empty) directory names to differentiate them better. bfs does this already. TODO: Bring these together into one function that checks $0 --- .config/zsh/zshrc.d/40-functions.zsh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.config/zsh/zshrc.d/40-functions.zsh b/.config/zsh/zshrc.d/40-functions.zsh index e32705d..d2d7d48 100644 --- a/.config/zsh/zshrc.d/40-functions.zsh +++ b/.config/zsh/zshrc.d/40-functions.zsh @@ -759,3 +759,20 @@ rmdir() { command bfs "$@" fi } + +# TODO: bring together with bfs +# find wrapper with condensed output by default (i.e. no directories except if +# they're empty) +(( ! $+commands[find] )) || find() { + emulate -L zsh + + # Make sure that std{out,err} are associated with a tty and that no + # arguments were passed that start with a dash + if [[ -t 1 && -t 2 ]] && (( ! $# || ! ${@[(I)-*]} )); then + # Only print files and empty directories (and mark these with a + # trailing slash) + command find "$@" -type f -print -o -type d -empty -printf "%p/\n" + else + command find "$@" + fi +}