Re: [SSFR] Partage de fonctions ...

[ Thread Index | Date Index | More debianworld.org/shellscript-fr Archives ]


On 03/04/08 ? ? 12:22, Edi Stojicevic wrote:
> Salut,
> 
> Quelles fonctions, concoctees par vos soins, utilisez vous le plus souvent ?
> 
> Voici quelques unes que j'utilise :

Ce serait bien de preciser le shell, certaines fonctions semblent specifiques
a zsh.

Voici quelques unes des miennes, certaines recuperees au hasard du web.
J'utilise exclusivement linux maintenant mais la plupart
marche sous *BSD, Solaris, HPUX et Aix avec sh, bash et ksh
certaines necessitent les outils GNU ps et ls.

# personal ps (mes processus)
pps() { ps -Af | grep -w $LOGNAME | grep -v grep; }

# ps utilisateurs (tous sauf root)
psu() { ps -Af | grep -v root; }

# psgrep recherche de processus
psgrep() {
        if [ $# -ne 1 ]; then
                echo "usage: psgrep <pattern>" >& 2
        else
                ps auxww | grep $1 | grep -v grep;
        fi
}

# ps memory size (tri par taille decroissante)
psm() { ps --cols=1000 --sort='-vsz,uid,pgid,ppid,pid' -eo user,pid,wchan,pcpu,pmem,vsz,rss,sz,args; }

# ll time (tri par date de fichier)
llt() { ls -orA --sort=time "$@"; }

# lls [size] (tri par taille, taille mini optionnelle, 4K par defaut)
lls() {
	local min
	case "$1" in
	[123456789]*) min=$1;shift;;
	esac
	ls -ogrA --time-style="+" $* | awk -v min=${min:-4} '(NF>3)&&/^[^d]/{s=$3/1024;$1="";$2="";$3=""; if (s>min) printf "%12.2f\t%s\n", s, $0}' | sort -n
}

# llf ll files only
llf() { ls -l $* | egrep "^-"; }

# man local, affiche directement un fichier man ou la doc d'un fichier perl
manloc() {
	for f; do
		case $f in
		*.pm|*.pl) pod2man $f | nroff -man | $PAGER;;
		*)	if [ -f $f.1 ]; then
				nroff -man $f | $PAGER
			else
				nroff -man $f | $PAGER
			fi;;
		esac
	done
}

# vigrep: edite tous les fichiers contenant une chaine
vigrep() {
	pattern=$1
	shift
	matches=$(grep -l $pattern ${*:-*} )
	if [ ${#matches} -gt 0 ]; then
		$EDITOR +/$pattern $matches
	else
		print $pattern not found in ${*:-*}
	fi
}


# edition du PATH
viPath() {
	echo $PATH | tr ':' '\n' > /tmp/path.$$
	$EDITOR  /tmp/path.$$
	PATH=$(cat /tmp/path.$$ | tr '\n' ':')
	\rm /tmp/path.$$
}

# comme which -a mais avec des wildcards
# A faster version of which, that also prints ALL versions in your PATH,
# and accepts wildcards, e.g.: which '*uu*'. Silent if nothing found.
whichall() {
	local ifs=$IFS d cmd
	IFS=$IFS:
	for cmd; do
		for d in $PATH; do
			for file in $d/$cmd; do
				[ -L $file ] && echo link $file
				[ -x $file -a ! -d $file ] && echo $file
			done
		done
	done
	IFS=$ifs
}


# execute une commande sur une liste de commandes
# wcmd cmd arg1 arg2...
wcmd() {
	local cmd arg nom
	cmd=$1
	shift
	for arg; do
		nom=$(which $arg)
		if [ $? -ne 0 ]; then
			echo "$arg not found" >& 2
		else
			case $nom in
			/*)	$cmd $nom;;
			*)	which $arg;;
		esac
		fi
	done
}

# utilisation de wcmd pour ls, vi, file et more
wll() { wcmd "ls -loF" $*; }
wvi() { wcmd "$EDITOR" $*; }
wfile() { wcmd file $*; }      
wm() { wcmd ${PAGER:-more} $*; }

-- 
Stéphane Billiart                      http://perso.orange.fr/billiart/




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/