#!/bin/ksh # # NAME: # l (lower-case letter "ell") # # SYNOPSIS: # l [-v] DIR SEARCH # # DESCRIPTION: # Customizes directory listings to show context. # Any files in DIR containing the pattern SEARCH will # have that pattern highlighted in red. # # DIR must be quoted if you wish to use shell meta-characters. # "-v" prints the version and exits. # # EXAMPLES: # l /etc conf # l "/var/log/*" local # # HISTORY: # Taken from http://www.linux.com/feature/122271 # CLI Magic: A little script to customize directory listings # Sergio Gonzalez Duran PATH=/usr/local/bin:/bin:/usr/bin export PATH usage () { sed -n -e '/^# NAME:/,/^$/p' $0 | sed -e 's/^#//' >&2 exit 1 } version () { lrevno='$RCSfile: l,v $ $Revision: 1.6 $' lrevdate='$Date: 2007/12/12 01:06:37 $' echo "$lrevno $lrevdate" | sed -e 's/RCSfile: //' \ -e 's/.Date: //' -e 's/,v . .Revision: / v/' -e 's/\$//g' exit 0 } # Argument checks. case "$1" in -v) version ;; -*) usage ;; esac case "$#" in 2) DIR="$1"; SEARCH="$2" ;; *) usage ;; esac RED=`tput setaf 1; tput smso` # setaf 1 = red, smso = inverted NORMAL=`tput sgr0` # normal text attributes # "!" allows us to use / in our search pattern. exec ls -FC $DIR | sed -e "s!${SEARCH}!${RED}${SEARCH}${NORMAL}!g" exit 0