mirror of
https://github.com/TECHNOFAB11/tmux2k.git
synced 2025-12-11 23:50:08 +01:00
style: shellcheck fixes
This commit is contained in:
parent
54ecf3dc0b
commit
de0e8225a6
10 changed files with 356 additions and 389 deletions
|
|
@ -6,68 +6,63 @@ fahrenheit=$1
|
|||
location=$2
|
||||
fixedlocation=$3
|
||||
|
||||
display_location()
|
||||
{
|
||||
if $location && [[ ! -z "$fixedlocation" ]]; then
|
||||
echo " $fixedlocation"
|
||||
elif $location; then
|
||||
city=$(curl -s https://ipinfo.io/city 2> /dev/null)
|
||||
region=$(curl -s https://ipinfo.io/region 2> /dev/null)
|
||||
echo " $city, $region"
|
||||
else
|
||||
echo ''
|
||||
fi
|
||||
display_location() {
|
||||
if $location && [[ -n "$fixedlocation" ]]; then
|
||||
echo " $fixedlocation"
|
||||
elif $location; then
|
||||
city=$(curl -s https://ipinfo.io/city 2>/dev/null)
|
||||
region=$(curl -s https://ipinfo.io/region 2>/dev/null)
|
||||
echo " $city, $region"
|
||||
else
|
||||
echo ''
|
||||
fi
|
||||
}
|
||||
|
||||
fetch_weather_information()
|
||||
{
|
||||
display_weather=$1
|
||||
# it gets the weather condition textual name (%C), and the temperature (%t)
|
||||
curl -sL wttr.in/$fixedlocation\?format="%C+%t$display_weather"
|
||||
fetch_weather_information() {
|
||||
display_weather=$1
|
||||
# it gets the weather condition textual name (%C), and the temperature (%t)
|
||||
curl -sL wttr.in/"$fixedlocation"\?format="%C+%t$display_weather"
|
||||
}
|
||||
|
||||
#get weather display
|
||||
display_weather()
|
||||
{
|
||||
if $fahrenheit; then
|
||||
display_weather='&u' # for USA system
|
||||
else
|
||||
display_weather='&m' # for metric system
|
||||
fi
|
||||
weather_information=$(fetch_weather_information $display_weather)
|
||||
display_weather() {
|
||||
if $fahrenheit; then
|
||||
display_weather='&u' # for USA system
|
||||
else
|
||||
display_weather='&m' # for metric system
|
||||
fi
|
||||
weather_information=$(fetch_weather_information $display_weather)
|
||||
|
||||
weather_condition=$(echo "$weather_information" | rev | cut -d ' ' -f2- | rev) # Sunny, Snow, etc
|
||||
temperature=$(echo "$weather_information" | rev | cut -d ' ' -f 1 | rev) # +31°C, -3°F, etc
|
||||
unicode=$(forecast_unicode "$weather_condition")
|
||||
weather_condition=$(echo "$weather_information" | rev | cut -d ' ' -f2- | rev) # Sunny, Snow, etc
|
||||
temperature=$(echo "$weather_information" | rev | cut -d ' ' -f 1 | rev) # +31°C, -3°F, etc
|
||||
unicode=$(forecast_unicode "$weather_condition")
|
||||
|
||||
echo "$unicode${temperature/+/}" # remove the plus sign to the temperature
|
||||
echo "$unicode${temperature/+/}" # remove the plus sign to the temperature
|
||||
}
|
||||
|
||||
forecast_unicode()
|
||||
{
|
||||
weather_condition=$(echo "$weather_condition" | awk '{print tolower($0)}')
|
||||
forecast_unicode() {
|
||||
weather_condition=$(echo "$weather_condition" | awk '{print tolower($0)}')
|
||||
|
||||
if [[ $weather_condition =~ 'snow' ]]; then
|
||||
echo '❄ '
|
||||
elif [[ (($weather_condition =~ 'rain') || ($weather_condition =~ 'shower')) ]]; then
|
||||
echo '☂ '
|
||||
elif [[ (($weather_condition =~ 'overcast') || ($weather_condition =~ 'cloud')) ]]; then
|
||||
echo '☁ '
|
||||
elif [[ $weather_condition = 'NA' ]]; then
|
||||
echo ''
|
||||
else
|
||||
echo '☀ '
|
||||
fi
|
||||
if [[ $weather_condition =~ 'snow' ]]; then
|
||||
echo '❄ '
|
||||
elif [[ (($weather_condition =~ 'rain') || ($weather_condition =~ 'shower')) ]]; then
|
||||
echo '☂ '
|
||||
elif [[ (($weather_condition =~ 'overcast') || ($weather_condition =~ 'cloud')) ]]; then
|
||||
echo '☁ '
|
||||
elif [[ $weather_condition = 'NA' ]]; then
|
||||
echo ''
|
||||
else
|
||||
echo '☀ '
|
||||
fi
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
# process should be cancelled when session is killed
|
||||
if ping -q -c 1 -W 1 ipinfo.io &>/dev/null; then
|
||||
echo "$(display_weather)$(display_location)"
|
||||
else
|
||||
echo "Location Unavailable"
|
||||
fi
|
||||
main() {
|
||||
# process should be cancelled when session is killed
|
||||
if ping -q -c 1 -W 1 ipinfo.io &>/dev/null; then
|
||||
echo "$(display_weather)$(display_location)"
|
||||
else
|
||||
echo "Location Unavailable"
|
||||
fi
|
||||
}
|
||||
|
||||
#run main driver program
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue