fonctions
#! zsh
# $Id: fonctions,v 1.3 2000/10/12 01:16:45 seb Exp $
# {{{ Prompt
function setprompt {
# export PROMPT="%{$COLOR3%}[%{$COLOR1%}%n%{$COLOR3%}@%{$COLOR1%}%m%{$COLOR3%}[%{$COLOR1%}tty%l%{$COLOR3%}]%{$COLOR1%}%~%{$COLOR3%}] ( %{$COLOR1%}=> %? %{$COLOR3%} )
#%{$COLOR1%}%#%{$COLOR4%} "
export PROMPT="%{$COLOR3%}[%{$COLOR1%}tty%l %{$COLOR3%}(%{$COLOR1%}%?%{$COLOR3%})%{$COLOR1%} %{$COLOR3%}-%{$COLOR1%} %~%{$COLOR3%}]%{$COLOR1%}
%{$COLOR3%}[%{$COLOR1%}%n%{$COLOR3%}@%{$COLOR1%}%m%{$COLOR3%}]%{$COLOR1%} %{$COLOR2%}%%%{$COLOR1%}%{$COLOR4%} "
#%{$COLOR1%}%(#.#.$)%{$COLOR4%} "
export RPROMPT="%{[A%}%{$COLOR3%}[%{$COLOR1%}%D{%H:%M%P}%{$COLOR3%}/%{$COLOR1%}%D{%d-%m-%Y}%{$COLOR3%}]%{$COLOR4%}%{[B%}"
export PROMPT2="%{$COLOR3%}[%{$COLOR1%}%(#.#.$)%{$COLOR3%}]%{$COLOR4%} "
export SPROMPT="%{$COLOR3%}[%{$COLOR1%}correct%{$COLOR3%}[%{$COLOR1%}'%R'%{$COLOR3%}]%{$COLOR1%}->%{$COLOR3%}[%{$COLOR1%}'%r'%{$COLOR3%}]] [%{$COLOR1%}n%{$COLOR3%}/%{$COLOR1%}y%{$COLOR3%}/%{$COLOR1%}a%{$COLOR3%}/%{$COLOR1%}e%{$COLOR3%}]%{$COLOR4%} "
}
function c1 {
export COLOR1="[0;31m"
export COLOR2="[1;31m"
export COLOR3="[1;30m"
export COLOR4="[0;0m"
setprompt
}
function c2 {
export COLOR1="[0;32m"
export COLOR2="[1;32m"
export COLOR3="[1;30m"
export COLOR4="[0;0m"
setprompt
}
function c3 {
export COLOR1="[0;33m"
export COLOR2="[1;33m"
export COLOR3="[1;30m"
export COLOR4="[0;0m"
setprompt
}
function c4 {
export COLOR1="[0;34m"
export COLOR2="[1;34m"
export COLOR3="[1;30m"
export COLOR4="[0;0m"
setprompt
}
function c5 {
export COLOR1="[0;35m"
export COLOR2="[1;35m"
export COLOR3="[1;30m"
export COLOR4="[0;0m"
setprompt
}
function c6 {
export COLOR1="[0;36m"
export COLOR2="[1;36m"
export COLOR3="[1;30m"
export COLOR4="[0;0m"
setprompt
}
function c7 {
export COLOR1="[0;37m"
export COLOR2="[1;37m"
export COLOR3="[1;30m"
export COLOR4="[0;0m"
setprompt
}
# }}}
# {{{ Titre sous X
function title () {
[[ -t 1 ]] || return
# echo -n '\033]0;'$*'\007'
case $TERM in
sun-cmd) print -Pn "\e]l$*\e\\"
;;
xterm*|rxvt) print -Pn "\e]2;$*\a"
;;
esac
}
# {{{ Changing terminal window/icon titles
function set_title () {
local num title
case "$1" in
window)
num=2
;;
icon)
num=1
;;
*)
print "Usage: set_title ( window | title ) <title>"
return 1
;;
esac
title="$2"
# Other checks will need to be added here.
if [[ "$TERM" == 'linux' ]]; then
print "Cannot currently display $1 title; only remembering value set."
else
print -Pn "\e]$num;$title\a"
fi
}
function cx () {
local long_host short_host title_host short_from_opts
long_host=${HOST}
short_host=${HOST%%.*}
if [[ "$1" == "-s" ]]
then
short_from_opts=yes
shift
fi
if [[ ${+CX_SHORT_HOSTNAMES} -eq 1 ||
"$short_from_opts" == "yes" ]] ; then
title_host=$short_host
else
title_host=$long_host
fi
if [[ "$USER" != "$USERNAME" ]]; then
# We've probably su'ed to a different user but not as a login
# shell
unset TITLE ITITLE
fi
if [[ -z "$*" ]]; then
# Revert window title to previous setting or default
: ${TITLE="$USERNAME@${title_host}"}
set_title window "$TITLE"
# Revert window icon title to previous setting or default
: ${ITITLE="$USERNAME@${short_host}"}
set_title icon "$ITITLE"
else
# Change window title
TITLE="$USERNAME@${title_host} $*"
set_title window "$TITLE"
# Change window icon title
ITITLE="$* @ $USERNAME@${short_host}"
set_title icon "$ITITLE"
fi
}
function cxx () {
# Clear titles
unset TITLE ITITLE
cx
}
if [[ "$TERM" == xterm* || "$TERM" == rxvt ]] ; then
# pas besoin de chpwd, si on prépare les autres
# chpwd () {
# cx "[ tty%l ]"
# }
function mycx () {
cx '[ tty%l ]'
}
mycx
function dist_login () {
local command
command=$1
shift
OLDTERM=${TERM}
TERM=xterm
command ${command} "$@"
ret=$?
TERM=${OLDTERM}
unset OLDTERM
mycx
return $?
}
function ssh () {
dist_login ssh "$@"
}
function slogin () {
dist_login slogin "$@"
}
function telnet () {
dist_login telnet "$@"
}
function su () {
dist_login su "$@"
}
fi
# }}}
# }}}
# {{{ Divers
function call_epelle {
for i in *.tex
do
epelle -latex -8bit $i
done | sort | uniq -c | sort -n | less
}
function getNewsArticle () {
( echo "article $1"
echo QUIT ) | nc news nntp
}
function backup_file () {
while test $# -gt 0 ; do
file=$1
shift
basebackup="${file}.`date +%Y%m%d`"
backup=${basebackup}
indice=1
while test -f $backup ; do
backup=`printf "%s%02d" $basebackup $indice`
indice=`expr $indice + 1`
done
cp $file $backup
done
}
# }}}
# Local variables:
# folded-file: t
# fold-internal-margins: nil
# mode: shell-script
# end: