Skip to content

Instantly share code, notes, and snippets.

@cvonkleist
Last active May 13, 2022 16:54
Show Gist options
  • Save cvonkleist/658b6f98346bf51769e96049f84bb45d to your computer and use it in GitHub Desktop.
Save cvonkleist/658b6f98346bf51769e96049f84bb45d to your computer and use it in GitHub Desktop.
Get IP address of hostname in SSH config, with ZSH completion
# show ip address for ssh host, with zsh completion for hostname
_sship () { ssh -G $1 | awk '/^hostname/ {print $2}' }
compdef _sship=ssh
# Usage
# =====
# Add the above two lines to the bottom of your ~/.zshrc file.
#
# Use it like this on the commandline:
#
# _sship somebox1
# 11.22.33.44 # <= this is what it will print
#
# This is what your ~/.ssh/config might look like:
#
# Host somebox1
# HostName 11.22.33.44
# Host otherbox22
# LocalForward 1234 localhost:4567
# HostName 22.33.44.55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment