[zsh] Completion plugin



Version FR en bas

Hi there,

I am currently creating a ZSH completion plugin for the cli interface of Yunohost. Before continuing, I would like to know if someone has already tried that before, as it is beginning to be very tedious :sweat_smile:
(Tedious, or maybe I’m just doing it wrong :upside_down_face: )

Anyway, here is the current status of my work [1]. I am open to any remark to on it. It is in a working state, there is looots of stuff to improve, and much more to be done. Currently, only the yunohost user and yunohost domain parts are kind of dealt with. The yunohost app is written, but untested, sorry :slightly_frowning_face:

So, if you have any remarks or advices about my work, I would be happy to hear them :blush:

Salut !

Je suis en train d’écrire un plugin d’autocompletion pour ZSH et Yunohost. Avant de continuer, je me demandais juste si quelqu’un s’y était déjà attaqué, vu que ça commence à être un peu répétitif et laborieux (ou alors, c’est juste moi qui m’y prends mal… :upside_down_face:)

En tout cas, je pose ici [1] là où j’en suis. C’est vraiment une version de travail, toute bugguée et pas finie, soyez gentils :sweat_smile: Je considère que les fonctions yunohost user et yunohost domain sont à peu près bonnes, à quelques détails près, et pour yunohost app, c’est juste écrit, mais pas testé (oui, je sais, les gens bien ne publient pas sans avoir testé… :frowning_face:). Le reste n’existe pas.

Du coup, je me pointe ici pour avoir un retour sur ce que je suis en train de faire, si ça intéresse des gens. Je suis preneur des conseils ou remarques que vous pourriez avoir :slight_smile:

[1] https://framabin.org/p/?f9dbde4ac576b8ab#ZH/TkcUW5WMRWpAGd6BocTy/4fT3lH++fQGHcXwkNn4=
Will be available only for one week, I’ll repost it if needed, no worries
Dispo juste pendant une semaine, je le reposeterai si besoin, pas d’inquiétude

05-01-2019 : updated link, doesn’t crash automatically anymore


I know nothing about zsh but that looks fancy.

Isn’t there any way that this could be generated somewhat automatically from the action map ? https://github.com/YunoHost/yunohost/blob/stretch-unstable/data/actionsmap/yunohost.yml


Bonjour, c’est cool de proposer ça. Je suis un grand utilisateur de ZSH mais je ne suis pas un habitué de ce type de développement. Je ne serai donc pas te dire si tu t’y prends correctement ou pas mais j’imagine que tu t’es inspiré d’autres réalisations ?


Thanks for the suggestion ! :slight_smile: I didn’t knew about that map. A somewhat functionnal completion plugin could be generated from it, but it would lack some information I think.

Typically, I would like to provide system dependent lists for commands like yunohost app info <tab>, the content of <tab> being fetch from yunohost app list -i. I don’t see how this can be achived directly from the map, without having to add extra information after the generation of the zsh’s plugin. :confused:

@rds13 : Je n’ai pas du tout l’habitude de faire ce genre de trucs. Je viens de passer à zsh il y a quelques semaines, et, horreur, y’a pas de complétion pour YunoHost ! :scream: Du coup, je me lance, à l’arrache, en regardant comment c’est fait ailleurs :sweat_smile:

J’ai pas mal galéré à trouver une façon de faire pas trop moche pour les commandes à tiroir de Yunohost (les yunohost <cmd1> <cmd2> --option <cmd3> <arg_cmd3>, mais ça a l’air de fonctionner de ce que je vois.

Je mettrai à jour le lien du post d’ouverture quand j’aurai un truc qui couvrira une majeure partie de l’application.


Ah yeah I see… What you want to achieve is one order of magnitude higher than what I was thinking about :stuck_out_tongue: Yet I really think you should aim to automatize things, so that the autocompletion plugin can evolve automatically as yunohost evolve … (if you’re aiming for a long-term thing)

So about this problem with autocompletion of arguments, don’t you think we imagine to add keys or annotation or idk to the roadmap so that this kind of info could be contained in it ?

For instance :

        ### app_info()
    action_help: Get information about an installed app
    api: GET /apps/<app>
           help: Specific app ID
               from: app list --installed
               key: id

I don’t know / haven’t though about all the use case though so I don’t know if we can really imagine something that would cover all of them


As I haven’t yet been through all possible cases, I can’t precisely answer to that. It should be possible to have an autocomplete property where it’s needed, maybe in a more generic form, as completion from a file instead of a command may be needed.
For instance:

### app_setting()
            action_help: Set or get an app setting value
            api: GET /apps/<app>/settings
                    help: App ID
                        from: app list --installed
                        key: id
                    help: Key to get/set
                        from: /etc/yunohost/<app>/settings.yml
                        key: keys

Anyway. You are right about generating this file automatically from the actionmap file. I will come back here if I manage to write something not too ugly :slight_smile:


Alright ! I know that it’s probably a bit more meta and technical but I think it’s worth it :wink: I’m not particularly a zsh fanboy or anything (I think i prefer the bash vanilla experience) but if that significantly improves the UX for people using the CLI (and not willing to run ten commands with --help to know how to build the command) that would be really great to integrate this in yunohost on the long-term.

Also don’t hesitate to come discuss and ask questions if you need, on the dev chatroom : https://yunohost.org/#/chat_rooms