How to make bash alias invocation conditional on PWD?

Solution 1:

From man bash:

For almost every purpose, aliases are superseded by shell functions.

So make it a shell function.

function cmakerel {
    if expr match "$PWD" '.*bld.*' >/dev/null ; then
        cmake -D....
    else
        echo "Wrong directory!"
    fi
}

It's a regular expression you can adjust to your needs.