Alex Peng
2008-Oct-10 05:40 UTC
[zfs-discuss] add autocomplete feature for zpool, zfs command
Is it fun to have autocomplete in zpool or zfs command? For instance - "zfs cr ''Tab key'' " will become "zfs create" "zfs clone ''Tab key'' " will show me the available snapshots "zfs set ''Tab key'' " will show me the available properties, then "zfs set com ''Tab key''" will become "zfs set compression=", another ''Tab key'' here would show me "on/off/lzjb/gzip/gzip-[1-9]" ...... Looks like a good RFE. Thanks, -Alex -- This message posted from opensolaris.org
Boyd Adamson
2008-Oct-10 06:06 UTC
[zfs-discuss] add autocomplete feature for zpool, zfs command
Alex Peng <alex.peng at sun.com> writes:> Is it fun to have autocomplete in zpool or zfs command? > > For instance - > > "zfs cr ''Tab key'' " will become "zfs create" > "zfs clone ''Tab key'' " will show me the available snapshots > "zfs set ''Tab key'' " will show me the available properties, then "zfs set com ''Tab key''" will become "zfs set compression=", another ''Tab key'' here would show me "on/off/lzjb/gzip/gzip-[1-9]" > ...... > > > Looks like a good RFE.This would be entirely under the control of your shell. The zfs and zpool commands have no control until after you press enter on the command line. Both bash and zsh have programmable completion that could be used to add this (and I''d like to see it for these and other solaris specific commands). I''m sure ksh93 has something similar. Boyd
Nathan Kroenert
2008-Oct-10 06:12 UTC
[zfs-discuss] add autocomplete feature for zpool, zfs command
Hm - This caused me to ask the question: Who keeps the capabilities in sync? Is there a programmatic way we can have bash (or other shells) interrogate zpool and zfs to find out what it''s capabilities are? I''m thinking something like having bash spawn a zfs command to see what options are available in that current zfs / zpool version... That way, you would never need to do anything to bash/zfs once it was done the first time... do it once, and as ZFS changes, the prompts change automatically... Or - is this old hat, and how we do it already? :) Nathan. On 10/10/08 05:06 PM, Boyd Adamson wrote:> Alex Peng <alex.peng at sun.com> writes: >> Is it fun to have autocomplete in zpool or zfs command? >> >> For instance - >> >> "zfs cr ''Tab key'' " will become "zfs create" >> "zfs clone ''Tab key'' " will show me the available snapshots >> "zfs set ''Tab key'' " will show me the available properties, then "zfs set com ''Tab key''" will become "zfs set compression=", another ''Tab key'' here would show me "on/off/lzjb/gzip/gzip-[1-9]" >> ...... >> >> >> Looks like a good RFE. > > This would be entirely under the control of your shell. The zfs and > zpool commands have no control until after you press enter on the > command line. > > Both bash and zsh have programmable completion that could be used to add > this (and I''d like to see it for these and other solaris specific > commands). > > I''m sure ksh93 has something similar. > > Boyd > _______________________________________________ > zfs-discuss mailing list > zfs-discuss at opensolaris.org > http://mail.opensolaris.org/mailman/listinfo/zfs-discuss-- ////////////////////////////////////////////////////////////////// // Nathan Kroenert nathan.kroenert at sun.com // // Senior Systems Engineer Phone: +61 3 9869 6255 // // Global Systems Engineering Fax: +61 3 9869 6288 // // Level 7, 476 St. Kilda Road // // Melbourne 3004 Victoria Australia // //////////////////////////////////////////////////////////////////
Tim Foster
2008-Oct-10 07:31 UTC
[zfs-discuss] add autocomplete feature for zpool, zfs command
On Thu, 2008-10-09 at 22:40 -0700, Alex Peng wrote:> Is it fun to have autocomplete in zpool or zfs command? > > For instance - > > "zfs cr ''Tab key'' " will become "zfs create" > "zfs clone ''Tab key'' " will show me the available snapshots > "zfs set ''Tab key'' " will show me the available properties, then "zfs set com ''Tab key''" will become "zfs set compression=", another ''Tab key'' here would show me "on/off/lzjb/gzip/gzip-[1-9]" > ......Mark Musante already wrote a bash autocomplete script: http://www.sun.com/bigadmin/scripts/sunScripts/zfs_completion.bash.txt Cyril Plisko has a tcsh autocomplete script: http://unixconsult.org/zfs_tcsh_completion - a ksh93 one would be nice if anyone knows of one? I''m not sure baking this support into the zfs utilities is the right way to go. None of the other Solaris commands do this sort of auto-completion, do they? cheers, tim
Darren J Moffat
2008-Oct-10 10:06 UTC
[zfs-discuss] add autocomplete feature for zpool, zfs command
Tim Foster wrote:> On Thu, 2008-10-09 at 22:40 -0700, Alex Peng wrote: >> Is it fun to have autocomplete in zpool or zfs command? >> >> For instance - >> >> "zfs cr ''Tab key'' " will become "zfs create" >> "zfs clone ''Tab key'' " will show me the available snapshots >> "zfs set ''Tab key'' " will show me the available properties, then "zfs set com ''Tab key''" will become "zfs set compression=", another ''Tab key'' here would show me "on/off/lzjb/gzip/gzip-[1-9]" >> ...... > > Mark Musante already wrote a bash autocomplete script: > http://www.sun.com/bigadmin/scripts/sunScripts/zfs_completion.bash.txt > > Cyril Plisko has a tcsh autocomplete script: > http://unixconsult.org/zfs_tcsh_completion > > - a ksh93 one would be nice if anyone knows of one? > > I''m not sure baking this support into the zfs utilities is the right way > to go. None of the other Solaris commands do this sort of > auto-completion, do they?Not only is it not the "right way" it actually isn''t possible. The program that is running at the time is the users shell there is no ZFS code running at the point the user hits the TAB key and depending on what they press after TAB there might never be any ZFS code run. Some Solaris commands do have things like history and the like "in" them but those are interactive commands: like mdb, zonecfg etc. The zfs commands don''t follow that model. For this to work for zfs the model would be like this: $ zfs zfs> list -t snapshot ..... zfs> clone tank/foo at s1 tank/bar zfs> But that isn''t how zfs(1) works. This is exactly the same as the age old discussion about where ''*'' expansion happens. In UNIX systems is is the shell (unless it is quoted) but on MS-DOS it happened in the commands them selves. -- Darren J Moffat
Boyd Adamson
2008-Oct-10 11:14 UTC
[zfs-discuss] add autocomplete feature for zpool, zfs command
On 10/10/2008, at 5:12 PM, Nathan Kroenert wrote:> On 10/10/08 05:06 PM, Boyd Adamson wrote: >> Alex Peng <alex.peng at sun.com> writes: >>> Is it fun to have autocomplete in zpool or zfs command? >>> >>> For instance - >>> >>> "zfs cr ''Tab key'' " will become "zfs create" >>> "zfs clone ''Tab key'' " will show me the available snapshots >>> "zfs set ''Tab key'' " will show me the available properties, >>> then "zfs set com ''Tab key''" will become "zfs set compression=", >>> another ''Tab key'' here would show me "on/off/lzjb/gzip/gzip-[1-9]" >>> ...... >>> >>> >>> Looks like a good RFE. >> This would be entirely under the control of your shell. The zfs and >> zpool commands have no control until after you press enter on the >> command line. >> Both bash and zsh have programmable completion that could be used >> to add >> this (and I''d like to see it for these and other solaris specific >> commands). >> I''m sure ksh93 has something similar. >> Boyd > Hm - > > This caused me to ask the question: Who keeps the capabilities in > sync? > > Is there a programmatic way we can have bash (or other shells) > interrogate zpool and zfs to find out what it''s capabilities are? > > I''m thinking something like having bash spawn a zfs command to see > what options are available in that current zfs / zpool version... > > That way, you would never need to do anything to bash/zfs once it > was done the first time... do it once, and as ZFS changes, the > prompts change automatically... > > Or - is this old hat, and how we do it already? :) > > Nathan.I can''t speak for bash, but there are certainly some completions in zsh that do this kind of thing. I''m pretty sure there is some completion code that runs commands gnu-style with --help and then parses the output. As long as there is a reliable and regular way to query the subcommands I think it''s reasonable. (Personally I''d like to see a more general and complete way for commands to provide completion info to shells, either in a separate file of some sort or by calling them in a certain way, but that''s a pipe dream I fear) Boyd .. who has a vague feeling that that''s how it worked for DCL on VMS