[Surfraw-devel] [PATCH] Improve printing of elvi list

Jameson Rollins jrollins at finestructure.net
Fri Aug 20 15:15:53 UTC 2010


This patch adds a new function, print_elvi, that improves the printing
of the elvi descriptions in two ways:

- Ignore scripts that end with '~'.  This is useful for users who
  maintain their own elvi, by ignoring editor turds.  This could
  probably be expanded to ignore other turd-like files as well.

- Improve listing of scripts that are actually just symbolic links to
  other scripts.  Scripts that are links are now displayed as such,
  disambiguating them from the script they link to.  This makes it
  much nicer to maintain elvi shortcuts (such as wiki --> wikipedia).
---
 surfraw.IN |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 surfraw.IN

diff --git a/surfraw.IN b/surfraw.IN
old mode 100644
new mode 100755
index 3c7a730..97d69af
--- a/surfraw.IN
+++ b/surfraw.IN
@@ -310,6 +310,14 @@ w3_parse_option_hook () {
     return 1
 }
 
+print_elvi() {
+    local dir="$1"
+    sed -n 's/^.*elvis: \(.*\)$/\1/p' $(find "$dir" -mindepth 1 -maxdepth 1 ! -type l ! -name '*~' -printf '%p\n' | sort)
+    for script in $(find "$dir" -mindepth 1 -maxdepth 1 -type l -printf '%f\n' | sort) ; do
+	printf '%-16s--> %s\n' "$script" $(basename $(readlink "${dir}/${script}"))
+    done
+}
+
 w3_parse_option () {
     opt="$1"
     case "$opt" in
@@ -319,11 +327,11 @@ w3_parse_option () {
     case "$opt" in
 	-browser=*)	    setopt   SURFRAW_browser		$optarg	;;
 	-elvi)		    echo " GLOBAL ELVI:"
-			    sed -n 's/^.*elvis: \(.*\)$/\1/p' $elvidir/*
+			    print_elvi "$elvidir"
 			    localelvidir=$(get_local_elvi_dir)
 			    if [ -d "$localelvidir" ] && [ -n "$(ls "$localelvidir")" ]; then
 				echo " LOCAL ELVI:"
-				sed -n 's/^.*elvis: \(.*\)$/\1/p' "$localelvidir/"*
+				print_elvi "$localelvidir"
 			    fi
 			    exit 0 ;;
 	-escape-url-args=*) setoptyn SURFRAW_escape_url_args	$optarg ;;
-- 
1.7.1



More information about the Surfraw-devel mailing list