Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/contrib/bash-completion b/contrib/bash-completion
- index 4f73fab..1463e17 100644
- --- a/contrib/bash-completion
- +++ b/contrib/bash-completion
- @@ -23,10 +23,10 @@ _netctl()
- case $COMP_CWORD in
- 1)
- - COMPREPLY=( $(compgen -W "--help --version list store restore stop-all start stop restart switch-to status enable disable reenable is-enabled edit" -- "$cur") )
- + COMPREPLY=( $(compgen -W "--help --version list store restore stop-all start stop restart switch-to status enable disable reenable is-active is-enabled edit" -- "$cur") )
- ;;
- 2)
- - [[ ${COMP_WORDS[COMP_CWORD-1]} = @(start|stop|restart|switch-to|status|enable|disable|reenable|is-enabled|edit) ]] &&
- + [[ ${COMP_WORDS[COMP_CWORD-1]} = @(start|stop|restart|switch-to|status|enable|disable|reenable|is-active|is-enabled|edit) ]] &&
- mapfile -t COMPREPLY < <(IFS=$'\n'; compgen -W "$(_netctl_profiles)" -- "$cur")
- ;;
- esac
- @@ -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..26b8753 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")}"
- }
- @@ -31,6 +31,7 @@ _netctl_commands() {
- 'enable:Enable the systemd unit for a profile'
- 'disable:Disable the systemd unit for a profile'
- 'reenable:Reenable the systemd unit for a profile'
- + 'is-active:Check whether a profile is active'
- 'is-enabled:Check whether a profile is enabled'
- 'edit:Edit a profile'
- )
- @@ -47,6 +48,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..ec51a46 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,44 @@ get_wpa_network_id() {
- return 1
- }
- +## Print whether profile is active
- +# $2: profile name
- +is_active() {
- + local interface id flag profile exists
- + 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)
- + [[ -z $exists ]] && (printf "unknown\n"; return 2)
- +}
- +
- +## Print whether profile is enabled
- +# $2: profile name
- +is_enabled() {
- + local interface id flag profile exists
- + 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)
- + [[ -z $exists ]] && (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 +285,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)
- diff --git a/src/netctl.in b/src/netctl.in
- index 2953ecf..bdac443 100644
- --- a/src/netctl.in
- +++ b/src/netctl.in
- @@ -22,6 +22,7 @@ Commands:
- disable [PROFILE] Disable the systemd unit for a profile
- reenable [PROFILE] Reenable the systemd unit for a profile
- is-enabled [PROFILE] Check whether a profile is enabled
- + is-active [PROFILE] Check whether a profile is active
- edit [PROFILE] Edit a profile
- END
- }
- @@ -48,6 +49,32 @@ sd_call() {
- systemctl $command $(printf 'netctl@%s.service\n' "$@")
- }
- +is_active() {
- + if [[ ! $(list_profiles) =~ (^|[[:space:]])$1($|[[:space:]]) ]]; then
- + printf "unknown\n"
- + return 2
- + elif sd_call "is-active --quiet" "$1" 2> /dev/null; then
- + printf "active\n"
- + return 0
- + else
- + printf "inactive\n"
- + return 1
- + fi
- +}
- +
- +is_enabled() {
- + if [[ ! $(list_profiles) =~ (^|[[:space:]])$1($|[[:space:]]) ]]; then
- + printf "unknown\n"
- + return 2
- + elif sd_call "is-enabled --quiet" "$1" 2> /dev/null; then
- + printf "enabled\n"
- + return 0
- + else
- + printf "disabled\n"
- + return 1
- + fi
- +}
- +
- list() {
- local indicators=( '*' ' ' )
- list_profiles | while read -r Profile; do
- @@ -163,8 +190,12 @@ case $# in
- esac;;
- 2)
- case $1 in
- - start|stop|restart|status|is-enabled)
- + start|stop|restart|status)
- sd_call "$1" "$2";;
- + is-active)
- + is_active "$2";;
- + is-enabled)
- + is_enabled "$2";;
- switch-to)
- ensure_root "$(basename "$0")"
- switch_to "$2";;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement