-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Bash completion #35451
base: master
Are you sure you want to change the base?
Bash completion #35451
Conversation
An example of the script in action, showing user interaction required before any action taken:
|
Works from any folder, even when
Reduce number of choices by typing
Increase choices by typing
And so on:
|
Works with options beginning with
|
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.
Comments on current behavior:
# 1
# Comment: Is having a triling ':' expected ? Not sure if we should remove it or not.
# Having it is weird, but it suggests that occ is expecting something after the ':'.
# How are other software handling that ?
$ occ<tab>
activity: dav: integrity: preview: text: versions:
app: db: l10n: security: theming: workflows:
background: encryption: list serverinfo: trashbin:
background-job: federation: log: sharing: twofactorauth:
broadcast: files: maintenance: status update:
check group: migrations: support: upgrade
config: help notification: tag: user:
# 2
$ occ files:<tab>
files:cleanup files:repair-tree files:scan-app-data
files:recommendations:recommend files:scan files:transfer-ownership
# 3
# Comment: I don't think have the global list of command makes sense here.
# I would maybe expect completion on the options.
$ occ files:scan <tab>
activity: dav: integrity: preview: text: versions:
app: db: l10n: security: theming: workflows:
background: encryption: list serverinfo: trashbin:
background-job: federation: log: sharing: twofactorauth:
broadcast: files: maintenance: status update:
check group: migrations: support: upgrade
config: help notification: tag: user:
Isn't this something that symfony already provides us with as documented in https://github.com/nextcloud/documentation/blob/eae31ad02fa83e218d693f7a79eded3d127e7406/admin_manual/configuration_server/occ_command.rst#enabling-autocompletion ? |
It's odd that there are a couple comments here that I can't seem to reply to. Is this normal; am I missing something? |
According to stecman/symfony-console-completion#71, it doesn't seem work for everyone. The author stated:
Really don't like the idea of changing file/dir permissions within the NC folder to get bash comlpletion working! I imagine a lot of Also - the method at the link you provided doesn't work for me - I copied and pasted the "BASH (any version)" instructions:
Instructions point to different NC directory, adjusting for local instance:
User
Re-created my own
That completion method is not very discoverable - I know multiple NC admins (not full-time admins, but regulars) that had no idea this Symfony method existed. This version is discoverable and functions like every other bash completion. |
Hi again @artonge I couldn't reply directly to your comment, so... "Quote Reply" is here:
Yes, it's an indicator that further subcommands are expected.
I strongly recommend keeping it; it's quite informative.
Precisely.
I am not aware of any other program that expects colon-delimited input like
I like the idea, but I see some problems with implementation.
I do think I could prevent displaying the global list of commands if there is already a word with a colon in it. Also, if there were a list of commands that expect files as final arguments, I could make it so that those commands, followed by [tab], present a list of files and folders from the current directory. I'm unaware of any such commands that operate on files though.
|
…mplete' built-in handles de-duplication and sortation. Signed-off-by: Ronald Barnes <ron@ronaldbarnes.ca>
Completions are now customized to the expectations of the command being run, i.e. a
A user that's been chosen / selected will be filtered from further options:
If
Note: in the case of |
Completions are now customized to the expectations of the command being run, i.e. an
Lengthy list of all apps has pagination handled as any other bash completion (i.e.
|
Completions are now customized to the expectations of the command being run, i.e. an
Having chosen an app, now
|
Since aliases are usually added via alias occ='sudo -u www-data php /var/www/nextcloud/occ' What I suggest is using this script as one time setup script, which adds the resulting single alias line to But otherwise, especially the bash completion itself: Great stuff 👍🚀!! |
The I like the Had to check a bunch of default installs and was surprised this wasn't the standard setup. It's been so long since I created
How about, it is a one-time setup script which builds the single alias line, puts it in
Thank you! Really appreciate that. |
Ah you are right, that is even better.
Btw, So overall, also to allow running the script in shared hostings, it would be great if the script used the user-level directories for both, alias and completion, and the system-wide dirs only when executed as root (and probably still optionally). Ah right, it does things already as one-time-script. Then I wonder whether it's worth it being sourced and setting up everything for the current shell at all? Is it worth the hassle (and still not ruled out 100% risk that the current shell is unintentionally manipulated by the variables, functions and traps) to avoid the need for a |
I thought about creating the file, but I checked a Debian Bullseye (11) and it does not source an aliases file. Same with Fedora 37. Ubuntu 22.04 both defines aliases in
That's good to know, I was not aware.
Initially, I tried to keep changes mostly in the invoking user's environment. I will consider offering to put However, since running Maybe if user has sudoers privileges to run some things as www-data but writing to
I think so. When gaining shell access first time, run the script, and alias and completions are ready to help with the task at hand.
I'm not clear on this part. I may be overlooking something, but the only bit of remaining code that I have concern about is the global var That may affect something somehow somewhere, but I haven't encountered any other completion that depends on it being there and I have not been able to get the completions to work if I (The change affects how the |
Ah I see,
It really depends on the environment. In shared hostings, the provided login user may be the webserver user at the same time, in which case sudo is not required at all. In other cases, the login user might have sudo permissions, but probably not for root. But maybe too many checks aren't great either, at least not for now. We can react to specific environments once users face issues with the script in their particular environment, and otherwise assume/require a login user with sudo permissions, or root itself, for now. Choice for whether to add globally or for current user resp. SUDO_USER only probably via command-line option and/or interactive
I mean, large parts of the scripts deal with traps and unsetting variables, to not mess with the current shell (the script is sourced into) which is all not required when the script is executed instead of sourced. The only downside is that one cannot run
I don't mean the completion script itself (which of course needs to be sourced), but EDIT: Of course these parts are then obsolete/do not work anymore: Run "alias occ='sudo --user www-data php /var/www/nextcloud/occ'" (y/N)? Y
...
Run bash completion script complete.occ? (Y/n) Y But I do not think there are cases where one wants to load the alias + completion only once, and not install it for future logins. |
Interesting issue: if
I now copy** it to ** Only copy it to I'm wondering if it's best to just rename |
The work has been done; I really don't want to undo it. Plus, I should add an option to add the alias to the end of
I haven't had to deal with shared hosting for a long time, but I agree with your conclusion. There'll be a lot of permutations of deployed environments that will reveal issues to work out when they appear.
I wouldn't have thought that an issue. User logs in to server, runs bash script, issues
That seems possible, and is supported. |
Thinking about shared hosting scenarios, maybe instead of throwing error if |
Hello @RonaldBarnes , fyi I'm reopening this and would like to re-discuss this as the feature looks really nice and looks quite complete. |
Thank you, this is great news. I find this tool extraordinarily handy on several Nextcloud instances running different versions - if someone else in the Nextcloud community can make use of it too, that'd be great! |
Summary
Add bash completion for
occ
TODO
bash_completion.d
directory locationsChecklist