nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
26.23k stars 3.95k forks source link

Auto tab completion for bash #35450

Open RonaldBarnes opened 1 year ago

RonaldBarnes commented 1 year ago

How to use GitHub

Is your feature request related to a problem? Please describe. Having bash tab/auto completion for occ would make administration much easier.

The current method is not discoverable (multiple NextCloud admins had no idea it existed), and requires fiddling with file ownership / permissions. #14309, https://github.com/stecman/symfony-console-completion/issues/71.

Describe the solution you'd like A method of invoking bash tab completion that is obvious and works like other bash completions.

Describe alternatives you've considered A script, bash-add-alias.sh that will

Additional context Pull request is ready for testing. Needs better OS agnostic support (i.e. different web server user names and bash_completion.d directory locations).

RonaldBarnes commented 1 year ago

Example

bash-add-alias.sh

User is prompted before any changes made:

# . ./bash-add-alias.sh
Web server user name: "www-data".
Alias for occ command not found for user "root".
Run "alias occ='sudo --user www-data php /var/www/nextcloud/occ'" (y/N)? Y
alias occ='sudo --user www-data php /var/www/nextcloud/occ'
Add alias to /root/.bash_aliases? (y/N) N
Add alias to /home/ron/.bash_aliases? (y/N) N
Run bash completion script complete.occ?  (Y/n) Y
Running /var/www/nextcloud/complete.occ ... success.
Add complete.occ to /etc/bash_completion.d? (y/N) N
DONE.
RonaldBarnes commented 1 year ago

Example

occ tab completion

Run occ successfully from any directory, not just in the nextcloud directory (no occ in current dir in this example):

root@(dell):/tmp/nextcloud-occ-bash-completion# occ[TAB]
activity:        encryption:      memories:        text:
app:             federation:      notification:    theming:
background:      files:           onlyoffice:      trashbin:
background-job:  group:           preview:         twofactorauth:
broadcast:       help             recognize:       update:
check            integrity:       security:        upgrade
circles:         l10n:            serverinfo:      user:
config:          list             sharing:         versions:
dav:             log:             status           workflows:
db:              maintenance:     tag:
deck:            maps:            talk:
root@(dell):/tmp/nextcloud-occ-bash-completion# occ
RonaldBarnes commented 1 year ago

Example

occ tab completion for options / switches

Access all options / switches by starting word with -:

root@(dell):/tmp/nextcloud-occ-bash-completion# occ -[TAB]
--ansi            --no-ansi         --quiet           --version
-h                --no-interaction  -v                -vv
--help            --no-warnings     -V                -vvv
-n                -q                --verbose
root@(dell):/tmp/nextcloud-occ-bash-completion# occ -
j-lakeman commented 1 month ago

Would also love to see this! Once implemented, it should be easy to port it to zsh and fish shell as well.