-
Notifications
You must be signed in to change notification settings - Fork 595
Add first version of zsh completion #3864
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
Conversation
If we put it in src, we could run it through gcc and remove options which are disable at compile time. |
That's an interesting idea. Put it through cpp as part of "make" in src/firejail and plenty #ifdef in a _firejail.cpp which then generates a _firejail? Can do. |
Yes, like this. Except that I would use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorting all this would simplify future maintenance. For example --seccomp
, --seccomp.blocksecondary
and --seccomp.drop
are at three different places.
Aside notes:
- we should also pre-process bash-completions
- some of our
--help
descriptions are wrong/outdated/incomplete or can be improved in other ways.
src/zsh_completion/_firejail.in
Outdated
} | ||
|
||
_firejail_args=( | ||
'(--profile)'{--profile=,--profile=}'[use a custom profile]: : _files -g "~/.config/firejail/*.profile"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I type firejail --profile=
and press tab, only directories in the current working directory are shown (no files from cwd; files from cwd will be complete after you begin to enter them) and $HOME/.config/firejail/*.profile
.
It would be nice to show/complete files from cwd and profile names for firejail --profile=<PROFILE-NAME> foo
(e.g. firejail --profile=shellcheck foo
) too. Maybe we can reuse a modified version of _profiles
and _all_profiles
https://github.com/rusty-snake/fjp/blob/fa79d89504d425906a84590758137d1fa12b58fc/build.rs#L28-L57.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean. Let me look into that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this
'(--foo)'{--foo=,foo=}
syntax, I could find anything about it?
The (--foo) means: don't show this option again once a --foo option was given.
The {--foo=,--foo=} is usually for short and long options, e.g. {-f,--foo}, but since firejail does not have those, it's twice the same. I cannot remove it and I cannot remove the 2nd argument either.
The docs at http://zsh.sourceforge.net/Guide/zshguide06.html (section 6.8.2) write correctly:
The function _arguments has been described as having
the syntax from hell', but with the arguments already laid out in front of you it doesn't look so bad. The are three types of argument: options to _arguments itself, arguments saying how to handle options to the command (i.e.
p4 diff'), and arguments saying how to handle normal arguments to the command.
Using cpp for shell scripts turns out to be a bad idea and I had to work around small issues, but it's done and it works. Using unifdef would have been better, but that's another build dependency. |
I've less experience with autotools too, so this need to do some one else.
If it works now, very thing is good. But if we have future trouble with it, we may just use preproc.awk for it. What's this |
--profile is much better now. I did not know you can simply list the profile name without .profile. In fact, adding .profile to a system profile causes an error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I tested this, sorry for the delay. IMO this can be merged once the points below are solved:
-
src/zsh_completion/README.md
can be removed (we install it) -
--profile=
can only work with name of .profile but not .local or .inc -
_PREFIX_
does not fork when configured with--prefix=/usr
, sysconfdir should be used instead. (sysconfdir=@sysconfdir@
is in common.mk) - (optional) rebase and squash
Don't have duplicate descriptions and put = signs where they belong to zsh completion function now dynamically adjusts for options (e.g. no --apparmor option without AppArmor configured) No EXTRA_CFLAGS for cpp Found main.c which does the argument processing. Moved some arguments into the correct #ifdef blocks Profile selection now much better Not more cpp. Using preproc.awk instead. Updated bash firejail command completion to add profiles ignore bash and zsh dynamically created completion scripts Moved bash/zsh completions out of ALL_ITEMS to fix make install Cleanup
Thanks for the review! All done. Including the git rebase/squash. |
It's squashed, that's right. However, a37ffc3 has all the other commits as parents.
Aside: Using feature-branches is often easier to rebase and allows to have multiple open PRs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There a lot more that can be done in the future like suggesting binaries for private-bin
or no suggesting mutually exclusive options such as --profile
and --noprofile
. I will definitely add more features.
Thanks a lot for this. While I use git for a long time, this is the first time I rebase/squash. While I eventually would have figured it out, it's nice to see a working solution.
Live and learn 👍 |
From experience: once there's something it's much easier to build on that and extend it. And that was part of my plan: have zsh completion basically working so other people can easily add one new feature or two. |
why was this closed? |
Hmm...stupidity by the user? Me in this case? |
Thanks for this contribution! |
For consistency, use the conventional autoconf variable name (see also config.mk.in). Commands used to search and replace: $ git grep -Ilz '_SYSCONFDIR_' | xargs -0 \ perl -pi -e 's/_SYSCONFDIR_/\@sysconfdir\@/' Added on commit a37ffc3 ("Add first version of zsh completion", 2021-01-02) / PR netblue30#3864.
Adding a zsh completion script. Tested extensively for the options I use a lot.
I put the file into contrib/zsh_completion instead of src/ where the bash_completion is as makes more sense to me. Feel free to move it around if you prefer. Or move the back_completion into contrib/