Skip to content

Print command line completions - #606

Merged
boyter merged 1 commit into
boyter:masterfrom
lihaohong6:master
Apr 15, 2025
Merged

Print command line completions#606
boyter merged 1 commit into
boyter:masterfrom
lihaohong6:master

Conversation

@lihaohong6

Copy link
Copy Markdown
Contributor

This is a prototype for command line completions (#337).

Doing it the same way as other applications potentially interferes with existing scc command line argument parsing. In particular, users may want to count the LOC in the completion sub-directory, so scc completion would lead to unexpected results.

I made it so that command line completions are generated only if the arguments are scc completion --shell [name of shell]. The --shell option should prevent users from accidentally triggering this feature. It's nonetheless still a pretty ugly implementation. Perhaps a more elegant one exists?

@boytertesting boytertesting Bot added S/size Small change VH/complexity Very high complexity labels Apr 15, 2025
@boyter

boyter commented Apr 15, 2025

Copy link
Copy Markdown
Owner

OK I have no idea how this works and thus no way to verify its doing what it needs.

How do I trigger this to verify it?

@lihaohong6

Copy link
Copy Markdown
Contributor Author

It depends on the shell (and possibly the operating system). I'm using Linux through WSL to experiment, so hopefully the procedure is more-or-less the same on macOS if that's what you use.

For zsh, which is what I usually use, I would

  1. Run ./scc completion --shell zsh > _scc to generate shell completions and pipe the output to a file. Underscore + name of executable is usually how zsh completion files are named.
  2. Run sudo cp _scc /usr/share/zsh/site-functions/_scc. This copies the completions file to the location where zsh completion scripts are stored. There are ways to have zsh load completion scripts without superuser privileges, but this is the easiest.
  3. Restart the shell.
  4. Type scc --no- and then press tab. Something along the lines of the screenshot below should appear.
    image

I have a bunch of zsh plugins, so hopefully this applies to a vanilla zsh experience too.

Other shells are pretty similar. For bash, the command would be ./scc completion --shell bash > scc.bash, and the file would be stored in /usr/share/bash-completion/completions. bash requires a double tab to autocomplete, and shows something similar. I haven't customized bash, so this should be easier to reproduce.

image

For fish, the command is ./scc completion --shell fish > scc.fish and the file location is /usr/share/fish/vendor_completions.d. My fish is a fresh install, so it should be easily reproducible.

image

Technically powershell is supported too, but I'm not familiar with that ecosystem. Since everything is autogenerated anyway, I would assume cobra did it correctly.

@boyter

boyter commented Apr 15, 2025

Copy link
Copy Markdown
Owner

Ah gotcha. Im going to merge then and mess around with it. Thanks for this. We can keep track on the linked issue.

@boyter
boyter merged commit 4d544eb into boyter:master Apr 15, 2025
@azizsayfiddin

Copy link
Copy Markdown

Great, I like it. I think changing the completion generation from scc completion --shell zsh to scc --zsh would be more minimalistic, as with fzf zsh completion generation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S/size Small change VH/complexity Very high complexity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants