From 3cbb28408f4537fbc7beaa7148458f0db3f02baf Mon Sep 17 00:00:00 2001 From: James Rayner Date: Wed, 18 Nov 2009 13:45:35 +1100 Subject: FS#13418,FS#12505 - add zsh/bash completion --- Makefile | 18 ++++++++------- contrib/bash-completion | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ contrib/ifplugd.action | 26 ---------------------- contrib/zsh-completion | 23 ++++++++++++++++++++ 4 files changed, 91 insertions(+), 34 deletions(-) create mode 100644 contrib/bash-completion delete mode 100755 contrib/ifplugd.action create mode 100644 contrib/zsh-completion diff --git a/Makefile b/Makefile index 093cbe9..b69dd95 100644 --- a/Makefile +++ b/Makefile @@ -3,12 +3,11 @@ VERSION=2.5.0rc1 VPATH = doc install: - install -d $(DESTDIR)/usr/lib/network/{connections,hooks} $(DESTDIR)/etc/network.d/examples \ - $(DESTDIR)/etc/network.d/hooks \ + install -d $(DESTDIR)/usr/lib/network/{connections,hooks} \ + $(DESTDIR)/etc/network.d/{examples,hooks,interfaces} \ + $(DESTDIR)/etc/rc.d} \ $(DESTDIR)/var/run/network/{interfaces,profiles} \ - $(DESTDIR)/usr/bin/ $(DESTDIR)/etc/rc.d/ \ $(DESTDIR)/usr/share/man/{man5,man8} \ - $(DESTDIR)/etc/ifplugd # Documentation install -m644 examples/* $(DESTDIR)/etc/network.d/examples/ @@ -21,12 +20,15 @@ install: # Hooks install -m755 src/hooks/* ${DESTDIR}/usr/lib/network/hooks/ # Scripts - install -m755 src/netcfg $(DESTDIR)/usr/bin/netcfg2 - install -m755 src/netcfg-menu $(DESTDIR)/usr/bin/netcfg-menu + install -Dm755 src/netcfg $(DESTDIR)/usr/bin/netcfg2 + install -Dm755 src/netcfg-menu $(DESTDIR)/usr/bin/netcfg-menu install -m755 wpa_actiond/netcfg-wpa_actiond{,-action} ifplugd/net-auto-wired $(DESTDIR)/usr/bin - install -m755 ifplugd/netcfg.action $(DESTDIR)/etc/ifplugd/ + install -Dm755 ifplugd/netcfg.action $(DESTDIR)/etc/ifplugd/netcfg.action # Daemons - install -m755 src/net-profiles src/net-rename wpa_actiond/net-auto-wireless ifplugd/net-auto-wired $(DESTDIR)/etc/rc.d + install -m755 src/net-{profiles,rename} wpa_actiond/net-auto-wireless ifplugd/net-auto-wired $(DESTDIR)/etc/rc.d + # Shell Completion + install -Dm644 contrib/bash-completion $(DESTDIR)/etc/bash_completion.d/netcfg + install -Dm644 contrib/zsh-completion $(DESTDIR)/usr/share/zsh/site-functions/_netcfg install-wireless: install -d $(DESTDIR)/usr/lib/network/connections $(DESTDIR)/usr/bin \ diff --git a/contrib/bash-completion b/contrib/bash-completion new file mode 100644 index 0000000..44dd181 --- /dev/null +++ b/contrib/bash-completion @@ -0,0 +1,58 @@ +# netcfg completion by Maciej 'macieks' Sitarz + +_connected_prfls () +{ + COMPREPLY=( $( compgen -W "$( ls /var/run/network/profiles/ )" -- $cur ) ) +} + +_connected_intfs () +{ + COMPREPLY=( $( compgen -W "$( ls /var/run/network/interfaces/)" -- $cur ) ) +} + +_netcfg () +{ + local cur prev opts lopts cmds prfls + + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + opts="-c -d -a -i -h -v" + lopts="--help --version" + cmds="check-iface down all-down iface-down all-resume all-suspend" + prfls="`find /etc/network.d -maxdepth 1 -not -type d -printf '%f\n'`" + + case "${cur}" in + --*) + COMPREPLY=( $( compgen -W "${lopts}" -- $cur ) ) + return 0 + ;; + -*) + COMPREPLY=( $( compgen -W "${opts} ${lopts}" -- $cur ) ) + return 0 + ;; + *) + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=( $( compgen -W "${opts} ${lopts} ${cmds} ${prfls}" -- $cur ) ) + fi + ;; + esac + + case "${prev}" in + -c|check-iface|-i|iface-down) + _connected_intfs + return 0 + ;; + -d|down) + _connected_prfls + return 0 + ;; + *) + ;; + esac + + return 0 +} +complete -F _netcfg netcfg +complete -F _netcfg netcfg2 diff --git a/contrib/ifplugd.action b/contrib/ifplugd.action deleted file mode 100755 index 720b576..0000000 --- a/contrib/ifplugd.action +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -# -# /etc/ifplugd/ifplugd.action script for Arch Linux -# can replace the one that comes with extra/ifplugd - -# . /etc/rc.conf -# . /etc/rc.d/functions - -case "$2" in - up) - if [ "${1:0:3}" == eth ]; then - /usr/bin/netcfg "myethernet" # replace with name of your desired profile - fi - ;; - down) - /usr/bin/netcfg iface-down "$1" - /sbin/ifconfig "$1" down # note that we'll return 0 even if the netcfg call failed, e.g. because iface was already down - # hence no "failure" messages to syslog - ;; - *) - echo "Wrong arguments" > /dev/stderr - exit 1 - ;; -esac - -# vim: ft=sh ts=4 et sw=4: diff --git a/contrib/zsh-completion b/contrib/zsh-completion new file mode 100644 index 0000000..9f74e42 --- /dev/null +++ b/contrib/zsh-completion @@ -0,0 +1,23 @@ +#compdef netcfg netcfg2=netcfg +local -a disp + +all_profiles() { + _path_files -W "/etc/network.d" -g "*(.)" +} + +up_profiles() { + _files -W "/var/run/network/profiles" +} + +up_ifaces() { + _files -W "/var/run/network/interfaces" +} + +_arguments -C \ +'(- *)-c[Start specified profile if its interface is not currently up]:Network profile:all_profiles' \ +'(- *)-d[Take specified profile down]:Active profiles:up_profiles' \ +'(- *)-a[Take all active profiles down]' \ +'(- *)-i[Take down profile active on specified interface]:Active interfaces:up_ifaces' \ +'(- *)-r[Disconnect and reconnect specified profile]:Active profiles:up_profiles' \ +'(- *)-u[Start specified profile]:Network profile:all_profiles' \ +'(- *)*:Network profile:all_profiles' \ No newline at end of file -- cgit v1.2.3-24-g4f1b