• # Encore mieux fait maison (pour les bashistes)

    Posté par . En réponse au message [Terminal] Revenir à son point de départ à peu de frais. Évalué à 1.

    A coller dans son .bashrc ou ailleurs... Attention, après on ne peut plus s'en passer!
    function g() {
    	local CFG=$HOME/.cdirs
    	# no arg => list bookmarks
    	if [ $# = 0 ]; then
    		if [ -f $CFG ]; then
    			nl $CFG
    		else
    			echo "No bookmarks file [$CFG]"
    		fi
    	# print help
    	elif [ 1ドル = help ]; then
    		cat <<EOF
     g: Bookmarks your favorite directories
     Usage: g [ directory | regex | number | "del" | "edit" ]
    EOF
    		
    	# number => go to n-th bookmark
    	elif [[ 1ドル =~ [0-9]+ ]]; then
    		dir=`sed -ne ${1}p $CFG`
    		if [ "$dir" != "" ]; then
    			cd $dir
    		else
    			echo "Not found"
    		fi
    	# edit bookmarks
    	elif [ 1ドル = "edit" -o 1ドル = "del" ]; then
    		vi $CFG
    	# grep bookmarks, add bookmark if not found and directory exists
    	else
    		dir=`grep "1ドル" $CFG | sed -ne 1p`
    		if [ "$dir" != "" ]; then
    			cd $dir
    		elif [ -d 1ドル ]; then
    			cd 1ドル
    			pwd >> $CFG
    		else
    			echo "No such directory"
    		fi
    	fi
    }