Skip to main content
added 1 character in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

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.

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.

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.

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

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.