dotter icon indicating copy to clipboard operation
dotter copied to clipboard

[FEATURE] Automatically install shell completions using clap/structopt

Open gbaranski opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe. I'm always frustrated when I want to use program, and I press tab to see available options, but nothing is displayed, or it automatically selects files.

Describe the solution you'd like I'd like to press TAB and see all available options

Describe alternatives you've considered

Additional context Clap can generate completions using https://github.com/clap-rs/clap/tree/master/clap_generate, It's probably also possible when using structopt.

gbaranski avatar May 21 '21 09:05 gbaranski

Seems pretty simple and useful. Will get to this eventually, maybe after some of the pull requests get merged.

SuperCuber avatar May 21 '21 10:05 SuperCuber

when I source the following generated file in my .zshrc

dotter gen-completions --shell "zsh" > dotter-completions.zsh; sed -i '1s;^;#Generated with dotter gen-completions\n;' dotter-completions.zsh

source ../dotter-completions.zsh I get this:

_arguments:comparguments:327: can only be called from completion function

Am I misunderstanding #107? And sorry to "hijack" this [FEATURE] request. It was mentioned :)

salkin-mada avatar Dec 23 '22 11:12 salkin-mada

I haven't used this myself and not too knowledgeable in completions generation. maybe @TheCactusVert can help since they probably got it working when testing the PR

SuperCuber avatar Dec 23 '22 16:12 SuperCuber

source (or .) is only reading commands from a file and executing them in the current shell environment. What you really want is zsh calling this function every time you write dotter and press tab, so you must do the following instructions:

mkdir $HOME/.local/zsh/functions # Create a folder to contain all your functions wherever you want them
dotter gen-completions --shell "zsh" >> $HOME/.local/zsh/functions/_dotter.zsh # The file must have the same name as the executable whith _ in front
fpath=($HOME/.local/zsh/functions $fpath) # Add your autocompletions function to your function path # This line must be added in your .zshrc before compinit to be permanent

TheCactusVert avatar Dec 23 '22 20:12 TheCactusVert

Also I should've closed this issue when merging the PR :) feel free to continue conversation here

SuperCuber avatar Dec 24 '22 11:12 SuperCuber