[GUILT 5/6] Allow guilt scripts to be run from a directory which contains spaces

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



`dirname $0` breaks if $0 includes spaces.

I don't need this; it was the result of a mis-understanding.
But here it is anyway; take it if you think it's useful.

Signed-off-by: Alan Jenkins <alan.christopher.jenkins@xxxxxxxxxxxxxx>
---
 guilt               |   22 +++++++++++++---------
 guilt-add           |    2 +-
 guilt-applied       |    2 +-
 guilt-branch        |    2 +-
 guilt-commit        |    2 +-
 guilt-delete        |    2 +-
 guilt-diff          |    2 +-
 guilt-export        |    2 +-
 guilt-files         |    2 +-
 guilt-fold          |    2 +-
 guilt-fork          |    2 +-
 guilt-graph         |    2 +-
 guilt-guard         |    2 +-
 guilt-header        |    2 +-
 guilt-help          |    2 +-
 guilt-import        |    2 +-
 guilt-import-commit |    2 +-
 guilt-init          |    2 +-
 guilt-new           |    2 +-
 guilt-next          |    2 +-
 guilt-patchbomb     |    2 +-
 guilt-pop           |    2 +-
 guilt-prev          |    2 +-
 guilt-push          |    2 +-
 guilt-rebase        |    2 +-
 guilt-refresh       |    2 +-
 guilt-repair        |    2 +-
 guilt-rm            |    2 +-
 guilt-select        |    2 +-
 guilt-series        |    2 +-
 guilt-status        |    2 +-
 guilt-top           |    2 +-
 guilt-unapplied     |    2 +-
 33 files changed, 45 insertions(+), 41 deletions(-)

diff --git a/guilt b/guilt
index 9f06b41..45bdb66 100755
--- a/guilt
+++ b/guilt
@@ -6,12 +6,14 @@
 GUILT_VERSION="0.35"
 GUILT_NAME="Gloria"
 
+GUILT="$(basename "$0")"
+
 # If the first argument is one of the below, display the man page instead of
 # the rather silly and mostly useless usage string
 case $1 in
 	-h|--h|--he|--hel|--help)
 	shift
-	exec "guilt help" "`basename $0`"
+	exec "guilt help" "$GUILT"
 	exit
 	;;
 	-V|--ver|--versi|--versio|--version)
@@ -69,10 +71,12 @@ silent()
 
 ########
 
+GUILT_PATH="$(dirname "$0")"
+
 guilt_commands()
 {
-	find "`dirname $0`/../lib/guilt" -maxdepth 1 -name "guilt-*" -type f -perm +111 2> /dev/null | sed -e "s/.*\\/`basename $0`-//"
-	find "`dirname $0`" -maxdepth 1 -name "guilt-*" -type f -perm +111 | sed -e "s/.*\\/`basename $0`-//"
+	find "$GUILT_PATH/../lib/guilt" -maxdepth 1 -name "guilt-*" -type f -perm +111 2> /dev/null | sed -e "s/.*\\/$GUILT-//"
+	find "$GUILT_PATH" -maxdepth 1 -name "guilt-*" -type f -perm +111 | sed -e "s/.*\\/$GUILT-//"
 }
 
 # by default, we shouldn't fail
