Skip to content

Instantly share code, notes, and snippets.

@Goryudyuma
Last active January 3, 2019 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Goryudyuma/e9b856366c457799d0a4c0c71ced54ff to your computer and use it in GitHub Desktop.
Save Goryudyuma/e9b856366c457799d0a4c0c71ced54ff to your computer and use it in GitHub Desktop.
雨が降るまでの時間をターミナルに出す
export NEXT_RAIN_TIME
export NEXT_RAIN_TIME_LAST_UPDATE=0
update_weather_countdown() {
NEXT_RAIN_TIME=$(curl -s 'https://map.yahooapis.jp/weather/V1/place?coordinates=139.7649361,35.6812405&appid=$(Client ID)&output=json&interval=5' | jq -r -c '.Feature[0].Property.WeatherList.Weather | map(select(.["Rainfall"] > 0)) | .[0].Date')
NEXT_RAIN_TIME_LAST_UPDATE=$(date '+%s')
}
PERIOD=60
add-zsh-hook periodic update_weather_countdown
show_weather_countdown() {
if [[ $NEXT_RAIN_TIME =~ "^([0-9])+$" ]]; then
NOW_TIME=$(date "+%s")
NEXT_RAIN_TIME_UNIX_TIME=$(date -j -f "%Y%m%d%H%M%S" "${NEXT_RAIN_TIME}00" "+%s")
COUNT_DOWN=$(expr ${NEXT_RAIN_TIME_UNIX_TIME} - ${NOW_TIME})
if [ ${COUNT_DOWN} -lt 0 ]; then
echo '雨'
else
echo '雨まであと'${COUNT_DOWN}"s"
fi
else
if [[ $NEXT_RAIN_TIME = 'null' ]]; then
echo '晴'
else
echo '取得エラー'
fi
fi
}
#RPROMPT=$'$(show_weather_countdown)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment