SuperCuber / dotter

A dotfile manager and templater written in rust 🦀
The Unlicense
882 stars 46 forks source link

[FEATURE] Automatically install shell completions using clap/structopt #65

Closed gbaranski closed 1 year ago

gbaranski commented 3 years ago

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.

SuperCuber commented 3 years ago

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

salkin-mada commented 1 year ago

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 :)

SuperCuber commented 1 year ago

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

TheCactusVert commented 1 year ago

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
SuperCuber commented 1 year ago

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