Created
August 10, 2021 09:30
-
-
Save gervaisb/d8f7ae23dc4994abc53b7bca31c2d91b to your computer and use it in GitHub Desktop.
A wrapper over the MacOs hostname command to accept the '-i' or '--ip-address' flag.
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
#!/bin/sh | |
# hostname.sh - a wrapper over the MacOs hostname command to accept the '-i' | |
# or '--ip-address' flag. | |
# | |
# SYNOPSIS | |
# hostname [-i|--ip-address] [*] | |
# | |
# OPTIONS | |
# -i, --ip-address | |
# Display the IP address(es) of the host. | |
# * | |
# Delegate everything to '/bin/hostname'. | |
get_ip_adress () { | |
# This is a naive implementation that assume there is | |
# only one active network device. | |
ifconfig en0 | awk '/inet / {print $2; }' | |
exit 0 | |
} | |
delegate () { | |
/bin/hostname "$@" | |
} | |
if [ $1 == '-i' ] || [ $1 == '--ip-address' ] | |
then | |
get_ip_adress | |
else | |
delegate "$@" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I missed the
hostname -i
command too much and created this naive wrapper that can print my IP address.To use it I have aliased it to
hostname
: