I would urge you to look at that output.

That's not fish code, it's simply the default usage output. So it seems
that it just simply does not support fish.

Note that this kind of "source this tools output" is an anti-pattern.
There's no reason to constantly run the tool again and again. If a tool
offers this, you can save the output in a file and source that.

The usual way to support fish's completion is to simply ship a completion
script (or submit it for inclusion in fish-shell). Another possibility is
to ship a tool that fish (or any other shell) can pass a commandline to, so
it can actually contain some logic.

On Fri, Jul 21, 2017 at 5:01 PM Florian Dhaussy <florian.dhau...@elosi.com>
wrote:

> Oh okay, so I totally misunderstood the way that `source` work in fish ^^.
>
> Here is the result of the first command:
>
> #> env _MOLECULE_COMPLETE=source-fish molecule
> Usage: molecule [OPTIONS] COMMAND [ARGS]...
>
>    _____     _             _
>   |     |___| |___ ___ _ _| |___
>   | | | | . | | -_|  _| | | | -_|
>   |_|_|_|___|_|___|___|___|_|___|
>
>   Molecule aids in the development and testing of Ansible roles.
>
>   Enable autocomplete issue:
>
>     autoload bashcompinit && bashcompinit # zsh
>
>     eval "$(_MOLECULE_COMPLETE=source molecule)"
>
> Options:
>   --debug / --no-debug  Enable or disable debug mode. Default is disabled.
>   --version             Show the version and exit.
>   --help                Show this message and exit.
>
> Commands:
>   check        Use a provisioner to perform a Dry-Run...
>   converge     Use a provisioner to configure instances...
>   create       Start instances.
>   dependency   Mange the role's dependencies.
>   destroy      Destroy instances.
>   destruct     Use a provisioner to destruct instances.
>   idempotence  Use a provisioner to configure the instances...
>   init         Initialize a new role or scenario.
>   lint         Lint the role.
>   list         Lists status of instances.
>   login        Log in to one instance.
>   syntax       Use a provisioner to syntax check the role.
>   test         Test (destroy, create, converge, lint,...
>   verify       Run automated tests against instances.
>
> And adding your modification to ~/.config/fish/completions/molecule.fish
> gave me this output when I tab after `molecule`:
>
> #>molecule - (line 4): Expected a command, but instead found a pipe
>   |     |___| |___ ___ _ _| |___
>
>   ^
> from sourcing file -
>     called on line 3 of file ~/.config/fish/completions/molecule.fish
>
> from sourcing file ~/.config/fish/completions/molecule.fish
>     called on standard input
>
> in command substitution
>     called on standard input
>
> source: Error while reading file “-”
>
> And using it with `eval (env _MOLECULE_COMPLETE=source-fish molecule)` :
>
> #> molecule - (line 1): Expected a command, but instead found a
> pipe
> ven. 21 juil. 2017 16:56:04 CEST
> begin; Usage: molecule [OPTIONS] COMMAND [ARGS]...     _____
> _             _   |     |___| |___ ___ _ _| |___   | | | | . | | -_|  _| |
> | | -_|   |_|_|_|___|_|___|___|___|_|___|    Molecule aids in the
> development and testing of Ansible roles.    Enable autocomplete
> issue:      autoload bashcompinit && bashcompinit # zsh      eval
> "$(_MOLECULE_COMPLETE=source molecule)"  Options:   --debug / --no-debug
> Enable or disable debug mode. Default is disabled.   --version
> Show the version and exit.   --help                Show this message and
> exit.  Commands:   check        Use a provisioner to perform a Dry-Run...
> converge     Use a provisioner to configure instances...   create
> Start instances.   dependency   Mange the role's dependencies.
> destroy      Destroy instances.   destruct     Use a provisioner to
> destruct instances.   idempotence  Use a provisioner to configure the
> instances...   init         Initialize a new role or scenario.
> lint         Lint the role.   list         Lists status of instances.
> login        Log in to one instance.   syntax       Use a provisioner to
> syntax check the role.   test         Test (destroy, create, converge,
> lint,...   verify       Run automated tests against instances.
>
> ^
> from sourcing file -
>     called on line 60 of file /usr/share/fish/functions/eval.fish
>
> in function “eval”
>     called on line 3 of file ~/.config/fish/completions/molecule.fish
>
> from sourcing file ~/.config/fish/completions/molecule.fish
>     called on standard input
>
> in command substitution
>     called on standard input
>
> source: Error while reading file “-”
>
> Not sure if this autocomplete framework is compatible with fish.
>
>
> ------------------------------
> *De: *"Fabian Homborg" <fhomb...@gmail.com>
> *À: *"Florian Dhaussy" <florian.dhau...@elosi.com>, "fish-users" <
> fish-users@lists.sourceforge.net>
> *Envoyé: *Vendredi 21 Juillet 2017 14:52:19
> *Objet: *Re: [Fish-users] Adding completion for a click framework
> compatible program
>
> That failing code isn't valid fish script - it's for bash's completion
> framework, which is wholly incompatible. So the "source" mode here doesn't
> work for fish.
>
> What exactly is the issue with the "source-fish" mode? Can you post the
> output of `env _MOLECULE_COMPLETE=source-fish molecule`?
>
> Also, `eval` here adds a bit of overhead. If you don't need the command to
> have access to stdin, you can just pipe to `source` - `env
> _MOLECULE_COMPLETE=source-fish molecule | source`.
>
> On Fri, Jul 21, 2017 at 10:41 AM Florian Dhaussy <
> florian.dhau...@elosi.com> wrote:
>
>> Hi fish community !
>>
>> I'm actually trying to get completion on molecule
>> <https://github.com/metacloud/molecule> (a development helper for
>> Ansible). This program is in python, and include the click-completion
>> framework <https://github.com/click-contrib/click-completion> for
>> auto-completion.
>>
>> Following the click documentation (as also the one from fish), I created
>> a ~/.config/fish/completions/molecule.fish:
>>
>> # molecule.fish - molecule completions for fish shell
>>
>> eval (env _MOLECULE_COMPLETE=source molecule)
>>
>> I've just modified source-fish by only source, because it seems not
>> recognized by fish.
>>
>> When I'm trying to auto-complete the command with tab, here is the result:
>>
>> #> molecule - (line 1): Illegal command name “_molecule_completion()”        
>>                                                                              
>>                          ven. 21 juil. 2017 09:57:46 CEST
>> begin; _molecule_completion() {     COMPREPLY=( $( env 
>> COMP_WORDS="${COMP_WORDS[*]}" \                    COMP_CWORD=$COMP_CWORD \  
>>                   _MOLECULE_COMPLETE=complete $1 ) )     return 0 }  
>> complete -F _molecule_completion -o default molecule;
>>        ^
>> from sourcing file -
>>      called on line 60 of file /usr/share/fish/functions/eval.fish
>>
>> in function “eval”
>>      called on line 3 of file ~/.config/fish/completions/molecule.fish
>>
>> from sourcing file ~/.config/fish/completions/molecule.fish
>>      called on standard input
>>
>> in command substitution
>>      called on standard input
>>
>> source: Error while reading file “-”
>>
>>
>> Do you have any idea to suggest ? Does it come from my completion command
>> in molecule.fish ?
>>
>> Thanks for your time :).
>>
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> Fish-users mailing list
>> Fish-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/fish-users
>>
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to