Skip to content

Commit d35b55e

Browse files
committed
chore: Improve quoting read invocations, and more
1 parent d57d5fc commit d35b55e

22 files changed

+86
-84
lines changed

Diff for: git-addremove

+1-1
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

Diff for: git-addtree

+1-1
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

Diff for: git-all-commits

+8-8
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

Diff for: git-all-objects

+2-2
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

Diff for: git-already-merged

+1-1
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

Diff for: git-amend-all

+2-2
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

Diff for: git-apply-url

+6-6
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

Diff for: git-branch-done

+2-2
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"

Diff for: git-build

+7-7
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"

Diff for: git-changebar

+5-5
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
)

Diff for: git-checkout-branches

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ set -e
1212
# User is not in git repository
1313
if ! git branch > /dev/null 2>&1
1414
then
15-
echo "E: '$(basename ${PWD})' - Not a Git repository."
15+
echo "E: '$(basename "${PWD}")' - Not a Git repository."
1616
exit 1
1717
fi
1818

Diff for: git-children-of

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ branch=$2
55

66
[ -z "$branch" ] && branch=HEAD
77

8-
git rev-list --children $branch --not $commit^@ \
8+
git rev-list --children "$branch" --not "$commit^@" \
99
| awk "/^$commit/ { print \$2 }"
1010

Diff for: git-clone.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@
55

66
GIT=$(command -v git)
77

8-
if [ "x$1" = "x" -o "x$2" = "x" ];then
8+
if [ "$1" = "" -o "$2" = "" ];then
99
echo "use: $0 <git_repository_to_clone> <directory>"
1010
exit 1
1111
fi
1212

13-
if [ "x$GIT" = "x" ];then
13+
if [ "$GIT" = "" ];then
1414
echo "No git command found. install it"
1515
fi
1616

