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

41 lines
1.4 KiB
Fish
Raw Permalink Normal View History

2023-10-09 17:56:28 +02:00
function makeaway --description "Run 'make' from another directory"
2023-10-08 20:51:38 +02:00
# Get function name
set current_name $(status current-function)
2023-10-08 16:34:00 +02:00
# Check if no arguments were provided, or if the first argument is '--help'
2023-10-08 20:51:38 +02:00
if test -z $argv[1] || test "$argv[1]" = --help || test "$argv[1]" = -h
echo -e "Usage: $current_name <directory> [-- <target>]"
echo -e " $current_name [-h|--help] \t\t - Show this help message"
echo -e " $current_name <directory> \t\t - Run 'make' in the specified directory"
echo -e " $current_name <directory> -- <target> - Run 'make <target>' in the specified directory"
2023-10-08 16:34:00 +02:00
return 0
end
# Check if directory exists
2023-10-08 19:43:22 +02:00
set directory "$argv[1]"
if not test -d "$directory"
2023-10-08 20:51:38 +02:00
echo "$current_name: directory doesn't exists." 1>&2
return 1
end
2023-10-08 16:34:00 +02:00
# 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
2023-10-08 20:51:38 +02:00
echo "$current_name: no target found." 1>&2
2023-10-08 16:34:00 +02:00
return 1
2023-10-08 19:48:57 +02:00
else if test (count $argv) -ge 2 && not test "$argv[2]" = --
# User used "--" without target
2023-10-08 20:51:38 +02:00
echo "$current_name: unknown argument `$argv[2]`." 1>&2
2023-10-08 19:48:57 +02:00
return 1
2023-10-08 16:34:00 +02:00
end
# Make
2023-10-08 19:43:22 +02:00
cd "$directory"
2023-10-08 16:34:00 +02:00
make $target
cd -
end