aboutsummaryrefslogtreecommitdiff
path: root/bin/shoal
blob: 8b7294a871f1f6ac26e17bc97582d5115c15675d (plain) (blame)
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
34
35
36
37
38
#!/usr/bin/env bash

#
# shoal(1) -- Print all the non-wildcard Host names (first one per line) from
# an ssh_config(5) file, defaulting to $HOME/.ssh/config.
#
# Author: Tom Ryder <tom@sanctum.geek.nz>
# Copyright: 2014
# License: Public domain
#

# Start by assuming we should parse all hosts
declare -i shoal
shoal=1

# Iterate through the config
while read -r option value _ ; do

    # "### shoal" and "### noshoal" toggles parsing
    case $option in
        '###')
            case $value in
                noshoal)
                    shoal=0
                    ;;
                shoal)
                    shoal=1
                    ;;
            esac
            ;;
        'Host')
            if ((shoal)) && [[ $value != *[^[:alnum:]_-]*  ]] ; then
                printf '%s\n' "$value"
            fi
            ;;
    esac
done < "${1:-$HOME/.ssh/config}"