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

Extend completion support #3123

Merged
merged 21 commits into from Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions share/completions/alsamixer.fish
@@ -0,0 +1,6 @@
complete -c alsamixer -s h -l help -d "Show help"
complete -x -c alsamixer -s c -l card -d "Soundcard number or id to use"
complete -x -c alsamixer -s D -l device -d "Mixer device to control"
complete -x -c alsamixer -s V -l view -d "Starting view mode" -a "playback capture all"
complete -c alsamixer -s g -l no-color -d "Toggle the using of colors"
complete -x -c alsamixer -s a -l abstraction -d "Mixer abstraction level" -a "none basic"
25 changes: 25 additions & 0 deletions share/completions/godoc.fish
@@ -0,0 +1,25 @@
complete -x -c godoc -l analysis -o analysis -d "Comma-separated list of analyses to perform"
complete -c godoc -l ex -o ex -d "Show examples in command line mode"
complete -r -c godoc -l goroot -o goroot -d "Go root directory"
complete -c godoc -l html -o html -d "Print HTML in command-line mode"
complete -x -c godoc -l http -o http -d "HTTP service address"
complete -c godoc -l httptest.serve -o httptest.serve -d "httptest.NewServer serves on this address and blocks"
complete -c godoc -l index -o index -d "Enable search index"
complete -c godoc -l index_files -o index_files -d "Glob pattern specifying index files"
complete -x -c godoc -l index_interval -o index_interval -d "Interval of indexing"
complete -x -c godoc -l index_throttle -o index_throttle -d "Index throttle value"
complete -c godoc -l links -o links -d "Link identifiers to their declarations"
complete -x -c godoc -l maxresults -o maxresults -d "Maximum number of full text search results shown"
complete -x -c godoc -l notes -o notes -d "Regular expression matching note markers to show"
complete -c godoc -l play -o play -d "Enable playground in web interface"
complete -c godoc -s q -d "Arguments are considered search queries"
complete -c godoc -l server -o server -d "Webserver address for command line searches"
complete -c godoc -l src -o src -d "Print (exported) source in command-line mode"
complete -x -c godoc -l tabwidth -o tabwidth -d "Tab width"
complete -r -c godoc -l templates -o templates -d "Directory containing alternate template files"
complete -c godoc -l timestamps -o timestamps -d "Show timestamps with directory listings"
complete -r -c godoc -l url -o url -d "Print HTML for named URL"
complete -c godoc -s v -d "Verbose mode"
complete -r -c godoc -l write_index -o write_index -d "Write index to a file"
complete -r -c godoc -l zip -o zip -d "Zip file providing the file system to serve"

8 changes: 8 additions & 0 deletions share/completions/gofmt.fish
@@ -0,0 +1,8 @@
complete -c gofmt -l cpuprofile -o cpuprofile -d "Write cpu profile to this file"
complete -c gofmt -s d -d "Display diffs instead of rewriting files"
complete -c gofmt -s e -d "Report all errors (not just the first 10 on different lines)"
complete -c gofmt -s l -d "List files whose formatting differs from gofmt's"
complete -c gofmt -s r -d "Rewrite rule (e.g., 'a[b:len(a)] -> a[b:]')"
complete -c gofmt -s s -d "Simplify code"
complete -c gofmt -s w -d "Write result to (source) file instead of stdout"

9 changes: 9 additions & 0 deletions share/completions/mkdir.fish
@@ -0,0 +1,9 @@
complete -c mkdir -s m -l mode --description 'Set file mode (as in chmod)' -x
complete -c mkdir -s p -l parents --description 'Make parent directories as needed'
complete -c mkdir -s v -l verbose --description 'Print a message for each created directory'
complete -c mkdir -s Z --description 'Set SELinux security context of each created directory to the default type'
Copy link
Member

@floam floam Jun 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On OS X or BSD a few of these on a very prominent command like mkdir might be confusing to a user. The full possible usage is just three short options:

     mkdir [-pv] [-m mode] directory_name ...

The manpage:

