Last active
August 29, 2015 14:14
-
-
Save arcan1s/68d5ce7b9ac3285baced to your computer and use it in GitHub Desktop.
Netclt patch for #106
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/contrib/bash-completion b/contrib/bash-completion | |
index 4f73fab..b463a31 100644 | |
--- a/contrib/bash-completion | |
+++ b/contrib/bash-completion | |
@@ -40,10 +40,10 @@ _netctl_auto() | |
case $COMP_CWORD in | |
1) | |
- COMPREPLY=( $(compgen -W "--help --version list current switch-to enable disable enable-all disable-all" -- "$cur") ) | |
+ COMPREPLY=( $(compgen -W "--help --version list current switch-to enable disable enable-all disable-all is-active is-enabled" -- "$cur") ) | |
;; | |
2) | |
- [[ ${COMP_WORDS[COMP_CWORD-1]} = @(switch-to|enable|disable) ]] && | |
+ [[ ${COMP_WORDS[COMP_CWORD-1]} = @(switch-to|enable|disable|is-active|is-enabled) ]] && | |
mapfile -t COMPREPLY < <(IFS=$'\n'; compgen -W "$(_netctl_profiles)" -- "$cur") | |
;; | |
esac | |
diff --git a/contrib/zsh-completion b/contrib/zsh-completion | |
index 05c506f..63e89af 100644 | |
--- a/contrib/zsh-completion | |
+++ b/contrib/zsh-completion | |
@@ -11,7 +11,7 @@ _wireless_interfaces() { | |
(( $+function[_netctl_command] )) || | |
_netctl_command() { | |
- [[ $words[1] = (start|stop|restart|switch-to|status|enable|disable|reenable|is-enabled|edit) ]] && | |
+ [[ $words[1] = (start|stop|restart|switch-to|status|enable|disable|reenable|is-active|is-enabled|edit) ]] && | |
compadd "${(f)$(find -L /etc/netctl -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name '*.conf' -not -name '*.service' -printf "%f\n")}" | |
} | |
@@ -47,6 +47,8 @@ _netctl-auto_commands() { | |
'disable:Disable a profile temporarily for automatic selection' | |
'enable-all:Enable all profiles for automatic selection' | |
'disable-all:Disable all profiles temporarily for automatic selection' | |
+ 'is-active:Check whether a profile is active' | |
+ 'is-enabled:Check whether a profile is enabled' | |
) | |
_describe "netctl-auto commands" _commands | |
} | |
diff --git a/src/netctl-auto b/src/netctl-auto | |
index b84c0de..b73cdfc 100755 | |
--- a/src/netctl-auto | |
+++ b/src/netctl-auto | |
@@ -21,6 +21,8 @@ Commands: | |
disable [PROFILE] Disable a profile temporarily for automatic selection | |
enable-all Enable all profiles for automatic selection | |
disable-all Disable all profiles temporarily for automatic selection | |
+ is-enabled [PROFILE] Check whether a profile is enabled | |
+ is-active [PROFILE] Check whether a profile is active | |
END | |
} | |
@@ -73,6 +75,46 @@ get_wpa_network_id() { | |
return 1 | |
} | |
+## Print whether profile is active | |
+# $2: profile name | |
+is_active() { | |
+ local interface id flag profile | |
+ while read -r interface id flag profile; do | |
+ if [[ $profile == $1 ]]; then | |
+ if [[ $flag == 'a' ]]; then | |
+ printf "active\n" | |
+ return 0 | |
+ else | |
+ printf "inactive\n" | |
+ return 1 | |
+ fi | |
+ exists=0 | |
+ fi | |
+ done < <(list_wpa_profiles) | |
+ printf "unknown\n" | |
+ return 2 | |
+} | |
+ | |
+## Print whether profile is enabled | |
+# $2: profile name | |
+is_enabled() { | |
+ local interface id flag profile | |
+ while read -r interface id flag profile; do | |
+ if [[ $profile == $1 ]]; then | |
+ if [[ $flag == 'd' ]]; then | |
+ printf "disabled\n" | |
+ return 1 | |
+ else | |
+ printf "enabled\n" | |
+ return 0 | |
+ fi | |
+ exists=0 | |
+ fi | |
+ done < <(list_wpa_profiles) | |
+ printf "unknown\n" | |
+ return 2 | |
+} | |
+ | |
## Enable or disable profiles in WPA supplicant | |
# $1: profile action: "enable", "disable", "enable-all" or "disable-all" | |
# $2: profile name if action is "enable" or "disable" | |
@@ -245,6 +287,10 @@ case $# in | |
esac;; | |
2) | |
case $1 in | |
+ is-active) | |
+ is_active "$2";; | |
+ is-enabled) | |
+ is_enabled "$2";; | |
enable|disable) | |
profile_enable_disable "$1" "$2";; | |
switch-to) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment