config/.zsh/40_function.zsh

92 lines
2.3 KiB
Bash
Raw Normal View History

#Search on Google
google() {
emulate -L zsh
${=BROWSER} "http://www.google.com/search?&num=100&q=$*"
}
#Search French Wiktionary
wikdic_fr() {
emulate -L zsh
${=BROWSER} http://fr.wiktionary.org/wiki/${(C)1// /_}
}
#Search English Wiktionary
wikdic_en() {
emulate -L zsh
${=BROWSER} http://en.wiktionary.org/wiki/${(C)1// /_}
}
#Search French Wikipedia
wiki_fr() {
emulate -L zsh
${=BROWSER} "http://fr.wikipedia.org/w/index.php?title=Special%3ASearch&search=$*"
}
#Search English Wikipedia
wiki_en() {
emulate -L zsh
${=BROWSER} "http://en.wikipedia.org/w/index.php?title=Special%3ASearch&search=$*"
}
#French conjugaison
verbe() {
emulate -L zsh
${=BROWSER} "http://www.la-conjugaison.fr/du/verbe/${*}.php"
}
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
}
battery() {
if [[ $BATTERY -gt 0 ]] ; then
PERCENT="${${"$(acpi 2>/dev/null)"}/(#b)[[:space:]]#Battery <->: [^0-9]##, (<->)%*/${match[1]}}"
if [[ -z "$PERCENT" ]] ; then
PERCENT='acpi not present'
else
if [[ "$PERCENT" -lt 20 ]] ; then
PERCENT="warning: ${PERCENT}%%"
else
PERCENT="${PERCENT}%%"
fi
fi
fi
}