From 7b13704c50fb2cbfb1eed252915c2ba39d2f3e60 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Fri, 1 Apr 2011 15:12:48 +0200 Subject: [PATCH] [zsh] Add features form grml.org/zsh Add research function (google/ wiki ....) Add Alias Add BROWSER env variable ... --- .zsh/10_Environment.zsh | 11 +++++ .zsh/20_fancy.zsh | 52 +++++++++++++++-------- .zsh/30_alias.zsh | 25 +++++++++++ .zsh/40_function.zsh | 91 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 162 insertions(+), 17 deletions(-) create mode 100755 .zsh/40_function.zsh diff --git a/.zsh/10_Environment.zsh b/.zsh/10_Environment.zsh index 2b425cf..b68bd21 100644 --- a/.zsh/10_Environment.zsh +++ b/.zsh/10_Environment.zsh @@ -17,3 +17,14 @@ export LESS="$LESS -XRF" #export GIT_PAGER="more" export EDITOR=/usr/bin/vim + +if [[ -z "$BROWSER" ]] ; then + if [[ -n "$DISPLAY" ]] ; then + #v# If X11 is running + export BROWSER=x-www-browser + else + #v# If no X11 is running + export BROWSER=links + fi +fi + diff --git a/.zsh/20_fancy.zsh b/.zsh/20_fancy.zsh index 437af6b..74fa01a 100644 --- a/.zsh/20_fancy.zsh +++ b/.zsh/20_fancy.zsh @@ -1,23 +1,41 @@ #thx to matthew loar for that! -if [[ $TERM == "screen" ]]; then +#if [[ $TERM == "screen" ]]; then +# +#function precmd { +# #prompt_adam1_precmd +# echo -ne "\033]83;title zsh\007" +#} +# +#function preexec { +# local foo="$2 " +# local bar=${${=foo}[1]} +# echo -ne "\033]83;title $bar\007" +#} +# +#fi +# +## Titre de la fenĂȘtre d'un xterm +#case $TERM in +# xterm*) +# precmd () {print -Pn "\e]0;%n@%m: %~\a"} +# ;; +#esac -function precmd { - #prompt_adam1_precmd - echo -ne "\033]83;title zsh\007" -} -function preexec { - local foo="$2 " - local bar=${${=foo}[1]} - echo -ne "\033]83;title $bar\007" -} - -fi - -# Titre de la fenĂȘtre d'un xterm case $TERM in - xterm*) - precmd () {print -Pn "\e]0;%n@%m: %~\a"} - ;; + *xterm*|rxvt|rxvt-unicode|rxvt-256color|rxvt-unicode-256color|(dt|k|E)term) + precmd () { print -Pn "\e]0;[%n@%M][%~]%#\a" } + preexec () { print -Pn "\e]0;[%n@%M][%~]%# ($1)\a" } + ;; + screen) + precmd () { + print -Pn "\e]83;title \"$1\"\a" + print -Pn "\e]0;$TERM - (%L) [%n@%M]%# [%~]\a" + } + preexec () { + print -Pn "\e]83;title \"$1\"\a" + print -Pn "\e]0;$TERM - (%L) [%n@%M]%# [%~] ($1)\a" + } + ;; esac diff --git a/.zsh/30_alias.zsh b/.zsh/30_alias.zsh index f487986..2727914 100644 --- a/.zsh/30_alias.zsh +++ b/.zsh/30_alias.zsh @@ -1,6 +1,7 @@ alias mv='nocorrect mv' # no spelling correction on mv alias cp='nocorrect cp' alias mkdir='nocorrect mkdir' +alias rm='nocorrect rm' #alias @@ -16,3 +17,27 @@ alias ../../..='cd ../../..' alias xte='nohup xterm &' # xte lancera un xterm qui ne se fermera pas si on ferme le terminal alias minicom='minicom -c on' + +#Extension Alias +alias -s html=$BROWSER +alias -s org=$BROWSER +alias -s php=$BROWSER +alias -s com=$BROWSER +alias -s net=$BROWSER +alias -s png=feh +alias -s jpg=feh +alias -s gif=feg +alias -s sxw=soffice +alias -s doc=soffice +alias -s gz=tar -xzvf +alias -s bz2=tar -xjvf +alias -s java=$EDITOR +alias -s txt=$EDITOR +alias -s PKGBUILD=$EDITOR + + +# command L equivalent to command |less +alias -g L='|less -R' + +# command S equivalent to command &> /dev/null & +alias -g S='&> /dev/null &' diff --git a/.zsh/40_function.zsh b/.zsh/40_function.zsh new file mode 100755 index 0000000..63708f2 --- /dev/null +++ b/.zsh/40_function.zsh @@ -0,0 +1,91 @@ +#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 ' >&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 +}