1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-11-29 06:40:08 +00:00

added the ability to specify and only attempt a particular method

This commit is contained in:
rjorgenson 2017-01-09 14:41:46 -07:00
parent cf88f861fa
commit 20a5556642

View file

@ -448,17 +448,42 @@ prompt_public_ip() {
# grab a fresh IP if needed # grab a fresh IP if needed
if [[ $refresh_ip =~ true && -w $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then if [[ $refresh_ip =~ true && -w $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then
if type -p dig >/dev/null; then # if method specified, don't use fallback methods
fresh_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com 2> /dev/null)" if [[ -n $POWERLEVEL9K_PUBLIC_IP_METHOD ]] && [[ $POWERLEVEL9K_PUBLIC_IP_METHOD =~ 'wget|curl|dig' ]]; then
[[ "$fresh_ip" =~ ^\; ]] && unset fresh_ip local method=$POWERLEVEL9K_PUBLIC_IP_METHOD
fi fi
if [[ -n $method ]]; then
case $method in
'dig')
if type -p dig >/dev/null; then
fresh_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com 2> /dev/null)"
[[ "$fresh_ip" =~ ^\; ]] && unset fresh_ip
fi
;;
'curl')
if [[ -z "$fresh_ip" ]] && type -p curl >/dev/null; then
fresh_ip="$(curl --max-time 10 -w '\n' "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
fi
;;
'wget')
if [[ -z "$fresh_ip" ]] && type -p wget >/dev/null; then
fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
fi
;;
esac
else
if type -p dig >/dev/null; then
fresh_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com 2> /dev/null)"
[[ "$fresh_ip" =~ ^\; ]] && unset fresh_ip
fi
if [[ -z "$fresh_ip" ]] && type -p curl >/dev/null; then if [[ -z "$fresh_ip" ]] && type -p curl >/dev/null; then
fresh_ip="$(curl --max-time 10 -w '\n' "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)" fresh_ip="$(curl --max-time 10 -w '\n' "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
fi fi
if [[ -z "$fresh_ip" ]] && type -p wget >/dev/null; then if [[ -z "$fresh_ip" ]] && type -p wget >/dev/null; then
fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)" fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
fi
fi fi
[[ -n $fresh_ip ]] && echo $fresh_ip > $POWERLEVEL9K_PUBLIC_IP_FILE [[ -n $fresh_ip ]] && echo $fresh_ip > $POWERLEVEL9K_PUBLIC_IP_FILE
fi fi