return 0
}
+# Host completion for SSH known hosts.
+function _known_hosts() {
+ cur=${COMP_WORDS[COMP_CWORD]}
+
+ HOSTS=$(sed 's/[ ].*//;s/,/\n/' ~/.ssh/known_hosts)
+
+ COMPREPLY=($(compgen -W "$HOSTS" -- "$cur"))
+ return 0
+}
+
# Process completion for kill, strace etc.
function _pid() {
cur=${COMP_WORDS[COMP_CWORD]}
complete -F _process killall
complete -F _pid kill
complete -F _pid strace
+complete -F _known_hosts kill_known_host
--- /dev/null
+#!/usr/bin/perl
+#
+# $Id$
+#
+# kill_known_host: Remove an entry from the ssh hosts file.
+# Usage: kill_known_host <IP>
+# kill_known_host <hostname>
+# Exits: 0 on success.
+# 1 on error.
+# 111 if the entry didn't exist.
+# Notes: Based on Jim's kill-known-host.
+#
+
+my $KNOWN_HOSTS = "$ENV{HOME}/.ssh/known_hosts";
+my $SCRATCH = "$KNOWN_HOSTS.$$";
+
+# Check args.
+unless (@ARGV) {
+ print STDERR "Usage: kill_known_host <IP>\n";
+ print STDERR "Usage: kill_known_host <hostname>\n";
+ print STDERR "Exits: 0 on success.\n";
+ print STDERR " 1 on error.\n";
+ print STDERR " 111 if the entry didn't exist.\n";
+ exit 1;
+}
+
+my $host = shift;
+my $re;
+
+# Check if it's an IP or a hostname.
+if ($host =~ /^[1-9]\d{0,2}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
+ $re = "^([^\\s]+,)?$host\\s";
+}
+else {
+ $re = "^$host\\s";
+}
+
+# Read known hosts.
+open IN, "< $KNOWN_HOSTS" or die "Can't read known_hosts: $!\n";
+
+# Open scratch file.
+open OUT, "> $SCRATCH" or die "Can't open scratch file: $!\n";
+
+my ($in, $out) = (0, 0);
+while (<IN>) {
+ $in++;
+ next if /$re/;
+ print OUT;
+ $out++;
+}
+
+# Cleanup.
+close OUT;
+close IN;
+
+# Move hosts.
+rename $SCRATCH, $KNOWN_HOSTS or die "Can't rename $KNOWN_HOSTS: $!\n";
+
+exit 111 if $in == $out;
+exit 0;