confOS/.config/fish/functions/makeaway.fish

33 lines
1 KiB
Fish

function makeaway
# Check if no arguments were provided, or if the first argument is '--help'
if test -z $argv[1] || test "$argv[1]" = --help
echo -e "Usage: makeaway <directory> [-- <target>]"
echo -e " makeaway --help \t\t - Show this help message"
echo -e " makeaway <directory> \t\t - Run 'make' in the specified directory"
echo -e " makeaway <directory> -- <target> - Run 'make <target>' in the specified directory"
return 0
end
# Check if directory exists
set directory $argv[1]
if not test -d $directory
echo "Directory doesn't exists." 1>&2
return 1
end
# Find the target
set target ""
if test (count $argv) -ge 3 && test "$argv[2]" = --
# Target required
set target $argv[3]
else if test (count $argv) -ge 2 && test "$argv[2]" = --
# User used "--" without target
echo "No target found." 1>&2
return 1
end
# Make
cd $directory
make $target
cd -
end