datafolklabs / cement

Application Framework for Python
http://builtoncement.com
BSD 3-Clause "New" or "Revised" License
1.23k stars 119 forks source link

Fish shell completion for cement itself. #651

Open tomclad opened 1 year ago

tomclad commented 1 year ago

System Information

request I request you to include this cement completion file in cement. I am submitting this through issues is because I don't know how to modify and submit PR for cement. I am new to github and programming in general.

I request you to install cement.fish file in users ~/.config/fish/completions/ in future cement realeases. shellingham package can be used to detect the shell and if shell is found to be fish it can be installed at above location.

Issue I have been using cement developer tools for creating projects, plugins, extension, etc.

It was tedious to write commands all the time. so I have written fish shell completion for cement. According to fish shell this completion file only needs to saved at one of the following locations here I have put my cement completion file at ~/.config/fish/completions and it works as intended.

as it can be seen from below screenshot.

cement-command-completion-fish

Below script not only supports command completions but also all option completion for cement itself also for generate sub-command. and also supports option completion for sub-commands of generate sub-command. :-)

Fish shell completion file

# file name cement.fish
set -l cement generate
set -l generate plugin extension script project todo-tutorial

# cement options completion
complete -c cement -n "not __fish_seen_subcommand_from $cement" -x -s h -l help -d 'show this help message and exit'
complete -c cement -n "not __fish_seen_subcommand_from $cement" -r -s d -l debug -d 'full application debug mode'
complete -c cement -n "not __fish_seen_subcommand_from $cement" -r -s q -l quiet -d 'suppress all console output'
complete -c cement -n "not __fish_seen_subcommand_from $cement" -x -s v -l version -d 'show program\'s version number and exit'

# cement commands completion
complete -f -c cement -n "not __fish_seen_subcommand_from $cement" -a generate -d 'generate controller'

## generate options completion
complete -c cement -n "__fish_seen_subcommand_from generate;
and not __fish_seen_subcommand_from $generate" -x -s h -l help -d 'show this help message and exit'

### generate sub-commands options completion
complete -f cement -n "__fish_seen_subcommand_from $generate" -x -s h -l help -d 'show this help message and exit'
complete  cement -n "__fish_seen_subcommand_from $generate" -r -s f -l force -d 'force operation if destination exists'
complete  cement -n "__fish_seen_subcommand_from $generate" -r -s D -l defaults -d 'use all default variable values'
complete  cement -n "__fish_seen_subcommand_from $generate" -r -l clone -d 'clone this template to destination path'

## generate sub-commands completion
complete -f -c cement -n "__fish_seen_subcommand_from generate;and not __fish_seen_subcommand_from $generate" -a project -d 'generate project from template'
complete -f -c cement -n "__fish_seen_subcommand_from generate;and not __fish_seen_subcommand_from $generate" -a plugin -d 'generate plugin from template'
complete -f -c cement -n "__fish_seen_subcommand_from generate;and not __fish_seen_subcommand_from $generate" -a extension -d 'generate extension from template'
complete -f -c cement -n "__fish_seen_subcommand_from generate;and not __fish_seen_subcommand_from $generate" -a script -d 'generate script from template'
complete -f -c cement -n "__fish_seen_subcommand_from generate;and not __fish_seen_subcommand_from $generate" -a todo-tutorial -d 'generate todo-tutorial from template'

above file needs to be saved as follows. ~/.config/fish/completions/cement.fish

cheers. :=)

derks commented 11 months ago

@tomclad thank you for the request. Installing Cement itself would not be able to create this file as we only package the Python library and rely on those tools for install (PIP, etc). That said there are some options:

This request is for Cement devtools, though just wanted to note there are some docs for guides on doing this for apps built on Cement and making note here that we should add something for fish there as well: