add noheader option

This commit is contained in:
Mylloon 2024-04-11 14:44:19 +02:00
parent 48107de2ea
commit 2f8cec6c51
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -1,13 +1,18 @@
function catall --description "Print recursively multiple files."
# Declare our arguments
argparse h/help n/noheader -- $argv
# Get function name
set current_name $(status current-function)
# Check if no arguments were provided, or if the first argument is '--help'
if test -z $argv[2] || test "$argv[1]" = --help || test "$argv[1]" = -h
# Check if not enough arguments provided, or help menu
if set -ql _flag_help || test -z $argv[2]
echo -e "Usage: $current_name <directory> exts ..."
echo -e " $current_name [-h|--help] \t\t\t - Show this help message"
echo -e " $current_name <directory> *.c \t\t - Cat all .C files"
echo -e " $current_name <directory> *.c *.h ... \t - Cat .C and .H files, etc."
echo -e "Flag:"
echo -e " [-n|-noheader] \t\t\t - Don't show the filenames before print"
return 0
end
@ -21,7 +26,10 @@ function catall --description "Print recursively multiple files."
end
# Extra args for better printing
set args -exec echo -e "File: {}" \; -exec cat {} \; -exec echo "" \;
if not set -ql _flag_noheader
set args -exec echo -e "File: {}" \;
end
set -a args -exec cat {} \; -exec echo "" \;
# Print files
find $directory \( $exts \) $args