SYNOPSIS
     mkdir [-pv] [-m mode] directory_name ...

DESCRIPTION
     The mkdir utility creates the directories named as operands, in the order
     specified, using mode rwxrwxrwx (0777) as modified by the current
     umask(2).

     The options are as follows:

     -m mode
             Set the file permission bits of the final created directory to
             the specified mode.  The mode argument can be in any of the for-
             mats specified to the chmod(1) command.  If a symbolic mode is
             specified, the operation characters ``+'' and ``-'' are inter-
             preted relative to an initial mode of ``a=rwx''.

     -p      Create intermediate directories as required.  If this option is
             not specified, the full path prefix of each operand must already
             exist.  On the other hand, with this option specified, no error
             will be reported if a directory given as an operand already
             exists.  Intermediate directories are created with permission
             bits of rwxrwxrwx (0777) as modified by the current umask, plus
             write and search permission for the owner.

     -v      Be verbose when creating directories, listing them as they are
             created.

     The user must have write permission in the parent directory.

DIAGNOSTICS
     The mkdir utility exits 0 on success, and >0 if an error occurs.

SEE ALSO
     rmdir(1)

COMPATIBILITY
     The -v option is non-standard and its use in scripts is not recommended.

STANDARDS
     The mkdir utility is expected to be IEEE Std 1003.2 (``POSIX.2'') compat-
     ible.

Copy link
Contributor Author

@moverest moverest Jun 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I can do something like this:

if test (uname) = "Linux"
    complete -c mkdir -s Z --description 'Set SELinux security context of each created directory to the default type'
    complete -c mkdir -l context --description 'Like -Z' -f
    complete -c mkdir -l version --description 'Output version'
end

Or I can get rid of the file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What has worked well for us is something like

if mkdir --version >/dev/null ^/dev/null
# GNU
else
# BSD/OSX

this will also work if you install GNU tools on OSX, and will also work on Hurd.

I think the only place we actually check uname for completions is killall, but that's a special case (you can't ever invoke it on Solaris).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only killall, modprobe and open indeed. I'll use mkdir --version then.

I guess it's okay if I use uname for modinfo completions? I have a few other command completions done.

Copy link
Member

@floam floam Jun 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, testing for a feature directly is usually the way to go.

I think perhaps further you should also test, somehow, for SELinux on Linux (or, at least, a SELinux-enabled mkdir), and if that doesn't exist, don't show the --context=CTX (-Z CTX) options.

Copy link
Member

@floam floam Jun 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no other OS that has a mod info ...

Errr, seems Solaris does:

http://docs.oracle.com/cd/E23824_01/html/821-1462/modinfo-1m.html

But if you can only manage to provide completions relevant to a Linux modinfo, it seems reasonable to check uname.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if you can only manage to provide completions relevant to a Linux modinfo, it seems reasonable to check uname.

It seems like the linux one has --version and the solaris one doesn't - long options started as a GNUism, so other OSs don't have them, and if they do they're most likely compatible with the GNU stuff.

We should really try not to call uname - as I said, hurd will have GNU tools but won't identify as linux.

I think perhaps further you should also test, somehow, for SELinux on Linux (or, at least, a SELinux-enabled mkdir), and if that doesn't exist, don't show the --context=CTX (-Z CTX) options.

It seems like the canonical way to check if SELinux is enabled is sestatus. Since I think mkdir can also add contexts even if selinux is installed but not enabled, we should get away with just checking command -s sestatus.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the linux one has --version and the solaris one doesn't - long options started as a GNUism, so other OSs don't have them, and if they do they're most likely compatible with the GNU stuff.

They seem to be more different than that?

http://docs.oracle.com/cd/E23824_01/html/821-1462/modinfo-1m.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like modinfo is behave in a completely different way on Solaris... :-/

If I understand well, I should have for mkdir:

if command -s sestatus
    complete -c mkdir -s Z --description 'Set SELinux security context of each created directory to the default type'
    complete -c mkdir -l context --description 'Like -Z' -f