@@ -82,8 +86,8 @@ if [ $# -ne 0 ]; then
 	# take first arg, and try to execute it
 
 	arg="$1"
-	dir=`dirname $0`
-	libdir="`dirname $0`/../lib/guilt"
+	dir="$GUILT_PATH"
+	libdir="$GUILT_PATH/../lib/guilt"
 
 	if [ -x "$dir/guilt-$arg" ]; then
 		cmd="$dir/guilt-$arg"
@@ -870,10 +874,10 @@ pager="more"
 
 UNAME_S=`uname -s`
 
-if [ -r "`dirname $0`/os.$UNAME_S" ]; then
-	. "`dirname $0`/os.$UNAME_S"
-elif [ -r "`dirname $0`/../lib/guilt/os.$UNAME_S" ]; then
-	. "`dirname $0`/../lib/guilt/os.$UNAME_S"
+if [ -r "$GUILT_PATH/os.$UNAME_S" ]; then
+	. "$GUILT_PATH/os.$UNAME_S"
+elif [ -r "$GUILT_PATH/../lib/guilt/os.$UNAME_S" ]; then
+	. "$GUILT_PATH/../lib/guilt/os.$UNAME_S"
 else
 	die "Unsupported operating system: $UNAME_S"
 fi
diff --git a/guilt-add b/guilt-add
index 6529949..8a6b5a7 100755
--- a/guilt-add
+++ b/guilt-add
@@ -5,7 +5,7 @@
 
 USAGE="<file>..."
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-applied b/guilt-applied
index a1f684a..a84f1f7 100755
--- a/guilt-applied
+++ b/guilt-applied
@@ -5,7 +5,7 @@
 
 USAGE="[-c]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-branch b/guilt-branch
index 909f740..3e88321 100755
--- a/guilt-branch
+++ b/guilt-branch
@@ -5,7 +5,7 @@
 
 USAGE="[<new_name>]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-commit b/guilt-commit
index 4228be6..4ef6605 100755
--- a/guilt-commit
+++ b/guilt-commit
@@ -5,7 +5,7 @@
 
 USAGE="-n <num> | -a | --all"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-delete b/guilt-delete
index 4ab9c94..551e6a4 100755
--- a/guilt-delete
+++ b/guilt-delete
@@ -5,7 +5,7 @@
 
 USAGE="[-f] <patchname>"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-diff b/guilt-diff
index 0061926..182fa59 100755
--- a/guilt-diff
+++ b/guilt-diff
@@ -5,7 +5,7 @@
 
 USAGE="[-z] [<path>...]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-export b/guilt-export
index 8361902..62c1ef6 100755
--- a/guilt-export
+++ b/guilt-export
@@ -5,7 +5,7 @@
 
 USAGE="[<target_dir>]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-files b/guilt-files
index f31a94c..aab35d5 100755
--- a/guilt-files
+++ b/guilt-files
@@ -5,7 +5,7 @@
 
 USAGE="[-v] [-a] [-l]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-fold b/guilt-fold
index 06fbb7f..07d77a1 100755
--- a/guilt-fold
+++ b/guilt-fold
@@ -5,7 +5,7 @@
 
 USAGE="[-k] <patchname>"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-fork b/guilt-fork
index 8d58ffd..5677e1b 100755
--- a/guilt-fork
+++ b/guilt-fork
@@ -5,7 +5,7 @@
 
 USAGE="[<new_name>]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-graph b/guilt-graph
index 496a831..1c9fade 100755
--- a/guilt-graph
+++ b/guilt-graph
@@ -5,7 +5,7 @@
 
 USAGE="[<patchname>]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-guard b/guilt-guard
index 2c12fca..ada7f45 100755
--- a/guilt-guard
+++ b/guilt-guard
@@ -5,7 +5,7 @@
 
 USAGE="[-l | --list | -n | --none | [<patchname>] [(+|-)<guard>...]]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-header b/guilt-header
index 9910708..19cfd45 100755
--- a/guilt-header
+++ b/guilt-header
@@ -5,7 +5,7 @@
 
 USAGE="[-eE] [<patchname>]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-help b/guilt-help
index e1807a8..001ddfb 100755
--- a/guilt-help
+++ b/guilt-help
@@ -7,7 +7,7 @@ DO_NOT_CHECK_BRANCH_EXISTENCE=1
 
 USAGE="[<command> | <topic>]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-import b/guilt-import
index 72ba7c3..041d20a 100755
--- a/guilt-import
+++ b/guilt-import
@@ -5,7 +5,7 @@
 
 USAGE="[-P <patch> ] <patch_file>"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-import-commit b/guilt-import-commit
index 3045a5f..1784f26 100755
--- a/guilt-import-commit
+++ b/guilt-import-commit
@@ -5,7 +5,7 @@
 
 USAGE="[<hash> | <since>..[<until>] | ..<until>]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-init b/guilt-init
index 646e24b..148699c 100755
--- a/guilt-init
+++ b/guilt-init
@@ -7,7 +7,7 @@ DO_NOT_CHECK_BRANCH_EXISTENCE=1
 
 USAGE=""
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-new b/guilt-new
index 402104e..0803063 100755
--- a/guilt-new
+++ b/guilt-new
@@ -5,7 +5,7 @@
 
 USAGE="[-f] [-s] [-e|-m message] <patchname>"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-next b/guilt-next
index a0941fc..c7263f1 100755
--- a/guilt-next
+++ b/guilt-next
@@ -5,7 +5,7 @@
 
 USAGE="[-p|--path]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-patchbomb b/guilt-patchbomb
index b72a706..c61cd1b 100755
--- a/guilt-patchbomb
+++ b/guilt-patchbomb
@@ -7,7 +7,7 @@ DO_NOT_CHECK_BRANCH_EXISTENCE=1
 
 USAGE="[-n] [-s] [--in-reply-to <msgid>] [--git] [--subject-prefix <prefix>] [<hash> | <since>..[<until>] | ..<until>]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-pop b/guilt-pop
index df466c7..1e36f00 100755
--- a/guilt-pop
+++ b/guilt-pop
@@ -5,7 +5,7 @@
 
 USAGE="[-f] [-a | --all | -n <num> | <patchname>]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-prev b/guilt-prev
index d454030..31c054c 100755
--- a/guilt-prev
+++ b/guilt-prev
@@ -5,7 +5,7 @@
 
 USAGE="[-p|--path]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-push b/guilt-push
index d9a8590..4a54d07 100755
--- a/guilt-push
+++ b/guilt-push
@@ -5,7 +5,7 @@
 
 USAGE="[ -f ] [-a | --all | -n <num> | <patchname>]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-rebase b/guilt-rebase
index 614ba22..c33022f 100755
--- a/guilt-rebase
+++ b/guilt-rebase
@@ -7,7 +7,7 @@
 
 USAGE="<upstream>"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-refresh b/guilt-refresh
index f764937..4e22929 100755
--- a/guilt-refresh
+++ b/guilt-refresh
@@ -5,7 +5,7 @@
 
 USAGE="[--git] [--diffstat]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-repair b/guilt-repair
index 77ad223..99df731 100755
--- a/guilt-repair
+++ b/guilt-repair
@@ -7,7 +7,7 @@ DO_NOT_CHECK_STATUS_FILE_FORMAT=1
 
 USAGE="--full | --status"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-rm b/guilt-rm
index 351ec93..d68622b 100755
--- a/guilt-rm
+++ b/guilt-rm
@@ -5,7 +5,7 @@
 
 USAGE="<file>..."
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-select b/guilt-select
index 8b139d4..fb7941b 100755
--- a/guilt-select
+++ b/guilt-select
@@ -5,7 +5,7 @@
 
 USAGE="[ -n | --none | -s | --series | [--pop|--reapply] <guards...> ]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-series b/guilt-series
index c87b31e..f8cd7c7 100755
--- a/guilt-series
+++ b/guilt-series
@@ -5,7 +5,7 @@
 
 USAGE="[-v | -g | -e]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-status b/guilt-status
index c701fd1..b4cd1eb 100755
--- a/guilt-status
+++ b/guilt-status
@@ -5,7 +5,7 @@
 
 USAGE="[-a|-A] [-c|-C] [-d|-D] [-m|-M] [-r|-R] [-t|-T] [-u|-U] [-x|-X] [-n]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-top b/guilt-top
index 3b1d596..6215009 100755
--- a/guilt-top
+++ b/guilt-top
@@ -5,7 +5,7 @@
 
 USAGE="[-p|--path]"
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
diff --git a/guilt-unapplied b/guilt-unapplied
index e703408..9aec87a 100755
--- a/guilt-unapplied
+++ b/guilt-unapplied
@@ -5,7 +5,7 @@
 
 USAGE=""
 if [ -z "$GUILT_VERSION" ]; then
-	echo "Invoking `basename $0` directly is no longer supported." >&2
+	echo "Invoking $GUILT directly is no longer supported." >&2
 	exit 1
 fi
 
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]