For make
specifically, you can use its -C
option:
function omake
make -C $SOURCE_ROOT $argv
end
Many other programs take the -C
option. On top of my head: ninja, git
Otherwise, if you're content with a subshell anyway, a standalone script gives you just that, with the benefit that you can write it in any language, from Python to C, and won't have to rewrite it when you want to change your shell.
This could be written in any language:
#!/usr/bin/env fish
cd $SOURCE_ROOT
and exec make $argv
However, what really bugs me is the blatant omission of the -C
option in env
! Env can set environment variables and run programs; clearly, it would be nice to be able to set the working directory too! Here is a rudimentary cdrun
script to make up for that:
#!/usr/bin/env fish
cd $argv[1]
and exec env $argv[2..-1]
or
#!/bin/sh
set cd="$1"
shift
cd "$cd" &&
exec env "$@"
Armed with the cdrun
command, your omake function would be as simple as:
function omake
cdrun $SOURCE_ROOT make $argv
end
or
omake() {
cdrun "$SOURCE_ROOT" make "$@"
}