odedlaz / tmux-status-variables

Tmux plugin that adds support for scriptable variables in the status line
MIT License
18 stars 4 forks source link

Status bar shows "null" most of the time. #1

Open wuweituzi opened 3 years ago

wuweituzi commented 3 years ago

I have everything configured correctly on my linux system. On some days, the status bar shows the correct values but on most days it shows "null" for all variables.

From my .tmux.conf:

set -g @plugin 'odedlaz/tmux-status-variables'
set -g @ipinfo_format "\
📍 #ip \
(#city, #region #country) \
🏭 #isp "

What's breaking here?

winstonmyers commented 2 years ago

I was having this same issue, and it seems due to hitting the daily limit for the unauthenticated API, here's the ouput with set +x enabled:

++++ get_isp '{ "status": 429, "error": { "title": "Rate limit exceeded", "message": "You'\''ve hit the daily limit for the unauthenticated API. Create an API access token by signing up to get 50k req/month." } }'

I've got a fix for this that sets the $ipinfo="" and enables a sleep timer that waits until the next day to begin running again, using the Plugin Skeleton described in the README.

Here are my current changes within ./tmux-status-variables/scripts/ipinfo.tmux, with line numbers and git gutters:

   17 on_cache_miss() {
   18    log "ipinfo" "getting fresh data from ipinfo.io"
   19    data="$(curl -s ipinfo.io/json)"
   20    log "ipinfo" "$data"
   21
   22    ipinfo=$ipinfo_format
   23    for field in ${fields[@]}; do
   24       get_field_fn="get_$field"
   25
   26       if declare -f $get_field_fn > /dev/null; then
   27          value=$($get_field_fn "$data")
   28       else
   29          value=$(echo $data | jq -r .$field)
   30       fi
   31
   32       ipinfo=${ipinfo/\#$field/$value}
   33    done
   34
~  35    if [ "$ipinfo" != *"null"* ]; then
+  36       echo $ipinfo
+  37       sleep 5m
+  38    else
+  39       ipinfo=""
+  40       echo "$ipinfo"
+  41       sleep "$(($(date -d 23:59:59 +%s) - $(date +%s) + 1))s"
+  42    fi
   43 }

@odedlaz would this be a viable fix for the issue?