commit f18cdd440ad98883c71e327d33c6e4782dc08352
parent f730eb6cba02432728743ade70a4f0a937ea6a71
Author: Frederic Cambus <fcambus@users.sourceforge.net>
Date: Mon, 21 Oct 2013 08:37:19 -0700
Merge pull request #2 from qbit/master
Allow config options to be set in ~/.ansiweatherrc
Diffstat:
2 files changed, 43 insertions(+), 16 deletions(-)
diff --git a/README.md b/README.md
@@ -11,7 +11,7 @@ Weather data comes from the `OpenWeatherMap` free weather API.
AnsiWeather requires the following dependencies :
-- cURL (used to fetch Weather data) : http://curl.haxx.se
+- A command to fetch HTTP data such as [cURL](http://curl.haxx.se) or [wget](https://www.gnu.org/software/wget/)
- jq (lightweight and flexible command-line JSON processor) : http://stedolan.github.io/jq/
## Usage
@@ -25,6 +25,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
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
###############################################################################
# #
@@ -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)