end

But, --version is only present with GNU tools, so I should also have:

if mkdir --version >/dev/null ^/dev/null
    complete -c mkdir -l version --description 'Output version'
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They seem to be more different than that?

Sure, but that doesn't matter here - if we have --version, then we have the GNU version. If we don't, then it's something else (currently it only seems to be a thing on Solaris).

If I understand well, I should have for mkdir:

Yes, but silence commands stdout - >/dev/null.

But, --version is only present with GNU tools, so I should also have:

Nope - the entire completion here is specific to the GNU version. The BSD version just has -m, -p and -v - just those short options, not the long versions.

So it's more like

if mkdir --version >/dev/null ^/dev/null
    complete -c mkdir -l version -d 'Output version'
    complete -c mkdir -s m -l mode --description 'Set file mode (as in chmod)' -x
    # [...]
else
    complete -c mkdir -s m --description 'Set file mode (as in chmod)' -x
    # [...]
end

In other words: Use how it reacts to "--version" as an indicator.

complete -c mkdir -l context --description 'Like -Z' -f
complete -c mkdir -l help --description 'Display help'
complete -c mkdir -l version --description 'Output version'


33 changes: 33 additions & 0 deletions share/completions/netctl-auto.fish
@@ -0,0 +1,33 @@
set -l cmds list store restore stop-all start stop restart switch-to status enable disable reenable is-enabled edit

function __fish_print_netctl-auto_profile
for line in (netctl-auto list)
set -l profile (string sub -s 3 $line)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the "3" come from? Does it print whitespace before the actual profile? If so, string trim might be nicer.

Copy link
Contributor Author

@moverest moverest Jun 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output of netctl-auto list is this:

* wlan0-ActiveProfile1
  wlan0-Profile2
! wlan0-DisabledProfile3

So it removes the "* " and " ". I forgot the "! " case which I am adding now. I'm still reading the man page but I don't know another way to do this nicer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case sub is okay.

