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
Add basic ezjail-admin completion #4324
Conversation
I was going to suggest using Those completions actually read the jail state files directly, so instead of screenscraping the output, you could do something like: function __fish_complete_jails
set -l jails /usr/local/etc/ezjail/*
echo $jails
end
function __fish_complete_running_jails
for j in (__fish_complete_jails)
if test -f /var/run/jail_{$j}.id
echo $j
end
end
end etc. |
These files need to be separated with a newline, not a space. Otherwise splitting won't be performed. So either |
These look like good suggestions. However, how about filtering for stopped jails? Also, isn't it true that a loop executes slightly slower than the screen scraping approach, especially when chaining two loops like with |
The screen scraping approach requires starting an external tool. The overhead of fork/exec is typically larger than a tiny loop. Also note that I also suggested an approach without a loop (the I'd suggest testing if you are in doubt. My money is on the builtin-approach being faster, which is presumably also why the zsh completions do that. Rule 1 of optimizing shell scripts: Use external tools as little as possible.
I would assume there's a way without screen scraping there. Possibly by reading the files. Check the zsh completions. |
Additionally, @zanchey's suggested approach will output the full path of the jail instead of just the jail name. This leads to cluttered output. If this is what the Zsh completions do, I believe my approach is the cleaner one, as it also has the benefit of not requiring the jail configurations to be present in All used tools (grep, awk) are included in FreeBSD. I'm open to any kind of improvement. Also, it's just a suggestion and attempt to extend fish's usability. Maybe I should try to get it merged in ezjail and not here. |
In that case, yeah, we want the command. |
Sorry, I left the stopped jails function out. I figured just inverting the test was a trivial addition. This approach came from the completions for zsh shipped with ezjail, so it might be worth checking with them to see whether it is a stable approach. |
You know what? Let's just merge this for now. Any improvements can be made later. Thanks @herrbischoff, and sorry for the delay! |
Description
Add basic completion for ezjail-admin utility on FreeBSD.
TODOs: