[zsh] Add features form grml.org/zsh

Add research function (google/ wiki ....)
Add Alias
Add BROWSER env variable
...
This commit is contained in:
Mathieu Maret 2011-04-01 15:12:48 +02:00
parent b499a0f5e0
commit 7b13704c50
4 changed files with 162 additions and 17 deletions

View File

@ -17,3 +17,14 @@ export LESS="$LESS -XRF"
#export GIT_PAGER="more" #export GIT_PAGER="more"
export EDITOR=/usr/bin/vim 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

View File

@ -1,23 +1,41 @@
#thx to matthew loar for that! #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 case $TERM in
xterm*) *xterm*|rxvt|rxvt-unicode|rxvt-256color|rxvt-unicode-256color|(dt|k|E)term)
precmd () {print -Pn "\e]0;%n@%m: %~\a"} 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 esac

View File

@ -1,6 +1,7 @@
alias mv='nocorrect mv' # no spelling correction on mv alias mv='nocorrect mv' # no spelling correction on mv
alias cp='nocorrect cp' alias cp='nocorrect cp'
alias mkdir='nocorrect mkdir' alias mkdir='nocorrect mkdir'
alias rm='nocorrect rm'
#alias #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 xte='nohup xterm &' # xte lancera un xterm qui ne se fermera pas si on ferme le terminal
alias minicom='minicom -c on' 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 &'

91
.zsh/40_function.zsh Executable file
View File

@ -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 <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
}