From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16999 invoked by alias); 6 Jul 2014 22:21:21 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32849 Received: (qmail 9690 invoked from network); 6 Jul 2014 22:21:09 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s1024; t=1404684857; bh=YVWl7smR+3ZyCFSlZYLdo47F7r56GfNeFwEcZWe/Xxo=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:X-Rocket-Received:Received:From:To:Subject:MIME-Version:Content-Type:Content-ID:Date:Message-ID; b=orjXIXfGUET1SwPnmURRzSsW4K0W41GQsAlIQx35xJ0a76ttbIHItnMz+3XR9AXUeMe3qsmmQDq/7dOJhPbZgs4y80X3WM911/7gDYLGtO6DfZkcjbXgVIfdbLQNccnpQ+PDMeZp0ZRF8K7FQoUNyAOMwnE+B3oG8RpzADY+XU0= X-Yahoo-Newman-Id: 714088.76141.bm@smtp109.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: AK.j4YkVM1n3vwqQ701J4EQl4_ZdprfMhX9d0TDrVTKbS1E QclJIaDD_NnzlD8vQ4Ll21wW7k8aLTbrzC8DwtJsOtqryPVnpMbaRUSXBU8Q 6Sp5VBjwYzza9ja9FLqQD62zENM60IrDUGT2rWUfBHcR2NhM92LWeVY_2gQU V7jDXL3uHKGSqNWvpGisjOkWdeWj2MC_1DyrZeB6dQAIUyYdjY8H_LYlWHpJ 9Z9J3wOlOqlNwoMCKvE7Lh0wN.fVE6RPsMUAiaT_qU1IMwN5it6GioOpDEEq ryxT3IvGxiN1ORst0.Mu.8JPCbZHyEcGvlW2Kj6o8y1KsfgAGgPqOBUOoHZA toaZit6UgJl3.ngw..Ity74YnRLJWIyxIz.v8ntcg6q5SqvxU_Al2qNiQGf3 9DshvefMEayh9GGn1aLCDQl.TTViYeRFObq_W99YoMOHFg3xBerBBZ2XlUJO hHFThxhDcfcu.kF09ZbYA32jc_rSIK9Agn0YVG5AjMjKPh7gDrDb0hpRyQRU LsgN0Q2p9doMxzgZMc5GkUPsqy6C_ X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- X-Rocket-Received: from kiddle.eu (okiddle@95.222.208.198 with plain [188.125.69.59]) by smtp109.mail.ir2.yahoo.com with SMTP; 06 Jul 2014 22:14:17 +0000 UTC From: Oliver Kiddle To: Zsh workers Subject: PATCH: _ss MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <12107.1404684847.1@thecus.kiddle.eu> Date: Mon, 07 Jul 2014 00:14:16 +0200 Message-ID: <12116.1404684856@thecus.kiddle.eu> Attached is a new completion function for ss: a Linux only replacement for netstat. ss allows you to specify filters instead of using grep but the documentation for these is not in the manpage. Having zsh complete them makes ss rather more usable. It may be possible to complete something more useful for link and netlink sockets but I don't know much about them and there aren't any active on my system. Oliver diff --git a/Completion/Linux/Command/_ss b/Completion/Linux/Command/_ss new file mode 100644 index 0000000..95aa798 --- /dev/null +++ b/Completion/Linux/Command/_ss @@ -0,0 +1,98 @@ +#compdef ss + +local curcontext="$curcontext" suf ret=1 +local -a state line expl pref filt +local -A opt_args +local info="-h -V --help --version" +local sx="state exclude" + +_arguments -C -s \ + "(- *)"{-h,--help}'[show option summary]' \ + "(- *)"{-V,--version}'[show version information]' \ + "($info -n --numeric)"{-n,--numeric}"[don't resolve service names]" \ + "($info -r --resolve)"{-r,--resolve}'[resolve host addresses]' \ + "($info -a --all -l --listening)"{-a,--all}'[display all sockets]' \ + "($info -l --listening -a --all)"{-l,--listening}'[display listening sockets]' \ + "($info -o --options -e --extended)"{-o,--options}'[show timer information]' \ + "($info -e --extended -o --options)"{-e,--extended}'[show detailed information]' \ + "($info -m --memory)"{-m,--memory}'[show socket memory usage]' \ + "($info -p --processes)"{-p,--processes}'[show process using each socket]' \ + "($info -i --info)"{-i,--info}'[show internal TCP information]' \ + "($info -s --summary)"{-s,--summary}'[print summary statistics]' \ + "($info -4 --ipv4 -6 --ipv6)"{-4,--ipv4}'[display only IP version 4 sockets]' \ + "($info -4 --ipv4 -6 --ipv6)"{-6,--ipv6}'[display only IP version 6 sockets]' \ + "($info -0 --packet)"{-0,--packet}'[display PACKET sockets]' \ + "($info -t --tcp)"{-t,--tcp}'[display TCP sockets]' \ + "($info -u --udp)"{-u,--udp}'[display UDP sockets]' \ + "($info -d --dccp)"{-d,--dccp}'[display DCCP sockets]' \ + "($info -w --raw)"{-w,--raw}'[display RAW sockets]' \ + "($info -x --unix)"{-x,--unix}'[display Unix domain sockets]' \ + "($info -f --family)"{-f,--family}'[display sockets of specified type]:family:(unix inet inet6 link netlink)' \ + "($info -A --query --socket)"{-A,--query,--socket}'[specify socket tables to show]: :_values -s , socket\ table all inet tcp udp raw unix packet netlink unix_dgram unix_stream packet_raw packet_dgram' \ + "($info -D)"{-D,--diag=}'[dump raw info to file]:file:_files' \ + "($info -F)"{-F,--filter=}'[read filter information from a file]:file:_files' \ + "($info)*: :->filter" && ret=0 + +if [[ -n $state ]]; then + case $words[CURRENT-1] in + (d|s)port) + _wanted operators expl operator \ + compadd \< \> \= \>= \<= \== \!= eq ge gt lt le ne && ret=0 + ;; + dst|src) + if compset -P unix: || (( $+opt_args[-x] + $+opt_args[--unix] )) || [[ $opt_args[-f] = unix ]]; then + _files -g '*(=)' && ret=0 + elif compset -P nl:; then + if compset -P \*:; then + _pids && ret=0 + else + _message channel + fi + elif compset -P link:; then + compset -P \*: && _message ifindex || _message protocol + else + compset -P 'inet(6|):' + pref=$? + compset -S ':*' || suf="-qS:" + if compset -P \*:; then + _ports && ret=0 + elif compset -P \*/; then + _wanted netmasks expl netmask compadd $suf {1..31} && ret=0 + elif (( pref )); then + _alternative \ + "hosts:host:_hosts $suf" \ + "prefixes:prefix:compadd $suf nl link unix" && ret=0 + else + _hosts $suf && ret=0 + fi + fi + ;; + state|exclude) + _wanted states expl state compadd -M 'm:{a-zA-Z_}={A-Za-z-}' \ + ESTABLISHED SYN-SENT SYN-RECV FIN-WAIT-1 FIN-WAIT-2 TIME-WAIT \ + CLOSED CLOSE-WAIT LAST-ACK LISTEN CLOSING \ + all connected synchronized bucket big && ret=0 + ;; + *) + if [[ $words[CURRENT-2] = (d|s)port ]]; then + compset -P '*:' || pref=(-P :) + _ports $pref + return + else + (( $#line > 1 )) && [[ ${words[CURRENT-1]:Q} != (and|or|\() ]] && + filt=( "($sx)*"{and,or} ) + _values -w -s ' ' -S ' ' filter $filt \ + "*state[sockets in specified state]" \ + "*exclude[sockets not in specified state]" \ + "($sx)*src[local address/port of socket]" \ + "($sx)*dst[peer address/port of socket]" \ + "($sx)*dport[peer port]: :(lt gt ge)" \ + "($sx)*sport[local port]" \ + "($sx)*autobound[socket bound to ephemeral port]" \ + "($sx)*"{not,\(,\)} && ret=0 + fi + ;; + esac +fi + +return ret