-
Notifications
You must be signed in to change notification settings - Fork 387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additional helper functions #432
Comments
Thanks! 1-3 are useful, no doubt, and I think I have some private prototypes for those stashed somewhere. Will take a look when I find time.
Processwise I think it would be wise to approach getting these in in some order, one at a time, and opening separate issues/PR's for each. |
Fair point. I should probably read some more of your completion scripts from this repo to understand how certain things can be implemented. I used the function e.g. in this script kutil, but as already said there are maybe better ways to get the job done. Concerning the other functions I agree that separate issues/PR's make sense. What do your prefer? I guess Pull requests containing my poorly written bash functions creates a lot of overhead as you probably want to modify many things (especially since you have already some private implementations). So may you just close this issue and I create 3 new one? |
Hey :)
I'm new to bash-completion and wrote my completion scripts from scratch so far. Now I'm really happy that I can use some helper functions from your scripts. However, certain helper functions I used in the past are missing and I wanted to ask if you are interested in implementing them or if you can tell me alternative solution how these cases can be covered by your script (I would create a pull request, but as you will see my bash skills are really poor. Furthermore, I'm not sure if the functions are already implemented somewhere and I'm missing them).
1. Get n-th Parameter
As I can see, you support a
_get_first_arg
function. This is nice, but in the past I also need to obtain the n-th parameter from the command line. I used the following function to accomplish this:2. List Contains
This is not really completion specific, but it is that useful that I use it in nearly all my completion scripts. The idea is to compare two strings that contain space separated words with each other. If one word matches, it returns true, otherwise false.
Sometimes you have parameter groups for a command. E.g. you supply the argument
--decrypt
that can be combined with--username
and--password
, but not with other options that would be allowed otherwise. In this cases I check if--decrypt
,--username
or--password
are present on the command line. If this is the case, I only complete the corresponding set. This can be done with:if _comp_contains "${COMP_LINE}" "--decrypt --username --password";
3. Remove Already Used Arguments
The
curl
command is a good example. Let's look at its completions:After
-ntlm
is specified once, it is not useful to complete this option a second time. To prevent this, I usually use the following function:After using
_comp_filter opts
, duplicate options are filtered from my completion list.4. Removing Short Arguments
I agree with your guidelines that short options should not be completed. However, for the completion logic it is sometimes useful to define a list with a certain set of arguments, e.g.
-o --output -m --merge ...
. Moreover, this list could sometimes be used again to define the completion list. In these cases it is useful when you have a function that filters the short options.After using
_comp_filter_shorts opts
, the options list does no longer contain short options.Summarized
Like already mentioned, the above shown functions are implemented rather poorly and probably contain some bugs for situations that I have not thought of. However, I think that the actual functionalities are quite useful and could be used for many completion scripts. Therefore, I would be happy if they are present in the default completion toolset for bash.
It would be great if you could supply some feedback for each function. I would be interested whether:
Best Regards
Tobias
The text was updated successfully, but these errors were encountered: