Artificial intelligent assistant

Dynamic bash alias based on the location I have the following folder structure: alpha src doit.py beta src doit.py gama src doit.py and the command python ../../doit.py --clean --add_source inner I want to create an alias, `doit` that executes the corresponding file depending in which parent folder I'm located. For example: 1. If I'm inside `alpha` or one of is sub-directories, when I use: `doit --addsource extra` to actually run: `python /home/alpha/src/doit.py --clean --addsource extra` 2. If I'm inside `beta` or one of is sub-directories, when I use: `doit --addsource inner` to actually run: python /home/beta/src/doit.py --clean --addsource inner

You would be better served by a shell function:


doit () {
local dir

case $PWD/ in
/home/alpha/*) dir=alpha ;;
/home/beta/*) dir=beta ;;
/home/gamma/*) dir=gamma ;;
*) echo 'Not standing in the correct directory' >&2
return 1
esac

python "/home/$dir/src/doit.py" --clean "$@"
}


This would set the variable `dir` to the string `alpha`, `beta` or `gamma` depending on the current working directory, or complain that you're in the wrong directory tree if the current directory is elsewhere.

It then runs the Python script, utilizing the `$dir` value, with the `--clean` option and adds whatever other arguments that you've passed to the function.

You would add this shell function's definition to wherever you ordinarily add aliases.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 6f8c73e8cc55e666c01c1a780616c987