zshrc: Move weather to its own file
authorFrank Terbeck <ft@bewatermyfriend.org>
Mon, 28 Nov 2011 21:02:04 +0000 (22:02 +0100)
committerMichael Prokop <mika@grml.org>
Tue, 6 Dec 2011 13:50:43 +0000 (14:50 +0100)
Signed-off-by: Frank Terbeck <ft@bewatermyfriend.org>
etc/zsh/zshrc
usr_share_grml/zsh/functions/weather [new file with mode: 0644]

index b87dab9..88f736c 100644 (file)
@@ -3681,51 +3681,6 @@ fluxkey-change() {
     fi
 }
 
-# retrieve weather information on the console
-# Usage example: 'weather LOWG'
-weather() {
-    emulate -L zsh
-    [[ -n "$1" ]] || {
-        print 'Usage: weather <station_id>' >&2
-        print 'List of stations: http://en.wikipedia.org/wiki/List_of_airports_by_ICAO_code'>&2
-        return 1
-    }
-
-    local VERBOSE="yes"    # TODO: Make this a command line switch
-
-    local ODIR=`pwd`
-    local PLACE="${1:u}"
-    local DIR="${HOME}/.weather"
-    local LOG="${DIR}/log"
-
-    [[ -d ${DIR} ]] || {
-        print -n "Creating ${DIR}: "
-        mkdir ${DIR}
-        print 'done'
-    }
-
-    print "Retrieving information for ${PLACE}:"
-    print
-    cd ${DIR} && wget -T 10 --no-verbose --output-file=$LOG --timestamping http://weather.noaa.gov/pub/data/observations/metar/decoded/$PLACE.TXT
-
-    if [[ $? -eq 0 ]] ; then
-        if [[ -n "$VERBOSE" ]] ; then
-            cat ${PLACE}.TXT
-        else
-            DATE=$(grep 'UTC' ${PLACE}.TXT | sed 's#.* /##')
-            TEMPERATURE=$(awk '/Temperature/ { print $4" degree Celcius / " $2" degree Fahrenheit" }' ${PLACE}.TXT | tr -d '(')
-            echo "date: $DATE"
-            echo "temp:  $TEMPERATURE"
-        fi
-    else
-        print "There was an error retrieving the weather information for $PLACE" >&2
-        cat $LOG
-        cd $ODIR
-        return 1
-    fi
-    cd $ODIR
-}
-
 # mercurial related stuff
 if check_com -c hg ; then
     # gnu like diff for mercurial
diff --git a/usr_share_grml/zsh/functions/weather b/usr_share_grml/zsh/functions/weather
new file mode 100644 (file)
index 0000000..44a87e1
--- /dev/null
@@ -0,0 +1,49 @@
+# retrieve weather information on the console
+# Usage example: 'weather LOWG'
+
+emulate -L zsh
+
+if [[ -n "$1" ]]; then
+    print 'Usage: weather <station_id>'
+    print \
+  'List of stations: http://en.wikipedia.org/wiki/List_of_airports_by_ICAO_code'
+    return 0
+fi
+
+local VERBOSE="yes"    # TODO: Make this a command line switch
+
+local ODIR=`pwd`
+local PLACE="${1:u}"
+local DIR="${HOME}/.weather"
+local LOG="${DIR}/log"
+
+if [[ -d ${DIR} ]]; then
+    print -n "Creating ${DIR}: "
+    mkdir ${DIR}
+    print 'done'
+fi
+
+print "Retrieving information for ${PLACE}:"
+print
+cd ${DIR} && \
+  wget -T 10 --no-verbose --output-file=$LOG --timestamping \
+       http://weather.noaa.gov/pub/data/observations/metar/decoded/$PLACE.TXT
+
+if [[ $? -eq 0 ]]; then
+    if [[ -n "$VERBOSE" ]] ; then
+        cat ${PLACE}.TXT
+    else
+        DATE=$(grep 'UTC' ${PLACE}.TXT | sed 's#.* /##')
+        TEMPERATURE=$(awk '/Temperature/ {
+                             print $4" degree Celcius / " $2" degree Fahrenheit"
+                           }' ${PLACE}.TXT | tr -d '(')
+        echo "date: $DATE"
+        echo "temp:  $TEMPERATURE"
+    fi
+else
+    print "There was an error retrieving the weather information for $PLACE" >&2
+    cat $LOG
+    cd $ODIR
+    return 1
+fi
+cd $ODIR