1717
function clone {
1818

19-
$GIT clone -q $1 $2
19+
$GIT clone -q "$1" "$2"
2020
res=$?
21-
21+
2222
cd "$2"
23-
23+
2424
$GIT pull --all
25-
25+
2626
for remote in $($GIT branch -r | grep -v \>); do
27-
$GIT branch --track ${remote#origin/} $remote;
27+
$GIT branch --track "${remote#origin/}" "$remote";
2828
done
2929
}
3030

3131
echo "cloning repository into ... $2"
32-
clone $1 "$2"
32+
clone "$1" "$2"

Diff for: git-closest-match

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fi
1414
commit=$(for i in $all; do
1515
printf '%s\n' "$i "
1616
# why is there no git diff --shortnumstat ?
17-
git diff -M "$spec" $i | wc -l
17+
git diff -M "$spec" "$i" | wc -l
1818
done | sort -k 2 -n | head -n 1 | cut -f 1 -d ' ')
1919
if [ "$mode" = diff ]; then
2020
git log --no-walk "$commit" | cat -

Diff for: git-smerge

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@
33
current=$(git symbolic-ref HEAD | sed 's%refs/heads/%%')
44
branch=$1
55

6-
if ! git merge $branch; then
7-
echo GIT-SMERGE: Simple merge with $branch failed, attempting rebase-merge
6+
if ! git merge "$branch"; then
7+
echo "GIT-SMERGE: Simple merge with $branch failed, attempting rebase-merge"
88

99
git reset --hard HEAD
1010
git checkout -b temp.$$
1111

12-
if git rebase $branch > /dev/null 2>&1; then
13-
echo GIT-SMERGE: Rebase with $branch succeeded, using tree to create merge commit
12+
if git rebase "$branch" > /dev/null 2>&1; then
13+
echo "GIT-SMERGE: Rebase with $branch succeeded, using tree to create merge commit"
1414

15-
if ! git checkout $current; then
15+
if ! git checkout "$current"; then
1616
echo GIT-SMERGE: Some strange problem occurred!
1717
git branch -D temp.$$
1818
exit 1
1919
fi
2020

21-
git merge $branch > /dev/null 2>&1 # this is sure to fail
21+
git merge "$branch" > /dev/null 2>&1 # this is sure to fail
2222
git clean -fd
2323
git archive --format=tar temp.$$ | tar xf -
2424
git branch -D temp.$$
2525
git add .
2626
git add -A
27-
git ls-files --deleted -z | xargs -0 git rm
27+
git ls-files --deleted -z | xargs -0 git rm
2828
git commit
2929
else
30-
echo GIT-SMERGE: Rebase with $branch failed, returning to failed merge
30+
echo "GIT-SMERGE: Rebase with $branch failed, returning to failed merge"
3131

3232
git rebase --abort
33-
git checkout -f $current
33+
git checkout -f "$current"
3434
git branch -D temp.$$
35-
git merge $branch > /dev/null 2>&1 # this is sure to fail
35+
git merge "$branch" > /dev/null 2>&1 # this is sure to fail
3636
fi
3737
fi

Diff for: git-stale-branches

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ fi
77
git fetch --all
88

99
for r in $(git branch -r --format='%(refname)'); do
10-
git branch --merged $r;
10+
git branch --merged "$r";
1111
done | sort -u | grep -v '^\*' | xargs -r echo # git branch -D

Diff for: git-status-all

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

3-
find . -name .git -type d | \
4-
while read path; do \
5-
(cd "$path/.."; echo $(dirname "$path") ; git status); \
6-
done
3+
find . -name .git -type d |
4+
while read -r path; do
5+
(
6+
cd "$path/.." && dirname "$path" && git status
7+
)
8+
done

Diff for: git-sync

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
#!/usr/bin/env bash
22

3-
DIRS="$@"
3+
DIRS="$*"
44
if [[ -z "$DIRS" ]]; then
55
DIRS="."
66
fi
77

88
find "$DIRS" \( -name .git -o -name '*.git' \) -type d | \
9-
while read repo_dir
9+
while read -r repo_dir
1010
do
1111
if [[ -f "$repo_dir"/config ]]
1212
then
1313
# If this is a git-svn repo, use git svn fetch
1414
if grep -q '^\[svn-remote ' "$repo_dir"/config
1515
then
16-
echo git svn fetch: $repo_dir
16+
echo "git svn fetch: $repo_dir"
1717
GIT_DIR="$repo_dir" git svn fetch
1818

1919
# If this is a gc-utils repo, use gc-utils update
2020
elif grep -q '^\[gc-utils\]' "$repo_dir"/config
2121
then
22-
echo gc-utils update: $repo_dir
23-
(cd "$repo_dir"; gc-utils update)
22+
echo "gc-utils update: $repo_dir"
23+
(cd "$repo_dir" && gc-utils update)
2424

2525
else
2626
for remote in $(GIT_DIR="$repo_dir" git remote)
2727
do
2828
if [[ $remote != mirror ]]; then
29-
echo git fetch: $repo_dir -- $remote
30-
GIT_DIR="$repo_dir" git fetch $remote
29+
echo "git fetch: $repo_dir -- $remote"
30+
GIT_DIR="$repo_dir" git fetch "$remote"
3131
fi
3232
done
3333
fi
3434

3535
for remote in $(GIT_DIR="$repo_dir" git remote)
3636
do
3737
if [[ $remote == mirror ]]; then
38-
echo git push: $repo_dir -- $remote
39-
GIT_DIR="$repo_dir" git push --mirror $remote
38+
echo "git push: $repo_dir -- $remote"
39+
GIT_DIR="$repo_dir" git push --mirror "$remote"
4040
fi
4141
done
4242
fi

Diff for: git-track-branch

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22

33
branch_name=$1
4-
git checkout --track -b ${branch_name} origin/${branch_name}
4+
git checkout --track -b "${branch_name}" "origin/${branch_name}"

Diff for: git-undo

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ case $cmd in
2525
;;
2626

2727
pull|merge|rebase|am)
28-
git reset --hard HEAD@{0}
28+
git reset --hard "HEAD@{0}"
2929
;;
3030
esac
3131

Diff for: git-unpack

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if [ -f .git/objects/pack/*.pack ]; then
55
GIT_DIR=/tmp/tmpgit.$$ git init
66

77
for pack in .git/objects/pack/*.pack; do
8-
GIT_DIR=/tmp/tmpgit.$$ git unpack-objects < $pack
8+
GIT_DIR=/tmp/tmpgit.$$ git unpack-objects < "$pack"
99
if [ $? -ne 0 ]; then
1010
echo "Unpack of $pack failed, aborting"
1111
exit 1

0 commit comments

Comments
 (0)