Skip to content

Commit 5b01da5

Browse files
authored
Merge pull request #52 from hyperupcall/improve-shell
2 parents 559ad47 + d35b55e commit 5b01da5

22 files changed

+86
-84
lines changed

git-addremove

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

33
git add -A
4-
git ls-files --deleted -z | while read file; do
4+
git ls-files --deleted -z | while read -r file; do
55
git rm "$file"
66
done

git-addtree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env bash
2-
git subtree add --prefix $1 ext/$(basename $1) master --squash
2+
git subtree add --prefix "$1" "ext/$(basename "$1")" master --squash

git-all-commits

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/bin/sh
22

33
find .git/objects -type f | \
4-
while read file; do
5-
if echo $file | grep -Eq '\.idx$'; then
6-
git show-index < $file | awk '{print $2}'
7-
elif echo $file | grep -Eq '[0-9a-f]{38}$'; then
8-
echo $(basename $(dirname $file))$(basename $file)
4+
while read -r file; do
5+
if echo "$file" | grep -Eq '\.idx$'; then
6+
git show-index < "$file" | awk '{print $2}'
7+
elif echo "$file" | grep -Eq '[0-9a-f]{38}$'; then
8+
echo "$(basename "$(dirname "$file")")$(basename "$file")"
99
fi
1010
done | \
11-
while read hash; do
12-
if [ "$(git cat-file -t $hash)" = commit ]; then
13-
echo $hash
11+
while read -r hash; do
12+
if [ "$(git cat-file -t "$hash")" = commit ]; then
13+
echo "$hash"
1414
fi
1515
done

git-all-objects

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ cd "$(git rev-parse --git-path objects)"
66

77
# packed objects
88
for p in pack/pack-*([0-9a-f]).idx ; do
9-
git show-index < $p | cut -f 2 -d ' '
9+
git show-index < "$p" | cut -f 2 -d ' '
1010
done
1111

1212
# loose objects
1313
for o in [0-9a-f][0-9a-f]/*([0-9a-f]) ; do
14-
echo ${o/\/}
14+
echo "${o/\/}"
1515
done

git-already-merged

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
for branch in $(git branch -r --merged | grep -v HEAD)
66
do
7-
echo -e $(git show --format="%ci %cr %an" $branch | head -n 1) \\t$branch
7+
printf '%s\t%s\n' "$(git show --format="%ci %cr %an" "$branch" | head -n 1)" "$branch"
88
done | sort -r

git-amend-all

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
## This is free software, and you are welcome to redistribute it
77
## under certain conditions; see COPYING for details.
88

9-
# Purpose: This script adds all modified and deleted files,
9+
# Purpose: This script adds all modified and deleted files,
1010
# except the new files and adds it to the recent commit by amending it
1111

1212
set -e
1313

1414
# User is not in git repository
1515
if ! git branch > /dev/null 2>&1
1616
then
17-
echo "E: '$(basename ${PWD})' - Not a Git repository."
17+
echo "E: '$(basename "${PWD}")' - Not a Git repository."
1818
exit 1
1919
fi
2020

git-apply-url

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@
3232
URL=$1
3333

3434
error() {
35-
echo $*
35+
echo "$*"
3636
exit 1
3737
}
3838

39-
if [ ! $URL ]; then
40-
error $0 URL
39+
if [ ! "$URL" ]; then
40+
error "usage: $0 URL"
4141
fi
4242

43-
if [ -x $(command -v curl) ] && [ $(curl -V | grep https) ]; then
43+
if command -v curl >/dev/null 2>&1 && curl -V | grep -q https >/dev/null 2>&1; then
4444
fetch="curl -s"
45-
elif [ -x $(command -v wget) ]; then
45+
elif command -v wget >/dev/null 2>&1; then
4646
fetch="wget -O - -q --no-check-certificate"
4747
else
4848
error need curl or wget
4949
fi
5050

51-
$fetch $URL | patch -p1
51+
$fetch "$URL" | patch -p1

git-branch-done

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# destination branch as parameter - depends on merge strategy, typically master
55
DST_BRANCH=""
6-
if [ ! -z "$1" ]; then
6+
if [ -n "$1" ]; then
77
DST_BRANCH="$1"
88
else
99
echo "Usage: git branch-done <branch>"
@@ -13,4 +13,4 @@ fi
1313
# get current branch - typically topic branch like taskXXXX, bugXXXX, ...
1414
cb=$(git rev-parse --abbrev-ref HEAD)
1515
# no fast forward merge from current branch to destination branch
16-
git checkout $DST_BRANCH && git merge --no-ff $cb && git branch -d $cb
16+
git checkout "$DST_BRANCH" && git merge --no-ff "$cb" && git branch -d "$cb"

git-build

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#!/usr/bin/env bash
22

33
git clean -f -x -d
4-
git checkout $1
4+
git checkout "$1"
55

6-
rm -fr /usr/local/stow/git-$1
6+
rm -fr "/usr/local/stow/git-$1"
77

8-
make prefix=/usr/local/stow/git-$1 -j3 install
8+
make prefix="/usr/local/stow/git-$1" -j3 install
99

1010
git checkout origin/man
1111

12-
rsync -av man1/ /usr/local/stow/git-$1/share/man/man1/
13-
rsync -av man5/ /usr/local/stow/git-$1/share/man/man5/
14-
rsync -av man7/ /usr/local/stow/git-$1/share/man/man7/
12+
rsync -av man1/ "/usr/local/stow/git-$1/share/man/man1/"
13+
rsync -av man5/ "/usr/local/stow/git-$1/share/man/man5/"
14+
rsync -av man7/ "/usr/local/stow/git-$1/share/man/man7/"
1515

1616
git clean -f -x -d
1717
git checkout master
@@ -23,4 +23,4 @@ git merge origin/master
2323
cd /usr/local/stow
2424
stow -D git-*
2525

26-
stow git-$1
26+
stow "git-$1"

git-changebar

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ fi
2727
REV="$1"
2828
shift
2929

30-
while ! [ -z "$1" ]
30+
while [ -n "$1" ]
3131
do
32-
if grep 'tex[[:space:]]*$' >/dev/null <<@
33-
$1
32+
if grep 'tex[[:space:]]*$' >/dev/null <<@
33+
$1
3434
@
3535
then
3636
FILE="$1"
@@ -39,7 +39,7 @@ $1
3939

4040
docstart=$(grep -n 'begin{document}' "$FILE" | cut -d: -f1)
4141

42-
for i in $(GIT_DIFF_OPTS=-u0 git diff "$REV" "$FILE" |
42+
for i in $(GIT_DIFF_OPTS=-u0 git diff "$REV" "$FILE" |
4343
sed -n '/^@@/s/@@ -[0-9,]* +\([0-9,]*\).*/\1/p')
4444
do
4545
start=$(cut -d, -f1 <<@
@@ -52,7 +52,7 @@ $i
5252
$i
5353
@
5454
then
55-
diff=$(cut -d, -f2 <<@
55+
diff=$(cut -d, -f2 <<@
5656
$i
5757
@
5858
)

0 commit comments

Comments
 (0)