[Surfraw-commits] [SCM] surfraw - a fast unix command line interface to WWW branch, master, updated. surfraw_2-2-5_1-20-gc46924e

Ian Beckwith ianb at erislabs.net
Sun Oct 25 15:56:16 UTC 2009


The following commit has been merged in the master branch:
commit f57fc7187ae7ba833ad8799482f966e340ccf13a
Author: Ian Beckwith <ianb at erislabs.net>
Date:   Tue Oct 20 15:00:47 2009 +0100

    Implement XDG basedir spec for bookmarks

diff --git a/surfraw.IN b/surfraw.IN
index 98a5372..99fd4bc 100644
--- a/surfraw.IN
+++ b/surfraw.IN
@@ -22,42 +22,52 @@ w3_config_hook () {
     return 1
 }
 
-load_global_conf () {
+find_global_conf () {
+    base="$1"
     local conf OIFS
     conf=""
-    # if explicitly specified
-    if test -n "$SURFRAW_global_conf" && test -r "$SURFRAW_global_conf"; then
-	conf="$SURFRAW_global_conf"
-    elif test -n "$XDG_CONFIG_DIRS"; then
+    if test -n "$XDG_CONFIG_DIRS"; then
 	OIFS="$IFS"
 	IFS=:
 	set $XDG_CONFIG_DIRS
 	IFS="$OIFS"
 	for i in "$@"; do
-	    if test -r "$i/surfraw/conf"; then
-		conf="$i/surfraw/conf"
+	    if test -r "$i/surfraw/$base"; then
+		conf="$i/surfraw/$base"
 		break
 	    fi
 	done
-    elif test -r "@sysconfdir@/xdg/surfraw/conf"; then # XDG default
-	conf="@sysconfdir@/xdg/surfraw/conf"
-    elif test -r "@sysconfdir@/surfraw.conf"; then # old surfraw default
-	conf="@sysconfdir@/surfraw.conf"
+    elif test -r "@sysconfdir@/xdg/surfraw/$base"; then # XDG default
+	conf="@sysconfdir@/xdg/surfraw/$base"
+    elif test -r "@sysconfdir@/surfraw.$base"; then # old surfraw default
+	conf="@sysconfdir@/surfraw.$base"
     fi
-    if test -z "$conf"; then
+    echo "$conf"
+}
+
+load_global_conf () {
+    local conf
+    if test -n "$SURFRAW_global_conf" && test -r "$SURFRAW_global_conf"; then
+	conf="$SURFRAW_global_conf"
+    else
+	conf=$(find_global_conf conf)
+    fi
+    if test -z "$conf" || ! test -r "$conf"; then
 	err "couldn't find global config in @sysconfdir@/xdg/surfraw/conf or \$XDG_CONFIG_DIRS"
     fi
     . "$conf"
 }
 
-find_config_file () {
+find_local_conf () {
     base="$1"
     if test -n "$XDG_CONFIG_HOME" && test -r "$XDG_CONFIG_HOME/surfraw/$base"; then
 	echo "$XDG_CONFIG_HOME/surfraw/$base"
-    elif test -n "$HOME" && test -r "$HOME/.config/surfraw/$base"; then
-	echo "$HOME/.config/surfraw/$base"
-    elif test -r "$HOME/.surfraw.$base"; then
-	echo "$HOME/.surfraw.$base"
+    elif test -n "$HOME"; then
+	if test -r "$HOME/.config/surfraw/$base"; then
+	    echo "$HOME/.config/surfraw/$base"
+	elif test -r "$HOME/.surfraw.$base"; then
+	    echo "$HOME/.surfraw.$base"
+	fi
     fi
 }
 
@@ -67,9 +77,9 @@ load_local_conf () {
     if test -n "$SURFRAW_conf" && test -r "$SURFRAW_conf"; then
 	conf="$SURFRAW_conf"
     else
-	conf="$(find_config_file conf)"
+	conf="$(find_local_conf conf)"
     fi
-    if test -n "$conf"; then
+    if test -n "$conf" && test -r "$conf"; then
 	. $conf
     fi
 }
@@ -150,7 +160,7 @@ quote_ifs () {
 bookmark_file_search () {
 	search="$1"
 	file="$2"
-	if [ -f "$file" ]
+	if [ -r "$file" ]
 	then
 		@AWK@ -v search="$search" '$1 ~ search { print $2; }'  $file | head -n 1
 	fi
@@ -158,10 +168,12 @@ bookmark_file_search () {
 
 bookmark_lookup () {
 	search="$1"
-	lookup=`bookmark_file_search "$search" ~/.surfraw.bookmarks`
+	file=$(find_local_conf bookmarks)
+	lookup=$(bookmark_file_search "$search" "$file")
 	if [ -z "$lookup" ]
 	then
-		lookup=`bookmark_file_search "$search" @sysconfdir@/surfraw.bookmarks`
+	    file=$(find_global_conf bookmarks)
+	    lookup=$(bookmark_file_search "$search" "$file")
 	fi
 	if [ -n "$lookup" ]
 	then

-- 
surfraw -  a fast unix command line interface to WWW



More information about the Surfraw-commits mailing list