Last active
January 17, 2019 21:05
-
-
Save blizzrdof77/e2b4307d067667644db7e8bac314f7d9 to your computer and use it in GitHub Desktop.
Better `ping` support to allow for mixed domains/hostnames w/ protocals (e.g. `ping 'https://who.is/my/ping/?example=this'`)
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
# ------------------------------------------ | |
# Better `ping` support to allow for mixed | |
# domains/hostnames with protocols (e.g. 'http://..') | |
# | |
# @1 = host | |
# -> Example usage: | |
# ping http://google.com/ | |
# ------------------------------------------ | |
function ping { | |
local pingdomain="$1" | |
shopt -s nocasematch # allow for lowercase | |
pingdomain=${pingdomain/#*:\/\/} # strip leading protocol | |
pingdomain=${pingdomain/#*:*@/} # strip leading user:pass@ | |
pingdomain=$(echo "${pingdomain//"?"//}") # strip trailing '?' onwards | |
pingdomain="$(echo "$pingdomain" | cut -d/ -f 1)" # strip trailing '/' onwards | |
if [[ "$#" = "0" ]] && [[ -f $HISTFILE ]]; then | |
pingdomain=${$(tail -n 1 $HISTFILE)} | |
pingdomain=${pingdomain/#*ping /} | |
ping "$(echo $pingdomain)" | |
else | |
echo "Pinging hostname \"$pingdomain\"" | |
command ping $pingdomain | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment