Skip to content
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

Auto tab completion for bash #35450

Open
RonaldBarnes opened this issue Nov 27, 2022 · 4 comments · May be fixed by #35451
Open

Auto tab completion for bash #35450

RonaldBarnes opened this issue Nov 27, 2022 · 4 comments · May be fixed by #35451

Comments

@RonaldBarnes
Copy link

How to use GitHub

  • Please use the 👍 reaction to show that you are interested into the same feature.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

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, stecman/symfony-console-completion#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

  • build an alias for the user by detecting system settings (web server user, path of occ, etc.)
    • i.e. alias occ='sudo --user www-data php /var/www/nextcloud/occ'
  • run the alias
  • add the alias to the user's ~/.bash_aliases for persistence
  • add the alias to the SUDO_USER's .bash_aliases for persistence
  • run the complete.occ script to enable bash tab completion
  • copy the complete.occ script to directory so it's run each time bash is started
    • (i.e. /etc/bash_completion.d/)
  • set appropriate file owner and write permissions on /etc/bash_completion.d/complete.occ
  • verify that the file owner of occ is the same as the web server user detected

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 RonaldBarnes added 0. Needs triage Pending check for reproducibility or if it fits our roadmap enhancement labels Nov 27, 2022
@RonaldBarnes RonaldBarnes linked a pull request Nov 27, 2022 that will close this issue
6 tasks
@RonaldBarnes
Copy link
Author

RonaldBarnes commented Nov 28, 2022

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
Copy link
Author

RonaldBarnes commented Nov 28, 2022

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
Copy link
Author

RonaldBarnes commented Nov 28, 2022

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
Copy link

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

@joshtrichards joshtrichards added 3. to review Waiting for reviews and removed 0. Needs triage Pending check for reproducibility or if it fits our roadmap labels Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants