-
Notifications
You must be signed in to change notification settings - Fork 260
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
Improve argument parser + implement bash completion #506
Conversation
Thank you so much for this. One other thing that the user mentioned was autocomplete on profiles and layouts, so -p would autocomplete profiles and -l would autocomplete layouts. To do this we would have to dig into the internals a little bit more to get the list of profiles and layouts. I can take a stab at it if you don't want to. |
Oh ok, that shouldn't be too difficult. It's just a matter of creating an option like "--list-profiles" and parse it on the bash file. I can work on this tomorrow, it's not a problem. |
That would be great, thanks again. |
I see that you are using a native |
Reading the code, we seem to still use optparse, a deprecated library. Update: it's... quite a lot of work. |
Ok another thing is done. The code I modified was mostly 12 years old. The new library is overall better, easier to use, does many things automatically and so on. |
I haven't merged this yet because I have a few tweaks to it. If it's OK with you I'll do a PR against your branch with them sometime soon. |
The translations files should be updated (because of Also, I haven't implemented the profile and layouts completion yet, because I don't know if we should use |
The I have had experience in both so I can support you if you need something to talk things through. |
My concern is about using a non-standard module. I don't really know how these are handheld here. |
Unless we absolutely need a 3rd party library, I would not merge it in. I have a pretty big aversion to 3rd party python modules in general. |
So, in case, if we wouldn't like to use the We have to remember about add installing completion/bash to setup.py |
Since the issue specifies bash completions, let's just leave it at that. I'm still on the fence about putting the completions in as part of a standard install through setup.py, as I'm not sure there is a standard location across all of the platforms that terminator currently runs on where we can place that file. If anyone knows one I'd be happy to include, but for now, let's not worry about that. |
Ok, I understand your worries, but I presume that if the completer will be not installed, no one will notice that it exists. Maybe install completions only when Bash shell is detected on the current system? I feel that https://github.com/scop/bash-completion/blob/master/README.md and https://ddev.readthedocs.io/en/v1.16.7/users/shell-completion/ are good references of a location for completers on UNIX shells. |
I would agree with you in general, but in our case, I'm one of the Fedora maintainers, and Markus is one of the debian maintainers, so between us most linux distros will pick up any packaging changes we make. I'll take a look at the docs and see if we can shoehorn it into setup.py somehow. |
@Vulcalien is this ready to go from your end, or are there more changes you have planned? |
I'm almost done. The only things remaining are the profile and layout completions (--profile=..., --layout=...) and I think the translation for the help messages of Edit: there is an |
There we go, translation files done. I haven't tested them, but I just run the automatic commands, so I don't expect anything to break. |
How is it going on with this PR? Do you need some hands to have work done? |
@Vulcalien is this ready to go now? |
The completion for --profile and --layout is still missing. I've recently been thinking of a solution (maybe make the output of --list-profiles and --list-layouts more bash-friendly). I think it's ready to get merged and in a second moment we can work on this again. |
I've pushed improved bash-completion abrzozowski@fe3e6f0 which supports
Now it's
You're welcome to use this commit The last thing to consider is installing completion to the system |
I'm testing this out. Thanks for making me notice the The new regex for the generic completion makes the options with only one dash not appear, for example I'm modifying the regex to see if I can make it work, thanks for help! Edit: another problem, harder to solve is the profiles/layouts with a quote in the name. Eg. On a related note, creating a profile with both single and double quotes will fail silently. I think we should consider not allowing users to create profiles/layouts with quotes. Update: I changed the output of |
Bash completion is also added for --profile and --layout but it won't work if the profile/layout has quotes or spaces in the name.
The feature doesn't work well for items with spaces or quotes in the name.
Since this PR has been unchanged for 2 months, I think it's a good idea to merge the feature, even if it's partially implemented. Also, there is an under the hood improvement, that would be a good PR on its own. Summary of the changes:
Missing feature:
Here is an attempt at implementing the missing feature: case $prev in
--profile | -p)
COMPREPLY=($(compgen -W "$($1 --list-profiles)"\
-- "$cur"))
return
;;
--layout | -l)
COMPREPLY=($(compgen -W "$($1 --list-layouts)"\
-- "$cur"))
return
;;
esac It doesn't work for profiles/layouts with whitespaces or quotes in the name (e.g. New Layout) |
You're right, this should go in. I'll work on getting the completions working with the spaces as well. I just need to remind myself to do it next time I look at the code. |
Closes #495
First, I had to study how bash completion works. To do so, I simply studied the scripts used by other applications.
Then, I used
sed
and regex in order to scrape the options fromterminator --help
. (I might have nightmares about regex...)In order to make the completion work, I put a symlink to the new file in
/usr/share/bash-completion/completions
namedterminator
.I think this is something the package maintainers have to care about.
Sadly, each shell uses a different type of completion script. This means that this one in particular will only work on bash.
In order to get the options,
terminator --help
has to be run, so there is a very little overhead because python has to start.Edit: the folder where the scripts are put might be different depending on the distro. On Debian it's the one I wrote.