Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interest for completion? (zsh) #297

Closed
moviuro opened this issue May 24, 2018 · 13 comments

Comments

@moviuro
Copy link
Contributor

@moviuro moviuro commented May 24, 2018

Hi,

I'm trying my hand at zsh completion. Would it be interesting for the cbsd project to ship a zsh completion script?

It won't be ready to ship right now, though, I'm guessing some weeks of work on my end will be necessary.

Cheers,

@olevole

This comment has been minimized.

Copy link
Collaborator

@olevole olevole commented May 24, 2018

Hi,
Yes, it would be nice to put these files in the CBSD code base (e.g in share directory), and/or update README.

Hhm, some time ago I enjoyed with bash completion. However, I can not find how I did it ;)
I think, together with yours zsh completion i've restore and put bash completion.

By the way, I saw some interesting solutions for popup/tooltip completion. E.g:

https://github.com/cloudnativelabs/kube-shell ( uses https://github.com/jonathanslenders/python-prompt-toolkit )

or there is a more suitable solution for CBSD:

https://github.com/jhawthorn/fzy
https://github.com/garybernhardt/selecta

I have been thinking for a long time to build them in cbsd shell ( /usr/local/bin/cbsd )
But I'm not sure that everyone will like it ;-)

So, fill free to add zsh completion script, this is very useful!

@moviuro

This comment has been minimized.

Copy link
Contributor Author

@moviuro moviuro commented May 24, 2018

👍

Though I was thinking of some more "usual" behavior, using http://zsh.sourceforge.net/Doc/Release/Completion-System.html (which is not trivial)

# cbsd <TAB>
completing command
jexec          -- [jail] execute command in jail
jconstruct-tui -- [jail] dialog to configure a jail
[...]
# cbsd jexec <TAB>
completing jexec options
jname=   -- in which jail to jexec
user=    -- whom to impersonate
completing command
at ls dd [...]
cp rm xz
# cbsd jexec jname=<TAB>
completing jname
*       haproxy    [...]
unbound nextcloud

I'll be publishing my completion when at least jexec works correctly.

@olevole

This comment has been minimized.

Copy link
Collaborator

@olevole olevole commented May 24, 2018

Wow! this requires some modification from the CBSD side ? Each cbsd script (except --help args) can display the available parameters via --args: 'cbsd <script> --args'. Maybe it can be adapted or or modified somehow for completion. I will try to read about zsh completion on the weekend

@moviuro

This comment has been minimized.

Copy link
Contributor Author

@moviuro moviuro commented May 24, 2018

No, it requires no modification to the cbsd code (so far).

However, I do parse cbsd's output. For example, for the jname= part, I use the following code:

__cbsd-jls-for-jexec() {
  cbsd jls display=status,jname | awk '{ if ( $1 ~ "On" ) print $2 }'
  printf '%s\n' '\\\*'
}
@moviuro

This comment has been minimized.

Copy link
Contributor Author

@moviuro moviuro commented May 24, 2018

I have the following code ATM, http://ix.io/1biJ (put in a file _cbsd somewhere along other completion files).

