Last active
October 10, 2022 15:26
-
-
Save angely-dev/15a040dec4c6360c420e355efa362c80 to your computer and use it in GitHub Desktop.
Autocomplete SSH, SCP, ping, ..., based on known hosts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
get_ssh_known_hosts() { | |
known_hosts=$(cat ~/.ssh/known_hosts | cut -d' ' -f1) | |
starts_with=$2 | |
COMPREPLY=( $(compgen -W "$known_hosts" -- "$starts_with") ) | |
return 0 | |
} | |
complete -F get_ssh_known_hosts ssh scp ping nslookup my-custom-command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How To
~/.local/bin
~/.bashrc
file (or source it manually):Demo
I used a Docker container just to be in a minimal isolated environment but Docker is not needed for this to work!
Dockerfile I used if needed:
To build it and run it:
$ docker build -t just-bash-ssh . $ docker run -it --rm just-bash-ssh bash
Note
This is based on
~/.ssh/known_hosts
file. This requires known hosts hashing to be disabled in~/.ssh/config
file (by default in most cases):See: https://security.stackexchange.com/questions/56268/ssh-benefits-of-using-hashed-known-hosts