I spent a bit of time this afternoon writing a bash completion script
for zfs and zpool since I didn't really like the only one I could
find. It's something I've just hacked together quickly so it's far
from complete, and I haven't spent much time testing it. That said, I
think it covers all the options I use with any frequency, and a fair
bit more, so I thought I'd post it now rather than wait until it's
finished - since that may never happen.
I hope this is of some use to someone. If you do try it, let me know
if there are any problems.
Nye
this is very good stuff. I spot a number of omissions
- datasets now need "-t all" since a while
- split is missing
- some of the commands listed are not actually supported
But overall the experience is just Rolls Royce!
> zfs_completion.bash
> 8KViewDownload
Thanks for pointing that out.
> - split is missing
Completely missing? It doesn't have explicit support, so the
completions for it aren't great, but you should get the 'split'
command itself plus the default poolname completion if you are using a
version of zpool which includes 'split' in its usage instructions. I
actually didn't write the specific completion for split purely because
I hadn't installed the updated manpage, so I'd missed the command
completely :-).
Taking a second look, I guess it's the <device> part that you need
adding like with 'zpool add' etc. It's not quite the same as 'split'
requires a new poolname in between the two, but I'll look into it.
> - some of the commands listed are not actually supported
This is because the script parses the usage instructions from the zfs
and zpool commands to determine what completions should be available.
I could add a filter to remove commands that are unsupported in
zfs-fuse, but it didn't seem worth the effort :P.
>
> But overall the experience is just Rolls Royce!
>
Thanks for the feedback! I am hoping to add more support for
command-specific options, plus complete the relevant switches if you
have typed the leading dash, but not otherwise (assuming this doesn't
prove technically difficult). However if I find it works well enough
for my needs then I may take an indefinite length of time get around
to it...
Nye
Hi
I'm trying to get zfs-fuse bash completion working with sudo. This presents a problem because calls to zfs and zpool to get completions are apparently not made with sudo, but instead the regular user. Any thoughts on how to solve this? Manually put sudo into the zfs-fuse bash completion file? I would rather not change to complete root shell, mistakes are expensive.
--
To post to this group, send email to zfs-...@googlegroups.com
To visit our Web site, click on http://zfs-fuse.net/
Errr... use zsh ? ;-)
Actually I use zsh, and zfs completions work with sudo without doing anything ! :)
Now you mention it, my proposed method to
alias zfs="sudo zfs"
alias zpool="sudo zpool"
might work like a charm. Can/did you try it?
This reminds me that my current local ebuild (with the lzo-patch)
doesn't yet have bash-completion.
Will try to add that now.
Stefan
done.
Unsure what to do w/ my ebuild (apart from testing it ;-) ).
File a bug at bugs.gentoo.org?
Anyone wants to test it?
Right now I call it zfs-fuse-0.7.1_beta2.ebuild here, it pulls the
"compress"-branch from Emanuels repo (has lzo, yes) and does
bash-completion now.
Stefan
Unsure what to do w/ my ebuild (apart from testing it ;-) ).
File a bug at bugs.gentoo.org?
Anyone wants to test it?Right now I call it zfs-fuse-0.7.1_beta2.ebuild here, it pulls the
"compress"-branch from Emanuels repo (has lzo, yes) and does
bash-completion now.
> Definitely shoot it up on b.g.o, with perhaps a note to the 0.7.0 ebuild
> bug.
forgot about the note, will add now:
The reason behind this is that (as I'm sure you're aware, but just to
make sure we're all on the same page) zfs needs to be called in order
to determine what the completions are, and as far as I can tell zfs
requires full access to /var/run/zfs/zfs_socket even to read the
relevant information.
Manually[0] putting sudo before every call would be one option,
although that could lead to a situation where you need to put in a
password when you press tab which would be strange given that you's
usually only expect the password prompt when actually entering a
command. Another option would be to use zfs only when in a root shell
so that it's no longer necessary - but I'm sure you don't want to do
that.
What I actually do is 'sudo chmod g+w /var/run/zfs/zfs_socket' and
'sudo chgrp users /var/run/zfs/zfs_socket' so that anyone in the
'users' group (ie. just me in this case) can use zfs without becoming
root. This does allow destructive operations (zpool destroy and so on)
as a normal user so might also not be desirable.
The problem boils down to the fact that there's no way to my knowledge
to query ZFS in order to get completion information, without *also*
having full control over ZFS. If there *is* a way, then that would
lead us to the ideal solution...
Hope that helps,
Nye
[0] When I say 'manually', what I would actually do is change all
calls to zfs (and zpool) to use a variable $ZFS/$ZPOOL and define that
at the top of the file so that it can be set in one place. This option
would potentially allow for automatically determining if sudo is
necessary and doing the right thing. The thing that concerns me is
that I normally do that in shell scripts as a matter of course so I'm
not sure if I didn't here simply out of laziness or if there was a
good reason not to.
The problem boils down to the fact that there's no way to my knowledge to query ZFS in order to get completion information, without *also* having full control over ZFS. If there *is* a way,
[0] When I say 'manually', what I would actually do is change all
calls to zfs (and zpool) to use a variable $ZFS/$ZPOOL and define that
at the top of the file so that it can be set in one place. This option
would potentially allow for automatically determining if sudo is
necessary and doing the right thing. The thing that concerns me is
that I normally do that in shell scripts as a matter of course so I'm
not sure if I didn't here simply out of laziness or if there was a
good reason not to.