Akom's Tech Ruminations

Various tech outbursts - code and solutions to practical problems

mssh Bash completion

Posted by Admin • Friday, February 28. 2014 • Category: Linux

Clusterssh (cssh) is great, but I was getting a little fed up with unmanageable terminal windows. They either go all over my monitors or get lost, and they are hard to move and resize.

So I switched to mssh, which solves all that because all the terminals are in one window.... but, it doesn't read my /etc/clusters file! In fact, nobody seemed to even know what file it does read.

What to do? First of all, for the record, it reads its aliases (-a) from ~/.mssh_clusters This file is exactly like /etc/clusters, except for a colon, like so:
alias1: host host host
alias2: host host host

Now that we got that straight, let's make a bash completion file

Now, stick this file into /etc/bash_completion.d/mssh (To apply immediately, run . /etc/bash_completion)

# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
# ex: ts=8 sw=8 noet filetype=sh
# mssh(1) completion by Akom (tech.akom.net), adapted from
# cssh by Aaron Spettl <aaron@spettl.de>, adapted from the
# Debian GNU/Linux dput(1) completion by Roland Mas <lolando@debian.org>
# Modified by James Mackie <jc.mackie@gmail.com> to enable node name matching.

have mssh &&
        local cur prev options paroptions clusters clusters_containing_cword


        # all options understood by mssh
        options='-a --alias -h --help -V --version'

        # get the names of all defined clusters
                sed -e 's/^\([a-z0-9.-]\+\):.*$/\1/i' ~/.mssh_clusters 2> /dev/null || /bin/true
        } | sort -u)

        # get the names of any clusters that contain $cur
        # this is so that you can use node names to retreive any clusters they might be in
                grep -- "$cur" ~/.mssh_clusters | sed -e 's/^\([a-z0-9.-]\+\):.*$/\1/i' 2> /dev/null || /bin/true
        } | sort -u)

        # use options and clusters for tab completion, except there isn't yet
        # at least one character to filter by
        # reason: don't show options if the user types "mssh <tab><tab>"
        [ -n "$cur" ] && paroptions="$paroptions $options"

        case $prev in
                if [ -z "$cur" ] ; then
                        COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$paroptions" | grep -- "^$cur") )

        #       COMPREPLY=( $( compgen -o filenames -G "$cur*" ) )
        #       ;;

                # also use ssh hosts for tab completion if function _known_hosts is present
                # this function returns a lot of noise for me, so I've commented it out
                #[ "`type -t _known_hosts`" = "function" ] && _known_hosts_real -a

                COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$paroptions" | grep -- "^$cur") ${clusters_containing_cword} )

        return 0
[ "$have" ] && complete -F _mssh mssh


0 Trackbacks

  1. No Trackbacks


Display comments as (Linear | Threaded)
  1. No comments

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Standard emoticons like :-) and ;-) are converted to images.
Markdown format allowed

Submitted comments will be subject to moderation before being displayed.