if [ (string sub -l 1 $line) = "*" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if string match -q '\**' -- $line

printf "%s\t%s\n" $profile "Active profile"
else
printf "%s\t%s\n" $profile "Profile"
end
end
end

complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -l help -d "Show help"
complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -l version -d "Show version"

complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a list -f -d "List all available profiles"
complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a store -f -d "Save the profiles that are currently active"
complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a restore -f -d "Load the profiles that were active during the last invocation of 'store'"
complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a stop-all -f -d "Stop all active network profiles"
complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a start -f -d "Start network profile"
complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a stop -f -d "Stop network profile"
complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a restart -f -d "Restart network profile"
complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a switch-to -f -d "Start profile after stopping the others that refer to the same interface"
complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a status -f -d "Show terse runtime status inforamation about a profile"
complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a enable -f -d "Enable the systemd unit for the specified profile"
complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a disable -f -d "Disable the systemd unit for the specified profile"
complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a reenable -f -d "Renable the systemd unit for the specified profile"
complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a is-enabled -f -d "Check whether the systemd unit for the specified profile is enabled"
complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a edit -f -d "Open the file of the specified profile in an editor"

complete -c netctl-auto -n "__fish_seen_subcommand_from start stop restart switch-to status enable disable reenable is-enabled edit" -f -a "(__fish_print_netctl-auto_profile)" -d "Profile"

8 changes: 8 additions & 0 deletions share/completions/poweroff.fish
@@ -0,0 +1,8 @@
complete -c poweroff -l help -d "Show help"
complete -c poweroff -l halt -d "Halt the machine"
complete -c poweroff -l poweroff -s p -d "Switch off the machine"
complete -c poweroff -l reboot -d "Reboot the machine"
complete -c poweroff -l force -s f -d "Force immediate halt/power-off/reboot"
complete -c poweroff -l wtmp-only -s w -d "Just write wtmp record"
complete -c poweroff -l no-wtmp -s d -d "Don't write wtmp record"
complete -c poweroff -l no-wall -d "Don't send wall message"
12 changes: 12 additions & 0 deletions share/completions/termite.fish
@@ -0,0 +1,12 @@
complete -c termite -s h -l help -d "Display help message"
complete -c termite -s v -l version -d "Display version information"
complete -r -c termite -s e -l exec -d "Tell termite start <cmd> instead of the shell"
complete -x -c termite -s r -l role -d "The role to set the termite window to report itself with"
complete -x -c termite -s t -l title -d "Set the termite window's title"
complete -r -c termite -s d -l directory -d "Tell termite to change to <dir> when launching"
complete -x -c termite -l geometry -d "Override the window geometry in pixels"
complete -c termite -l hold -d "Keep termite open after the child process exits"
complete -x -c termite -l display -d "Launch on <disp> X display"
complete -r -c termite -s c -l config -d "Config file to use"
complete -x -c termite -l name -d "Set the windows name part of WM_CLASS property"
complete -x -c termite -l class -d "Set the windows class part of the WM_CLASS property"
67 changes: 67 additions & 0 deletions share/completions/udisksctl.fish
@@ -0,0 +1,67 @@
set -l cmds help info dump status monitor mount unmount unlock lock loop-setup loop-delete power-off smart-simulate

set __fish_mount_opts async\tUse\ asynchronous\ I/O atime\tUpdate\ time\ on\ each\ access auto\tMounted\ with\ -a defaults\tUse\ default\ options dev\tInterpret\ character/block\ special\ devices exec\tPermit\ executables _netdev\tFilesystem\ uses\ network noatime\tDo\ not\ update\ time\ on\ each\ access noauto\tNot\ mounted\ by\ -a nodev\tDo\ not\ interpret\ character/block\ special\ devices noexec\tDo\ not\ permit\ executables nosuid\tIgnore\ suid\ bits nouser\tOnly\ root\ may\ mount remount\tRemount\ read-only\ filesystem ro\tMount\ read-only rw\tMount\ read-write suid\tAllow\ suid\ bits sync\tUse\ synchronous\ I/O dirsync\tUse\ synchronous\ directory\ operations user\tAny\ user\ may\ mount users\tAny\ user\ may\ mount\ and\ unmount

function __fish_complete_blockdevice
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function has been split out recently (7af9e1f). No need to redefine it here.

set -l cmd (commandline -ct)
[ "" = "$cmd" ]
and return
for f in $cmd*
[ -b $f ]
and printf "%s\t%s\n" $f "Block device"
[ -d $f ]
and printf "%s\n" $f/
end
end

function __fish_print_mounted_blockdevice
cat /proc/mounts | grep "^/.*" | cut -d " " -f 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless use of cat. Also string would be nice here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grep "^/.*"  /proc/mounts | cut -d " " -f 1`

I must admit that I am new to string. Should I do something like this?

string match -i -r "^/[^ ]*" < /proc/mounts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, yes. Though the "-i" is superfluous and you should test -r /proc/mounts before - you don't want errors here (this would also apply to cat | grep).

Of course the assumption here is that block devices can't have spaces in their names, which I believe holds, and even if it didn't it would be a very unusual configuration. /etc/mtab replaces spaces with '\040', dunno if it's the same here.

end

complete -f -c udisksctl -n "__fish_seen_subcommand_from $cmds" -l help -d "Shows help"
complete -f -c udisksctl -n "not __fish_seen_subcommand_from $cmds" -a help -d "Shows help"
complete -f -c udisksctl -n "not __fish_seen_subcommand_from $cmds" -a info -d "Shows information about an object"
complete -f -c udisksctl -n "not __fish_seen_subcommand_from $cmds" -a dump -d "Shows information about all objects"
complete -f -c udisksctl -n "not __fish_seen_subcommand_from $cmds" -a status -d "Shows high-level status"
complete -f -c udisksctl -n "not __fish_seen_subcommand_from $cmds" -a monitor -d "Monitor changes to objects"
complete -f -c udisksctl -n "not __fish_seen_subcommand_from $cmds" -a mount -d "Mount a filesystem"
complete -f -c udisksctl -n "not __fish_seen_subcommand_from $cmds" -a unmount -d "Unmount a filesystem"
complete -f -c udisksctl -n "not __fish_seen_subcommand_from $cmds" -a unlock -d "Unlock an encrypted device"
complete -f -c udisksctl -n "not __fish_seen_subcommand_from $cmds" -a lock -d "Lock an encrypted device"
complete -f -c udisksctl -n "not __fish_seen_subcommand_from $cmds" -a loop-setup -d "Set-up a loop device"
complete -f -c udisksctl -n "not __fish_seen_subcommand_from $cmds" -a loop-delete -d "Delete a loop device"
complete -f -c udisksctl -n "not __fish_seen_subcommand_from $cmds" -a power-off -d "Safely power off a drive"
complete -f -c udisksctl -n "not __fish_seen_subcommand_from $cmds" -a smart-simulate -d "Set SMART data for a drive"

complete -f -c udisksctl -n "__fish_seen_subcommand_from info" -s p -l object-path -d "Object to get information about"
complete -c udisksctl -n "__fish_seen_subcommand_from info" -s b -l block-device -d "Block device to get information about" -a "(__fish_complete_blockdevice)"
complete -f -c udisksctl -n "__fish_seen_subcommand_from info" -s d -l drive -d "Drive to get information about"

complete -x -c udisksctl -n "__fish_seen_subcommand_from mount" -s t -l filesystem-type -d "Filesystem type to use" -a "(__fish_print_filesystems)"
complete -x -c udisksctl -n "__fish_seen_subcommand_from mount" -s o -l options -d "Mount options" -a '(__fish_append , $__fish_mount_opts)'

complete -c udisksctl -n "__fish_seen_subcommand_from unmount" -s f -l force -d "Force/layzy unmount"
complete -c udisksctl -n "__fish_seen_subcommand_from unmount" -a "(__fish_print_mounted)" -f -d "Mount point"
complete -c udisksctl -n "__fish_seen_subcommand_from unmount" -s b -l block-device -a "(__fish_print_mounted_blockdevice)" -x -d "Mounted block device"

complete -c udisksctl -n "__fish_seen_subcommand_from loop-setup" -s f -l file -d "File to set-up a loop device for"
complete -c udisksctl -n "__fish_seen_subcommand_from loop-setup" -s r -l read-only -d "Setup read-only device"
complete -c udisksctl -n "__fish_seen_subcommand_from loop-setup" -s o -l offset -x -d "Start at <num> bytes into file"
complete -c udisksctl -n "__fish_seen_subcommand_from loop-setup" -s s -l size -x -d "Limit size to <num> bytes"

complete -c udisksctl -n "__fish_seen_subcommand_from loop-delete" -s p -l object-path -d "Object for loop device to delete"
complete -c udisksctl -n "__fish_seen_subcommand_from loop-delete" -s b -l block-device -d "Loop device to delete"

complete -c udisksctl -n "__fish_seen_subcommand_from smart-simulate" -s f -l file -d "File with libatasmart blob"

complete -c udisksctl -n "__fish_seen_subcommand_from mount unmount lock unlock loop-setup loop-delete power-off smart-simulate" -l no-user-interaction -d "Do not authenticate the user if needed"

for cmd in mount lock unlock
complete -r -c udisksctl -n "__fish_seen_subcommand_from $cmd" -s p -l object-path -d "Object to $cmd"
complete -r -c udisksctl -n "__fish_seen_subcommand_from $cmd" -s b -l block-device -d "Block device to $cmd" -a "(__fish_complete_blockdevice)"
end

for cmd in power-off smart-simulate
complete -r -c udisksctl -n "__fish_seen_subcommand_from $cmd" -s p -l object-path -d "Object path for ATA device"
complete -r -c udisksctl -n "__fish_seen_subcommand_from $cmd" -s b -l block-device -d "Block device for ATA device" -a "(__fish_complete_blockdevice)"
end