Adding support for httpie 😄

This commit is contained in:
Alex Epstein 2017-07-31 23:42:48 -04:00
parent 2b0d1cf653
commit 9d66388cd2
17 changed files with 203 additions and 145 deletions

View File

@ -16,10 +16,12 @@ getConfiguredClient()
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed."
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
@ -30,6 +32,7 @@ httpGet()
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}

View File

@ -17,29 +17,31 @@ getConfiguredClient()
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed."
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
checkInternet()
{
httpGet google.com > /dev/null 2>&1 || { echo "Error: no active internet connection" >&2; return 1; } # query google with a get request
}
## Allows to call the users configured client without if statements everywhere
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}
checkInternet()
{
httpGet google.com > /dev/null 2>&1 || { echo "Error: no active internet connection" >&2; return 1; } # query google with a get request
}
update()
{

View File

@ -15,16 +15,19 @@ checkOpenSSL()
fi
}
## This function determines which http get tool the system has installed and returns an error if there isnt one
getConfiguredClient()
{
if command -v curl &>/dev/null; then
if command -v curl &>/dev/null; then
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed."
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
@ -35,6 +38,7 @@ httpGet()
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}

View File

@ -9,25 +9,27 @@ configuredClient=""
## This function determines which http get tool the system has installed and returns an error if there isnt one
getConfiguredClient()
{
if command -v curl &>/dev/null; then
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed."
return 1
fi
if command -v curl &>/dev/null; then
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
## Allows to call the users configured client without if statements everywhere
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s -N "$@" ;;
wget) wget -qO- "$@" ;;
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}
@ -55,7 +57,7 @@ checkTargetCurrency()
echo "1"
else
echo "0"
fi
fi
}
## Grabs the base currency from the user and validates it with all the possible currency
@ -88,7 +90,7 @@ checkBase()
# Matches the symbol to the appropriate ids regarding the API calling.
transformBase()
{
case "$base" in
case "$base" in
"ETH") reqId="ethereum" ;;
"BTC") reqId="bitcoin" ;;
"XRP") reqId="ripple" ;;
@ -167,10 +169,10 @@ convertCurrency()
exchangeAmount=$(echo "$exchangeRate * $amount" | bc )
exchangeTo=$(echo "$exchangeTo" | tr '[:lower:]' '[:upper:]')
base=$(echo "$base" | tr '[:lower:]' '[:upper:]')
cat <<EOF
=========================
| $base to $exchangeTo
| $base to $exchangeTo
| Rate: $exchangeRate
| $base: $amount
| $exchangeTo: $exchangeAmount
@ -244,7 +246,7 @@ Supported Target Currencies:
| CNY | EUR | GBP | HKD |
| IDR | INR | JPY | KRW |
| MXN | RUB | USD |
_______________________
_______________________
Examples:
cryptocurrency BTC USD 12.35

View File

@ -10,30 +10,33 @@ currencyCodes=(AUD BGN BRL CAD CHF CNY CZK DKK
JPY KRW MXN MYR NOK NZD PHP PLN
RON RUB SEK SGD THB TRY USD ZAR)
## This function determines which http get tool the system has installed and returns an error if there isnt one
getConfiguredClient()
{
## This function determines which http get tool the system has installed and returns an error if there isnt one
getConfiguredClient()
{
if command -v curl &>/dev/null; then
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed."
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
}
## Allows to call the users configured client without if statements everywhere
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
fetch) fetch -o "..." ;;
esac
}
## Allows to call the users configured client without if statements everywhere
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}
checkValidCurrency()
{

View File

@ -17,10 +17,12 @@ getConfiguredClient()
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed."
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
@ -31,6 +33,7 @@ httpGet()
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}

29
geo/geo
View File

