aboutsummaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
authorrjorgenson <rjorgenson@gmail.com>2017-01-10 00:41:46 +0300
committerrjorgenson <rjorgenson@gmail.com>2017-01-10 00:41:46 +0300
commit20a5556642c4cca23d4b65e05fa64999c492a13d (patch)
tree66881ed1f77d070356cf20ba6824a319ecedf8c3 /powerlevel9k.zsh-theme
parentcf88f861fa29d0d78ca08c7f831717945abb94eb (diff)
added the ability to specify and only attempt a particular method
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-xpowerlevel9k.zsh-theme41
1 files changed, 33 insertions, 8 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 437a1fb1..ef945613 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -448,17 +448,42 @@ prompt_public_ip() {
# grab a fresh IP if needed
if [[ $refresh_ip =~ true && -w $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then
- 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
+ # if method specified, don't use fallback methods
+ if [[ -n $POWERLEVEL9K_PUBLIC_IP_METHOD ]] && [[ $POWERLEVEL9K_PUBLIC_IP_METHOD =~ 'wget|curl|dig' ]]; then
+ local method=$POWERLEVEL9K_PUBLIC_IP_METHOD
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
- fresh_ip="$(curl --max-time 10 -w '\n' "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
- fi
+ 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
- if [[ -z "$fresh_ip" ]] && type -p wget >/dev/null; then
- fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
+ if [[ -z "$fresh_ip" ]] && type -p wget >/dev/null; then
+ fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
+ fi
fi
[[ -n $fresh_ip ]] && echo $fresh_ip > $POWERLEVEL9K_PUBLIC_IP_FILE
fi