Include bash completion script in the distribution

The bash completion script was contributed some time ago by Aaron Spettl but never included.  Time to correct that...

Github issue #29
This commit is contained in:
Duncan Ferguson 2015-05-01 20:40:06 +01:00
parent 61449301d0
commit 264391660d
6 changed files with 83 additions and 5 deletions

View file

@ -1,3 +1,6 @@
4.03_07 0000-00-00 Duncan Ferguson <duncan_ferguson@user.sf.net>
- Include bash completion script in distribution (Github issue #29)
4.03_06 2015-01-31 Duncan Ferguson <duncan_ferguson@user.sf.net>
- Remove references to 'logmsg' preventing the history window from working (thanks to Andrew Stevenson)

View file

@ -1,6 +1,7 @@
AUTHORS
bin_PL/_build_docs
bin_PL/ccon
bin_PL/clusterssh_bash_completion.dist
bin_PL/crsh
bin_PL/cscp.x
bin_PL/cssh

View file

@ -9,6 +9,7 @@ WriteMakefile
'NAME' => 'App::ClusterSSH',
'EXE_FILES' => [
'bin/ccon',
'bin/clusterssh_bash_completion.dist',
'bin/crsh',
'bin/cssh',
'bin/ctel'

View file

@ -30,11 +30,14 @@ for my $source (glob("*")) {
print $dfh $_ while(<$sfh>);
close($sfh);
print $dfh "\n\n__END__\n\n";
if($source ne "clusterssh_bash_completion.dist") {
print $dfh "\n\n__END__\n\n";
my $pod= qx{ ./$source --generate-pod };
die "Failed to generate pod" if($?);
print $dfh $pod;
}
my $pod= qx{ ./$source --generate-pod };
die "Failed to generate pod" if($?);
print $dfh $pod;
close($dfh);
chmod(0555, $dest) || die "Could not chmod $dest: $!";

View file

@ -0,0 +1,70 @@
# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
# ex: ts=8 sw=8 noet filetype=sh
#
# cssh(1) completion by Aaron Spettl <aaron@spettl.de>, adapted from the
# Debian GNU/Linux dput(1) completion by Roland Mas <lolando@debian.org>
#
# On Debian (and Debian based distributions) drop this file into
# /etc/bash_completion.d
# and source the /etc/bash_completion script - or just restart bash.
have cssh &&
_cssh()
{
local cur prev options paroptions clusters extra_cluster_file_line clusters_line extra_cluster_file
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
# all options understood by cssh
options='-c --cluster-file -C --config-file --debug -e --evaluate \
-g --tile -G --no-tile -h --help -H --man -l --username \
-o --options -p --port -q --autoquit -Q --no-autoquit \
-s --show-history -t --term-args -T --title \
-u --output-config -v --version'
# find the extra cluster file line in the .csshrc or, alternatively, /etc/csshrc
extra_cluster_file_line="`grep '^[[:space:]]*extra_cluster_file' $HOME/.csshrc 2> /dev/null`"
[ -z "$extra_cluster_file_line" ] && extra_cluster_file_line="`grep '^[[:space:]]*extra_cluster_file' /etc/csshrc 2> /dev/null`"
# find the clusters line in the .csshrc or, alternatively, /etc/csshrc
clusters_line="`grep '^[[:space:]]*clusters' $HOME/.csshrc 2> /dev/null`"
[ -z "$clusters_line" ] && clusters_line="`grep '^[[:space:]]*clusters' /etc/csshrc 2> /dev/null`"
# extract the location of the extra cluster file
extra_cluster_file="`echo $extra_cluster_file_line | cut -f 2- -d '='`"
[ -n "$extra_cluster_file" ] && extra_cluster_file="`eval echo $extra_cluster_file`"
# TODO: don't use eval to expand ~ and $HOME
# get the names of all defined clusters
clusters=$(
{
[ -n "$clusters_line" ] && echo "$clusters_line" | cut -f 2- -d '=' | tr "$IFS" "\n" || /bin/true
[ -n "$extra_cluster_file" ] && sed -e 's/^\([a-z0-9.-]\+\).*$/\1/i' "$extra_cluster_file" 2> /dev/null || /bin/true
sed -e 's/^\([a-z0-9.-]\+\).*$/\1/i' /etc/clusters 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 "cssh <tab><tab>"
paroptions="$clusters"
[ -n "$cur" ] && paroptions="$paroptions $options"
case $prev in
--cluster-file|-c|--config-file|-C)
COMPREPLY=( $( compgen -o filenames -G "$cur*" ) )
;;
*)
COMPREPLY=()
# also use ssh hosts for tab completion if function _known_hosts is present
[ "`type -t _known_hosts`" = "function" ] && _known_hosts -a
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$paroptions" | grep "^$cur") )
;;
esac
return 0
}
[ "$have" ] && complete -F _cssh cssh crsh ctel

View file

@ -3,7 +3,7 @@ package App::ClusterSSH;
use 5.008.004;
use warnings;
use strict;
use version; our $VERSION = version->new('4.03_06');
use version; our $VERSION = version->new('4.03_07');
use Carp qw/cluck/;