Alias et fonction pour shell
# Transforme une ip en nombre et reciproquement
alias ip2nb='perl -e '\''print $1*2**24+$2*2**16+$3*256+$4."\n"
if ($ARGV[0]=~/(\d+).(\d+).(\d+).(\d+)/)'\'
alias nb2ip='perl -e '\''$z=$ARGV[0]; printf("%i.%i.%i.%i\n",
(0xFF000000&$z)>>24,(0xFF0000&$z)>>16,(0xFF00&$z)>>8,0xFF&$z)'\'
# Impression au format A5
book () {
psbook "$@" | psnup -2 | pstops "2:0,1U(1w,1h)" | psset --duplex | lpr
}
# Encode et decode en rot13
rot13 () {
if [ "$1" ]; then
echo "$*" | tr n-za-m a-z
else
tr n-za-m a-z
fi
}
# each <commande> <fichiers>
# Applique la commande sur chacun des fichiers
each () {
local command="$1"; shift
for i in "$@"; do
$command "$i"
done
}
# Pour avoir un df correct
df () {
LC_ALL=C command df "$@" | grep -v tmpfs
}
# Compression
rf+ () {
local fic
if [ $# = 1 ]; then
if [ -d "$1" ]; then
tar cvzf "${1%/}".tgz "$1" && rm -rf "$1"
else
gzip "$1"
fi
else
case "$1" in
*.tgz|*.tar.gz) tar cvzf "$@" ;;
*.tar) tar cvf "$@" ;;
*.tar.bz2|*.tz2)
fic="$1"; shift; tar cv "$@" | bzip2 > "$fic" ;;
*.gz) gunzip "$@" ;;
*.bz2) bunzip2 "$@" ;;
*.tar.z|*.tar.Z)
fic="$1"; shift; tar cv "$@" | compress > "$fic" ;;
*.z|*.Z) uncompress "$@" ;;
*.zip|*.ZIP) zip -r "$@" ;;
*.jar|*.jar) fastjar cvf "$@" ;;
*.rar) rar -rr a "$@" ;;
*) echo "unknow format : $1" ;;
esac
fi
}
# Decompression
rf- () {
local fic
case "$1" in
*.tgz|*.tar.gz) tar xvzf "$@" ;;
*.tar) tar xvf "$@" ;;
*.tar.bz2|*.tz2)
fic="$1"; shift; bunzip2 -c "$fic" | tar xv "$@" ;;
*.gz) gunzip "$@" ;;
*.bz2) bunzip2 "$@" ;;
*.tar.z|*.tar.Z)
fic="$1"; shift; uncompress -c "$fic" | tar xv "$@" ;;
*.z|*.Z) uncompress "$@" ;;
*.zip|*.ZIP) for fic in "$@" ; do command unzip $fic ; done ;;
*.jar|*.jar) fastjar xvf "$@" ;;
*.rar) rar x "$@" ;;
*.ace) unace x "$@" ;;
*) echo "unknow format : $1" ;;
esac
}
# Lister une archive
rfv () {
local fic
case "$1" in
*.tgz|*.tar.gz) tar tvzf "$@" ;;
*.tar) tar tvf "$@" ;;
*.tar.bz2|*.tz2)
fic="$1"; shift; bunzip2 -c "$fic" | tar tvf - "$@" ;;
*.zip|*.ZIP) zipinfo "$@" ;;
*.jar|*.jar) fastjar tf "$@" ;;
*.tar.z|*.tar.Z)
fic="$1"; shift; uncompress -c "$fic" | tar tvf - "$@" ;;
*.rar) rar l "$@" ;;
*.ace) unace l "$@" ;;
*) echo "unknow format : $1" ;;
esac
}
# Decompression en laissant les droits pour le groupe
rfa () {
rf- "$@"
chmod -R u+rX,g+rwX,o+r .
}
# Sets the title of the xterm
title() { echo -e "\e]2;$1\07" ; }
# Who takes all memory ? (Netscape...)
smem() {
ps -eo pmem,vsz,rss,fname,user | fgrep -v 0.0 |
sort -n $1 | gawk '{ printf(" %4s %7s %7s %-8s %-8s\n",$1,$2,$3,$4,$5) }'
}
# Display disk space used by each user
spc () {
command find ${1:-.} -printf "%u %b\n" 2>/dev/null |
gawk '{ t[$1]+=$2 } END { for (i in t) printf("%12i %s\n",t[i]/2,i) }' |
sort -r | cat -n | head $2
}
# Display a tree of files (function found somewhere on the net)
alias tree="find . -type d -print | sort | sed -e s:\./:: -e 's:[^/]*/:| :g'"
# Remove some useless files
cln() {
command find ${1:-.} \( -name '*.log' -o -name '*.tmp' -o -name '*~' -o \
-name '.*~' -o -name '#*#' -o -name '*.o' -o -name '*.aux' -o \
-name '*.toc' -o -name '.saves-*' -o -name '*.old' -o -name '*.bak' -o\
-name 'core' -o -name '.#*' -o -name '.nfs*' -o -name '~$*' \) -print0 |
perl -p0l012e unlink # xargs -0 -t rm -f
}
# A bash which
kel () {
for i in "$@"; do
for j in $([ -n "$ZSH_NAME" ] &&
whence -cap "$i" || type -all -path "$i"); do
ls -lalG "$j"
done
done ;
}
# replace <from_text> <to_text> <file(s)> : replace a text into all given files
replace () {
perl -e '$a=shift;$b=shift;while($f=shift){open(F,$f);@t=<F>;close(F);\
map s/$a/$b/,@t;open(W,">$f");print W @t;close(W)}' "$@"
}
# Display all the colors of the terminal
color() {
for i in 0 1 2 3 4 5 6 7 ; do
echo -ne "$i: \e[4${i}m \e[m\e[3${i};1m TEXT \e[m"
for j in 0 1 2 3 4 5 6 7 ; do
echo -ne "\e[0;4${i};3${j}mt${j} "
done
echo -n " "
for j in 0 1 2 3 4 5 6 7 ; do
echo -ne "\e[1;4${i};3${j}mt${j} "
done
echo -e "\e[m"
done
}
# A locate with regexp
loc() {
locate "*" | egrep -i "$@"
}
# Search a file
fd() {
find . -iname "*$1*"
}
# Search a file and list it
fdl() {
find . -name "*$1*" -print0 | xargs -0 ls --color=always -aldG
}
# Search a text in some files
search () {
find . -iname "$2" -type f -print0 | xargs -0 egrep -l "$1"
}
# Accelerator
md() {
mkdir "$1"
cd "$1"
}
# display all directories
alias lsd="ls --color=always -dlLG -- */"
# ls divers
alias ls="ls --color=auto -T 0 -v"
alias ll="ls -lBG"
alias lt="ls -ralt"
alias la="ls -AlBG"
alias lg="ls -al"
alias lb="ls -lBGb"
alias lq="ll --quoting-style=shell"
# Ouvrir un fichier dans un Emacs deja lance
alias e='emacsclient -n'
# Demande confirmation
alias cp='cp -iRv'
alias mv='mv -iv'
# Une calculatrice toute simple
ti() { perl -e '$g=9.80665; $pi=3.141592653589793; printf("%.15g\n",'$1');' ; }
### CD
# cd avec pile de repertoire ("cd-" pour depiler)
alias cd-="popd >/dev/null"
cd() {
if [ "$1" ] ; then
case $1 in
-) builtin cd - > /dev/null ;;
*) pushd "$1" > /dev/null ;;
esac
else
pushd ~ > /dev/null
fi
}
# Netscape4
alias n4='/usr/lib/netscape/477/navigator/navigator-smotif.real'
# show screen resolution
alias dim="xdpyinfo | awk '/dimensions:/ { print \$2 }'"
# Encode les cara speciaux en %xx (ex: " " -> "%20")
url2path () {
echo "$1" | perl -pe 's/%([\da-f]{1,2})/chr(hex($1))/eig'
}
# Decode les %xx en cara speciaux (ex: "%20" -> " ")
path2url () {
echo "$1" | perl -pe 's/([^\da-z.\/:])/sprintf("%%%02x", ord($1))/eig'
}
# grave un .cue : cue <vitesse> <fichier.cue>
cue () {
cdrdao write --eject --speed $1 --device ATA:1,0,0 --driver generic-mmc "$2"
}
# copy a cd : cdcopy [vitesse] [image]
cdcopy () {
cdrecord -v -eject -pad \
speed=${1:-12} dev=ATA:1,0,0 driveropts=burnproof \
-isosize ${2:-/dev/cdrom}
}
# Return the size of the cd in the cd-writer
cdsize () {
cdrecord -atip dev=0,$devg,0 |
perl -n -e 'printf "%.3f\n", 650*($1+$2/60+$3/6000)/74
if (/ATIP.*out: \S+ \((..):(..)\/(..)\)/)'
}
# mount an iso image
loop () {
mount -r "$1" /mnt -t iso9660 -o loop
}
# Transform all wav sound file into a .wav which can be recorded in an audio cd
# Quality decrease
dec () {
local dest
for fic in "$@"; do
if file "$fic" | fgrep "16 bit, stereo 44100"; then
: # does nothing
else
# the -v option is for decreasing the volume
sox "$fic" -v 0.7 -w -c 2 -r 44100 tmp$$.wav rate # polyphase resample
fi
done
}
# Convertit les fichiers sons en .ogg
x2ogg() {
for i in "$@"; do
mplayer -ao pcm:file="${i%.*}.wav" "$i"
oggenc -q 5 "${i%.*}.wav"
rm -f "${i%.*}.wav"
done
}
# Efface les lignes des fichiers qui n'existent plus d'une liste .m3u
purgem3u() {
for m3u in "$@"; do
local tmp=$(mktemp)
echo $tmp $m3u
while read f
do
[ -f "$f" ] && echo "$f"
done < "$m3u" > $tmp
mv $tmp $m3u
done
}
### Divers
# ^h : à la place de DEL
# echoe : N'affiche pas le ^H mais efface le caractère
stty erase '^h' echoe cs8
unset MAILCHECK # Ne dit pas s'il y'a du new Mail
HISTFILE="/dev/null" # Nom du fichier d'historique
|