I want to write just curl 8000
to work as curl localhost:8000
.
I’ve come up with the following zsh function so far:
function curl() {
local first_arg="$1"
if [[ "$first_arg" =~ ^([0-9]{4})(.*)$ ]]; then
local modified_url="localhost:${first_arg}"
command curl "$modified_url" "${@:2}"
else
command curl "$@"
fi
}
But obviously, the url is not guaranteed to be the first argument, such as curl -H '...' localhost:8000
. Is there a robust existing solution for such needs?