@ -8,24 +8,29 @@ currentVersion="1.16.2"
configuredClient=""
## This function determines which http get tool the system has installed and returns an error if there isnt one
getConfiguredClient() {
if command -v curl &>/dev/null; then
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed."
return 1
fi
getConfiguredClient()
{
if command -v curl &>/dev/null; then
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
## Allows to call the users configured client without if statements everywhere
httpGet() {
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}

View File

@ -9,16 +9,29 @@ detail=false
## This function determines which http get tool the system has installed and returns an error if there isnt one
getConfiguredClient()
{
if command -v curl &>/dev/null ; then
configuredClient="curl"
elif command -v wget &>/dev/null ; then
configuredClient="wget"
elif command -v fetch &>/dev/null ; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed."
return 1
fi
if command -v curl &>/dev/null; then
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
## Allows to call the users configured client without if statements everywhere
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}
getConfiguredPython()
@ -43,17 +56,6 @@ if [[ $(uname) != "Darwin" ]]; then
}
fi
## Allows to call the users configured client without if statements everywhere
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
fetch) fetch -o "..." ;;
esac
}
checkInternet()
{
httpGet google.com > /dev/null 2>&1 || { echo "Error: no active internet connection" >&2; return 1; } # query google with a get request

View File

@ -6,12 +6,30 @@ configuredClient=""
flagCount="0"
declare -a simpleOperations=(simplify factor derive integrate zeroes roots tangent area cos sin tan arccos arcsin arctan abs log)
## This function determines which http get tool the system has installed and returns an error if there isnt one
getConfiguredClient()
{
if command -v curl &>/dev/null; then
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
## Allows to call the users configured client without if statements everywhere
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}
@ -63,21 +81,6 @@ update()
fi
}
## This function determines which http get tool the system has installed and returns an error if there isnt one
getConfiguredClient()
{
if command -v curl &>/dev/null ; then
configuredClient="curl"
elif command -v wget &>/dev/null ; then
configuredClient="wget"
elif command -v fetch &>/dev/null ; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed."
return 1
fi
}
validateExpression()
{
local parsedExpression # only used here

View File

@ -5,18 +5,34 @@ currentVersion="1.16.2"
multiline="0" # flag that indicates multiline option
## This function determines which http get tool the system has installed and returns an error if there isnt one
getConfiguredClient()
{
if command -v curl &> /dev/null; then
if command -v curl &>/dev/null; then
configuredClient="curl"
elif command -v wget &> /dev/null; then
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool requires either curl or wget to be installed." >&2
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
## Allows to call the users configured client without if statements everywhere
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}
update()
{
# Author: Alexander Epstein https://github.com/alexanderepstein
@ -57,14 +73,6 @@ update()
fi
}
httpGet()
{
case "${configuredClient}" in
curl) curl -A curl -s "$@";;
wget) wget -qO- "$@";;
esac
}
makeqr()
{
input=$(echo ${input} | sed s/" "/%20/g ) ## replace all spaces in the sentence with HTML-encoded space %20

View File

@ -12,14 +12,27 @@ getConfiguredClient()
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed."
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
## Allows to call the users configured client without if statements everywhere
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}
getConfiguredPython()
{
@ -43,15 +56,6 @@ if [[ $(uname) != "Darwin" ]];then
}
fi
## Allows to call the users configured client without if statements everywhere
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
fetch) fetch -o "..." ;;
esac
}
checkInternet()
{

View File

@ -13,16 +13,19 @@ checkOpenSSL()
fi
}
## This function determines which http get tool the system has installed and returns an error if there isnt one
getConfiguredClient()
{
if command -v curl &>/dev/null; then
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed."
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
@ -33,6 +36,7 @@ httpGet()
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}

View File

@ -12,14 +12,27 @@ getConfiguredClient()
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed."
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
## Allows to call the users configured client without if statements everywhere
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}
getConfiguredPython()
{
if command -v python2 &>/dev/null; then
@ -42,16 +55,6 @@ if [[ $(uname) != "Darwin" ]]; then
}
fi
## Allows to call the users configured client without if statements everywhere
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
fetch) fetch -o "..." ;;
esac
}
checkInternet()
{
httpGet google.com > /dev/null 2>&1 || { echo "Error: no active internet connection" >&2; return 1; } # query google with a get request

View File

@ -16,14 +16,27 @@ getConfiguredClient()
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed."
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
## Allows to call the users configured client without if statements everywhere
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}
getConfiguredPython()
{
if command -v python2 &>/dev/null; then
@ -46,16 +59,6 @@ if [[ $(uname) != "Darwin" ]]; then
}
fi
## Allows to call the users configured client without if statements everywhere
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
fetch) fetch -o "..." ;;
esac
}
checkInternet()
{
httpGet google.com > /dev/null 2>&1 || { echo "Error: no active internet connection" >&2; return 1; } # query google with a get request

View File

@ -11,10 +11,12 @@ getConfiguredClient()
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed."
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
@ -25,6 +27,7 @@ httpGet()
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}
@ -164,7 +167,7 @@ while getopts "cr:a:guvh" opt; do
;;
c) if [[ $flag == "" ]]; then
flag="clear"
else
else
echo "Error: all flags are mutually exclusive"
exit 1
fi

View File

@ -13,10 +13,12 @@ getConfiguredClient()
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed."
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed\." >&2
return 1
fi
}
@ -27,6 +29,7 @@ httpGet()
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}

View File

@ -16,29 +16,32 @@ getConfiguredClient()
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, or fetch to be installed." >&2
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed\." >&2
return 1
fi
}
checkInternet()
{
httpGet google.com > /dev/null 2>&1 || { echo "Error: no active internet connection" >&2; return 1; } # query google with a get request
}
## Allows to call the users configured client without if statements everywhere
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -o "..." ;;
esac
}
checkInternet()
{
httpGet google.com > /dev/null 2>&1 || { echo "Error: no active internet connection" >&2; return 1; } # query google with a get request
}
update()
{
# Author: Alexander Epstein https://github.com/alexanderepstein