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 hidden or 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
For reference: https://www.gnu.org/software/bash/manual/html_node/A-Programmable-Completion-Example.html