[kwlug-disc] Bash Autocompletion for NextCloud

Ronald Barnes ron at ronaldbarnes.ca
Sat Nov 26 07:46:50 EST 2022


Bob Jonkman wrote on 2022-11-15 17:30:

> Autocomplete for Nextcloud's occ would be very useful.

Done. Feedback welcome.

TL;DR:

https://github.com/RonaldBarnes/nextcloud-occ-bash-completion/



> I'm currently using an alias to make occ more like a regular
> command:
> 
>> alias occ='sudo -u www-data php -f /var/www/nextcloud/occ'

There's a script that will help with that (for users that don't know how):

* checks for ./occ, prompts user for path if not found
   * path input supports tab-completion
* determines web server user name from (www-data|httpd|nobody)
   * Did I miss any?
* checks for existing alias
* creates alias string, offers to run it
* determines user's name
* checks for occ alias in user's .bash_aliases
* offers to add if if missing
* checks for SUDO_USER's .bash_aliases having occ alias
* offers to add it if missing
* verifies that owner of occ is web server user



> Now if I could get the occ command to autocomplete command,
> subcommands, and parameters it would save me having to open a
> separate terminal just for the 'occ -h' output

occ -[TAB] will auto-complete all the "switches" that start with hyphen(s)
occ [TAB] will show all the commands up to and including the first ":"
occ $some_command:[TAB] will show all subcommands following initial colon


Was interesting - there were >180 commands & subcommands initially; had
to figure out a way to narrow it down to something easier to use.

I think it works rather well now.


Also, the completion script adds colour to the completions' matching
portions.

https://github.com/RonaldBarnes/nextcloud-occ-bash-completion/


Again, feedback welcome!


Also, sorry for the long reply, I used this as a basis for a README.md...


rb






More information about the kwlug-disc mailing list