It:

  • Completes the subcommand, and displays it with a short help text.
  • Completes cbsd jexec with --help or jname= and helps select the jail
  • Displays cbsd jexec --help if you try to tab your way through it
  • Completes user= with users from the selected jail (unless you chose jname=\* in which case it's broken)
  • Breaks when you try to append the command after that

This is absolutely not production-ready, and if it destroys your home, it's not my fault

olevole added a commit that referenced this issue May 25, 2018
Import ZSH completion file: Thanks to @moviuro ( https://github.com/moviuro )
First prototype: not production-ready and can destroys homedir ;-), but work in progress.
Issue #297
@olevole

This comment has been minimized.

Copy link
Collaborator

@olevole olevole commented May 25, 2018

Cool, this works for me.
I'm not sure that this will not change,
but for now I added this into /usr/local/cbsd//share/autocompletion/zsh

Maybe someday we will be able to make _cbsd_subcmd dynamic (e.g. via Jenkins when new CBSD release is being prepared).

As far as I understand, we can write about ZSH completion activating something like:

  1. create ~/.zshrc for root:
# COMPLETION SETTINGS
# add custom completion scripts
fpath=(~/.zsh/completion $fpath) 

# compsys initialization
autoload -U compinit
compinit

# show completion menu when number of options is at least 2
zstyle ':completion:*' menu select=2
  1. create directory:
mkdir -p ~root/.zsh/completion/
  1. link helper:
ln -sf /usr/local/cbsd/share/autocompletion/zsh/_cbsd ~root/.zsh/completion/_cbsd
  1. Have fun!

?

@mekanix

This comment has been minimized.

Copy link
Member

@mekanix mekanix commented May 25, 2018

Sorry to be late to the party, I didn't have notifications turned on. As I'm working on socket based communication between CBSD daemon and CBSD shell (command, call it what you will), the CBSD CLI will probably slightly change. So, on the shell side of things, I intend to port https://github.com/AmokHuginnsson/replxx and try to use it for our purposes. Once I have that, we can probably "export" in a way that is convenient for ZSH (and Fish, as I use it) to consume it and write completion.

@olevole

This comment has been minimized.

Copy link
Collaborator

@olevole olevole commented May 28, 2018

@mekanix repplx - nice project. But before we finish the CBSD daemon, we will go a very long and long way)

@moviuro I added your scripts into CBSD 11.2.0 ( commited into ports tree today).
If you plan on continuing to work on this, please create a Pull Request into develop branch. And if there is a lot of work, I can give you a commit to a dev branch. Thanks you!

@moviuro

This comment has been minimized.

Copy link
Contributor Author

@moviuro moviuro commented May 28, 2018

@olevole I'll continue working on my own fork, no need to give me commit rights on upstream 😉 thanks though!

@mekanix

This comment has been minimized.

Copy link
Member

@mekanix mekanix commented May 30, 2018

I'm sorry if I made an impression that my work on sockets and new shell is coming soon, that's not true. I expect first version around Autumn, just to make it clear.

@olevole

This comment has been minimized.

Copy link
Collaborator

@olevole olevole commented Jun 30, 2018

CBSD contribution now has zfs completion scripts, so I will close this issue. Thanks you very much @moviuro !

@ntinti

This comment has been minimized.

Copy link

@ntinti ntinti commented Jul 14, 2018

Great supplement, I like it. But I'm wondering why zsh completion for poudriere is automatically there without any personal configuration in .zshrc

They installed it in a shared zsh directory

post-install-ZSH-on:
   @${MKDIR} ${STAGEDIR}${PREFIX}/share/zsh/site-functions/
   ${INSTALL_DATA} ${WRKSRC}/completions/zsh/_poudriere \
       ${STAGEDIR}${PREFIX}/share/zsh/site-functions/

curl and pkg also reside there, I think cbsd also can do it:

ls -la /usr/local/share/zsh/site-functions/
total 31
-rw-r--r--  1 root  wheel  13098 16 Juni 17:22 _curl
-rw-r--r--  1 root  wheel  31391 10 Mai  01:18 _pkg
-r--r--r--  1 root  wheel   9051  5 Apr. 21:52 _pkgtools
-rw-r--r--  1 root  wheel   7283 16 Juni 17:22 _poudriere
@olevole

This comment has been minimized.

Copy link
Collaborator

@olevole olevole commented Jul 16, 2018

@ntinti Got it. Unfortunately I do not use zsh [yet ;-)], so I'm not very good at this issue. Well, I'll add this configuration to the next release into sysutils/cbsd port.

As for comment from #309 (comment):

not only the first level, but following the whole tree of all options cbsd has would be nice for completion. Poudriere e.g. has it:

As I understand it, the work is not yet complete. Personally, I'm currently not working on this, maybe someone will be able to finish work sooner or later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.