From 4d49c902ac3ad01a7a93cdcb0876ca1dd4cb00fc Mon Sep 17 00:00:00 2001 From: Clément Martinez Date: Wed, 8 Jun 2016 23:34:51 +0200 Subject: Fix and enhance netctl-auto completions I mixed things up with `netctl` somehow. Since the two are quite different they do not have the same function, they should not have the same completions. I also find that I would be smarter to only display the relevent profiles given what we want to do. If we want to disable a profile we should only complete with enabled profile for completion for instance. I don't know if the implemention is nice enough however. --- share/completions/netctl-auto.fish | 75 +++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 21 deletions(-) (limited to 'share') diff --git a/share/completions/netctl-auto.fish b/share/completions/netctl-auto.fish index 90558c57..1b010b6f 100644 --- a/share/completions/netctl-auto.fish +++ b/share/completions/netctl-auto.fish @@ -1,35 +1,68 @@ -set -l cmds list store restore stop-all start stop restart switch-to status enable disable reenable is-enabled edit +set -l cmds list current start stop switch-to enable disable enable-all disable-all +# Helper function that prints network profiles managed by netctl-auto. +# If no argument is given, it prints all profiles. +# Othewise, it only prints the ones given as arguments witch are either: +# - active +# - disabled +# - other (meaning enabled but not active) +# +# For example, if you only want the enabled profiles, call it with +# the arguments active and other. function __fish_print_netctl-auto_profile + set -l show_active false + set -l show_disabled false + set -l show_other false + + for arg in $argv + switch $arg + case other + set show_other true + case disabled + set show_disabled true + case active + set show_active true + end + end + + if not count $argv >/dev/null + set show_active true + set show_disabled true + set show_other true + end + for line in (netctl-auto list) set -l profile (string sub -s 3 $line) if string match -q '\**' -- $line - printf "%s\t%s\n" $profile "Active profile" - else if string match -q "!*" -- $line - printf "%s\t%s\n" $profile "Disabled profile" + if test $show_active = true + printf "%s\t%s\n" $profile "Active profile" + end + else if string match -q "!*" -- $line + if test $show_disabled = true + printf "%s\t%s\n" $profile "Disabled profile" + end else - printf "%s\t%s\n" $profile "Profile" + if test $show_other = true + printf "%s\t%s\n" $profile "Profile" + end 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 for automatic selection" +complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a current -d "Report currently active profiles" +complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a start -f -d "Start automatic profile selection on interface" +complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a stop -f -d "Stop automatic profile selection on interface" +complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a switch-to -f -d "Switch to the given network profile" +complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a enable -f -d "Enable network profile for automatic selection" +complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a disable -f -d "Disable network profile for automatic selection" +complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a enable-all -f -d "Enable all profiles for automatic selection" +complete -c netctl-auto -n "not __fish_seen_subcommand_from $cmds" -a disable-all -f -d "Disable all profiles for automatic selection" -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" +complete -c netctl-auto -n "__fish_seen_subcommand_from switch-to" -f -a "(__fish_print_netctl-auto_profile other disabled)" -d "Profile" +complete -c netctl-auto -n "__fish_seen_subcommand_from enable" -f -a "(__fish_print_netctl-auto_profile disabled)" -d "Profile" +complete -c netctl-auto -n "__fish_seen_subcommand_from disable" -f -a "(__fish_print_netctl-auto_profile active other)" -d "Profile" +complete -c netctl-auto -n "__fish_seen_subcommand_from start stop" -f -a "(__fish_print_interfaces)" -- cgit v1.2.3