Is it possible to have separate bash completion functions for separate commands that share the same name?

I have two separate scripts with the same filename, in different paths, for different projects: /home/me/projects/alpha/bin/hithere

and /home/me/projects/beta/bin/hithere

.

Accordingly, I have two separate bash completion scripts because the correct completion is different for each of the scripts. In completion scripts, a complete command is executed to complete the complete script name, i.e.

complete -F _alpha_hithere_completion /home/me/projects/alpha/bin/hithere

However, it seems that only the most recent run of the script works, no matter which valid version hithere

is called: it seems that bash completion only cares about the filename and ignores the path information.

Is there a way to change this behavior so that I can have these two independent scripts with the same name, each with different completion functions?

Note that I am not interested in a solution that requires the alpha to know about the beta, or that requires the third component to know about one of them - to defeat the target in my case.

+3


source to share


1 answer


The bash manual describes the process for finding revisions:

If the command word is a fully qualified path name, compspec searches for the full path first. If no compspec is found for the full path, an attempt is made to find the compspec for the part following the last slash. If these requests do not result in a compspec, any compspec specified with the option -D

on complete

is used by default.



Thus, the full path is used complete

, but only if you invoke the command through your full path. As far as shutting down using just a short name, I think your only option (judging by the spec) would be a kind of dynamic hook that determines which termination function to call based on $PWD

- I don't see any evidence that Bash supports overloading completion name as you suggest.

+1


source







All Articles