# \[zsh\] Completion plugin

**URL:** https://forum.yunohost.org/t/zsh-completion-plugin/7016
**Category:** Contribute Room
**Tags:** french, english
**Created:** [February 3, 2019, 7:11pm UTC](https://forum.yunohost.org/t/zsh-completion-plugin/7016 "2019-02-03T19:11:36Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Fol](https://forum.yunohost.org/user_avatar/forum.yunohost.org/fol/32/2462_2.png) [@Fol](https://forum.yunohost.org/u/Fol)
#### Post date: [February 3, 2019, 7:11pm UTC](https://forum.yunohost.org/t/zsh-completion-plugin/7016/1 "2019-02-03T19:11:36Z")

</div>

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 😅  
(Tedious, or maybe I’m just doing it wrong 🙃 )

Anyway, here is the current status of my work [[1]](https://framabin.org/p/?f9dbde4ac576b8ab#ZH/TkcUW5WMRWpAGd6BocTy/4fT3lH++fQGHcXwkNn4=). 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 🙁

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

* * *

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… 🙃)

En tout cas, je pose ici [[1]](https://framabin.org/p/?f9dbde4ac576b8ab#ZH/TkcUW5WMRWpAGd6BocTy/4fT3lH++fQGHcXwkNn4=) là où j’en suis. C’est vraiment une version de travail, toute bugguée et pas finie, soyez gentils 😅 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é… ☹). 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 🙂

* * *

[1] [https://framabin.org/p/?f9dbde4ac576b8ab#ZH/TkcUW5WMRWpAGd6BocTy/4fT3lH++fQGHcXwkNn4=](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_

---

<div class="post-metadata">

### Author: ![Aleks](https://forum.yunohost.org/user_avatar/forum.yunohost.org/aleks/32/1704_2.png) [@Aleks](https://forum.yunohost.org/u/Aleks)
#### Post date: [February 4, 2019, 9:07pm UTC](https://forum.yunohost.org/t/zsh-completion-plugin/7016/2 "2019-02-04T21:07:46Z")

</div>

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](https://github.com/YunoHost/yunohost/blob/stretch-unstable/data/actionsmap/yunohost.yml)

---

<div class="post-metadata">

### Author: ![rds13](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/r/73ab20/32.png) [@rds13](https://forum.yunohost.org/u/rds13)
#### Post date: [February 4, 2019, 9:08pm UTC](https://forum.yunohost.org/t/zsh-completion-plugin/7016/3 "2019-02-04T21:08:15Z")

</div>

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 ?

---

<div class="post-metadata">

### Author: ![Fol](https://forum.yunohost.org/user_avatar/forum.yunohost.org/fol/32/2462_2.png) [@Fol](https://forum.yunohost.org/u/Fol)
#### Post date: [February 5, 2019, 12:29am UTC](https://forum.yunohost.org/t/zsh-completion-plugin/7016/4 "2019-02-05T00:29:28Z")

</div>

@Aleks  
Thanks for the suggestion ! 🙂 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. 😕

* * *

@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 ! 😱 Du coup, je me lance, à l’arrache, en regardant comment c’est fait ailleurs 😅

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.

---

<div class="post-metadata">

### Author: ![Aleks](https://forum.yunohost.org/user_avatar/forum.yunohost.org/aleks/32/1704_2.png) [@Aleks](https://forum.yunohost.org/u/Aleks)
#### Post date: [February 5, 2019, 12:41am UTC](https://forum.yunohost.org/t/zsh-completion-plugin/7016/5 "2019-02-05T00:41:59Z")

</div>

> [@Fol](#):
>
> 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.

Ah yeah I see… What you want to achieve is one order of magnitude higher than what I was thinking about 😛 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 :

```auto
        ### app_info()
info:
    action_help: Get information about an installed app
    api: GET /apps/<app>
    arguments:
        app:
           help: Specific app ID
           autocomplete:
               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

---

<div class="post-metadata">

### Author: ![Fol](https://forum.yunohost.org/user_avatar/forum.yunohost.org/fol/32/2462_2.png) [@Fol](https://forum.yunohost.org/u/Fol)
#### Post date: [February 5, 2019, 2:56pm UTC](https://forum.yunohost.org/t/zsh-completion-plugin/7016/6 "2019-02-05T14:56:36Z")

</div>

> [@Aleks](#):
>
> 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:

```auto
### app_setting()
    setting:
            action_help: Set or get an app setting value
            api: GET /apps/<app>/settings
            arguments:
                app:
                    help: App ID
                    autocomplete:
                        from: app list --installed
                        key: id
                key:
                    help: Key to get/set
                    autocomplete:
                        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 🙂

---

<div class="post-metadata">

### Author: ![Aleks](https://forum.yunohost.org/user_avatar/forum.yunohost.org/aleks/32/1704_2.png) [@Aleks](https://forum.yunohost.org/u/Aleks)
#### Post date: [February 5, 2019, 3:00pm UTC](https://forum.yunohost.org/t/zsh-completion-plugin/7016/7 "2019-02-05T15:00:48Z")

</div>

Alright ! I know that it’s probably a bit more meta and technical but I think it’s worth it 😉 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](https://yunohost.org/#/chat_rooms)

---

<div class="post-metadata">

### Author: ![Fol](https://forum.yunohost.org/user_avatar/forum.yunohost.org/fol/32/2462_2.png) [@Fol](https://forum.yunohost.org/u/Fol)
#### Post date: [April 25, 2020, 6:33pm UTC](https://forum.yunohost.org/t/zsh-completion-plugin/7016/8 "2020-04-25T18:33:05Z")

</div>

Hello,  
I am in a mood of ressurecting this idea 🙃

The way I am more inclined to do it is like suggested by Aleks, adding an property `autocomplete: {from: .... ; key: ... }`, where `key` would typically be a `jq` filter, as this tool seems to be installed by default (correct me if I’m wrong).

However, the properties `pattern` and `metavar` are puzzling me. I initially thought (a few day ago when unearthing this project 😅) that one of them could be of help.  
I did not got how those are used in the code however, and thus I don’t know if/how they could be used 🧐

---

<div class="post-metadata">

### Author: ![Fol](https://forum.yunohost.org/user_avatar/forum.yunohost.org/fol/32/2462_2.png) [@Fol](https://forum.yunohost.org/u/Fol)
#### Post date: [July 31, 2020, 2:44pm UTC](https://forum.yunohost.org/t/zsh-completion-plugin/7016/9 "2020-07-31T14:44:15Z")

</div>

Sooo… I have finally something worth showing, and kinda usable!

This conversation should continue on Github I guess, as a PR in the main repo?

Anyway, if someone wants to check that zsh completion plugin, it is here. It work, but there is lots of room for improvement (naming, coding style, architectural choices, …)

> **[buzuck/yunohost](https://github.com/buzuck/yunohost/tree/enh-zsh-completion)**
>
> YunoHost is an operating system aiming to simplify as much as possible the administration of a server. This repository corresponds to the core code, written mostly in Python and Bash. - buzuck/yuno...

* * *

Edit: Actually, the PR will wait a bit, I have to recheck my code first, and add lots of comments ^^’

* * *

2nd edit: PR done! It’s my first, so I hope I didn’t make it too badly ^^’
