summaryrefslogtreecommitdiffstats
path: root/util/bin/sshkill
blob: 80300483023f2fb1689883e61ece96a7b81e8618 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /bin/sh
#
# kill ssh client: sshkill user@host:port
# setup bash completion: . sshkill
#
if ! grep -q '^ControlPath /tmp/%u/sshmux/%r@%h:%p$' "$HOME/.ssh/config"; then
  echo "Your ~/.ssh/config's ControlPath sucks!" >&2
  (exit 23)
else
  if test "${0:0:1}" = -; then
    if ! echo "${BASHOPTS-}" | grep -Eq '(^|:)progcomp(:|$)'; then
      echo "source sshmux into something other than a progcomp'able bash" >&2
      (exit 23)
    else

      # setup bash completion
      comp_sshkill() {
        if test $COMP_CWORD = 1; then
          COMPREPLY=($(cd "/tmp/$LOGNAME/sshmux" &&
              ls | grep "^${COMP_WORDS[$COMP_CWORD]}.*"))
        fi
      }
      complete -F comp_sshkill sshkill

    fi
  else

    # kill ssh client
    set -euf
    exec pkill -f "^ssh: /tmp/$LOGNAME/sshmux/$1 \[mux\]$"

  fi
fi