# [TopGit PATCH] tg.sh: simplify cat_file

2 messages from 2010-10-04 to 2010-10-04. Participants: Bert Wesarg.
Thread: https://gitlist.dev/t/25338

## Bert Wesarg, 2010-10-04 18:43

Subject: [TopGit PATCH] tg.sh: simplify cat_file
Message-ID: <85c8c215f362c4b57e7646d536ef1ca77ade1591.1286217707.git.bert.wesarg@googlemail.com>
URL: https://gitlist.dev/e/85c8c215f362c4b57e7646d536ef1ca77ade1591.1286217707.git.bert.wesarg%40googlemail.com

```
Use shell parameter expansion to strip the leading (w): and (i)

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 tg.sh |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/tg.sh b/tg.sh
index 9d08d63..d320956 100644 tg.sh
--- a/tg.sh
+++ b/tg.sh
@@ -25,17 +25,15 @@ cat_file()
 	arg="$1"
 	case "$arg" in
 	'(w):'*)
-		arg=$(echo "$arg" | tail --bytes=+5)
-		cat "$arg"
-		return
+		cat "${arg#????}"
 		;;
 	'(i):'*)
 		# ':file' means cat from index
-		arg=$(echo "$arg" | tail --bytes=+5)
-		git cat-file blob ":$arg"
+		git cat-file blob "${arg#???}"
 		;;
 	*)
 		git cat-file blob "$arg"
+		;;
 	esac
 }
 
-- 
1.7.1.1067.g5aeb7

```

## Bert Wesarg, 2010-10-04 18:47

Subject: [TopGit PATCH v2] tg.sh: simplify cat_file
Message-ID: <064ca64cad83076e419ef2cb8bfa5d80e72915bb.1286217942.git.bert.wesarg@googlemail.com>
URL: https://gitlist.dev/e/064ca64cad83076e419ef2cb8bfa5d80e72915bb.1286217942.git.bert.wesarg%40googlemail.com
In-Reply-To: <85c8c215f362c4b57e7646d536ef1ca77ade1591.1286217707.git.bert.wesarg@googlemail.com>

```
Use shell parameter expansion to strip the leading (w): and (i)

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---

No need to use wildcards, we know exactly what we want to strip.

 tg.sh |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/tg.sh b/tg.sh
index 9d08d63..0e72865 100644 tg.sh
--- a/tg.sh
+++ b/tg.sh
@@ -25,17 +25,15 @@ cat_file()
 	arg="$1"
 	case "$arg" in
 	'(w):'*)
-		arg=$(echo "$arg" | tail --bytes=+5)
-		cat "$arg"
-		return
+		cat "${arg#(w):}"
 		;;
 	'(i):'*)
 		# ':file' means cat from index
-		arg=$(echo "$arg" | tail --bytes=+5)
-		git cat-file blob ":$arg"
+		git cat-file blob "${arg#(i)}"
 		;;
 	*)
 		git cat-file blob "$arg"
+		;;
 	esac
 }
 
-- 
1.7.1.1067.g5aeb7

```
