From d23f07f03c27212994df6dce65e0afd4abe37b9a Mon Sep 17 00:00:00 2001 From: Jake Boeckerman Date: Thu, 12 Dec 2024 16:33:29 -0700 Subject: [PATCH] stronger safety guarantee on flag-like files --- plugins/available/jake-implicit-commands.plugin.bash | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/available/jake-implicit-commands.plugin.bash b/plugins/available/jake-implicit-commands.plugin.bash index ea92912aec..e0b4d1eae8 100644 --- a/plugins/available/jake-implicit-commands.plugin.bash +++ b/plugins/available/jake-implicit-commands.plugin.bash @@ -361,7 +361,11 @@ function file { ( # TODO: `local -` instead of a subshell? set -o pipefail if [[ "$#" -eq 0 ]]; then - command file -E * | pager + # A safer form of file -E * using find + # -maxdepth 1 - find only the files under the starting-point + # -printf '%P\0' - customizing a form of -print0 which strips the ./ prefix that -print0 gives + # %P: File's name with the name of the starting-point under which it was found removed. + find . -maxdepth 1 -printf '%P\0' | xargs --null file -E | pager else command file -E "$@" | pager fi