wayshot icon indicating copy to clipboard operation
wayshot copied to clipboard

Implemented completions for various shell

Open Rishik-Y opened this issue 8 months ago • 7 comments

Implements auto-completion for various shells such as Bash, fish, zsh, powershell, elvish etc

Example:

wayshot - [TAB]
-s                      --extension
-c                      --format
-l                      --output-format
-o                      --encoding
-h                      --list-outputs
-V                      --output
--clipboard             --choose-output
--log-level             --generate-completions
--slurp                 --help
--cursor                --version

or

wayshot --output-format [TAB]
jpg   png   ppm   qoi   webp  

Rishik-Y avatar Mar 08 '25 19:03 Rishik-Y

This is still work in progress (Works fine with Bash but not tested yet with others), I was unable to figure put what was exactly the conflict when trying to sync no matter how much i try So figured to directly put it here and leave it to PR to show the conflict directly to me

But If anyone would like to, Do test it out and tell me its flaws :)

Rishik-Y avatar Mar 08 '25 19:03 Rishik-Y

You can use the function in clap to generate completions, not by writing in hand

For example https://github.com/neocmakelsp/neocmakelsp/blob/master/src%2Fshellcomplete.rs#L1-L16

Decodetalkers avatar Mar 09 '25 00:03 Decodetalkers

Hi @Decodetalkers, Could you check the code once? The only issue i seem to face was .bashrc not existing would crash the code, which was fixed by adding generate .bashrc if doesnt exist. Other than that I am pretty sure all of them work pretty fine.

Rishik-Y avatar Mar 11 '25 10:03 Rishik-Y

There were 2 more shells which we can implement for using clap_complete but skipped, One being Elvish, However it seems elvish being pre-1.0 seems to have made some changes which doesnt work with current clap_complete and powershell, Which pretty sure works however i cant understand where exactly the completions are being stored since Powershell exists as pkgs for NixOS

Rishik-Y avatar Mar 11 '25 10:03 Rishik-Y

There were 2 more shells which we can implement for using clap_complete but skipped, One being Elvish, However it seems elvish being pre-1.0 seems to have made some changes which doesnt work with current clap_complete and powershell, Which pretty sure works however i cant understand where exactly the completions are being stored since Powershell exists as pkgs for NixOS

I think just printing the completions is enough, if we need to install it to some place, we maybe need to think about it more. If just printing, then it is just the job of packagers.

Decodetalkers avatar Mar 11 '25 11:03 Decodetalkers

Side note: clap_complete_nushell can be used for generating nushell completions. It's part of official clap suite too, though I don't know the reasons it's separate from clap_complete

Gigas002 avatar Mar 18 '25 01:03 Gigas002

Ahh! Thanks for mentioning this I Knew clap_complete_nushell existed for nushell but i just roughly saw it via here where it was showcasing as read-only making it turn off for me. But Thanks for notifying, now that i know that it exists with clap-rs and is maintained, Will start working on it in a week after my exams get over

Rishik-Y avatar Mar 19 '25 04:03 Rishik-Y