ansiweather

Weather in terminal, with ANSI colors and Unicode symbols
Log | Files | Refs | README | LICENSE

commit 381cb653f047d84bb59f1f46f439ffd6380a750d
parent 46ccb5e6a993fd9f40f61301ba5ed4b4fcd252e6
Author: Aaron Bieber <deftly@gmail.com>
Date:   Sat, 19 Oct 2013 09:27:25 -0600

add ability to store options in config file

Diffstat:
MREADME.md | 9+++++++++
Mansiweather | 46++++++++++++++++++++++++++++++++--------------
2 files changed, 41 insertions(+), 14 deletions(-)

diff --git a/README.md b/README.md @@ -23,6 +23,15 @@ After cloning the repository, simply invoke the script by typing : The following configuration options are available and should be set according to your location and preferences. +Config options can also be set in ~/.ansiweatherrc + +Example : `~/.ansiweatherrc` + + location:Moscow,RU + fetch_cmd:ftp -V -o - + units:metric + + ### Location Example : `Moscow,RU` diff --git a/ansiweather b/ansiweather @@ -17,39 +17,57 @@ ###[ Configuration options ]################################################### +config_file=~/.ansiweatherrc + +function get_config { + ret="" + if [ -f $config_file ] + then + ret=$(grep $1 $config_file | awk -F\: '{print $2}') + fi + + if [ "X$ret" = "X" ] + then + return 1 + else + echo $ret + fi +} + # Location : example "Moscow,RU" -location="Moscow,RU" +location=$(get_config "location" || echo "Moscow,RU") # System of Units : "metric" or "imperial" -units="metric" +units=$(get_config "units" || echo "metric") # Display symbols : "true" or "false" (requires an Unicode capable display) -symbols=true - +symbols=$(get_config "symbols" || echo true) #### [ Colors and characters ]################################################# -background="\033[44m" -text="\033[36;1m" -data="\033[33;1m" -delimiter="\033[35m=>" -dashes="\033[34m-" +background=$(get_config "background" || echo "\033[44m") +text=$(get_config "text" || echo "\033[36;1m") +data=$(get_config "data" || echo "\033[33;1m") +delimiter=$(get_config "delimiter" || echo "\033[35m=>") +dashes=$(get_config "dashes" || echo "\033[34m-") ###[ Unicode Symbols for icons ]############################################### -sun="\033[33;1m\xe2\x98\x80" -moon="\033[36m\xe2\x98\xbd" -clouds="\033[37;1m\xe2\x98\x81" -rain="\xe2\x98\x94" +sun=$(get_config "sun" || echo "\033[33;1m\xe2\x98\x80") +moon=$(get_config "moon" || echo "\033[36m\xe2\x98\xbd") +clouds=$(get_config "clouds" || echo "\033[37;1m\xe2\x98\x81") +rain=$(get_config "rain" || echo "\xe2\x98\x94") ###[ Fetch Weather data ]###################################################### -weather=$(curl -s http://api.openweathermap.org/data/2.5/weather?q=$location\&units=$units) +fetch_cmd=$(get_config "fetch_cmd" || echo "curl -s") + +weather=$($fetch_cmd http://api.openweathermap.org/data/2.5/weather?q=$location\&units=$units)