confOS/.config/fish/functions/catall.fish

28 lines
973 B
Fish

function catall2 --description "Print recursively multiple files."
# 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
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."
return 0
end
# Define directory
set directory $argv[1]
# Define extensions
set exts -name "$argv[2]"
for ext in $argv[3..-1]
set -a exts -o -name "$ext"
end
# Extra args for better printing
set args -exec echo -e "File: {}" \; -exec cat {} \; -exec echo "" \;
# Print files
find $directory \( $exts \) $args
end