Skip to content

Commit 9a2edb0

Browse files
committed
chore: More Bash improvements
1 parent 5b01da5 commit 9a2edb0

10 files changed

+24
-44
lines changed

Diff for: git-addsub

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ for dir in "$@"; do
1212
SUBDIR=$(abspath "$dir")
1313
SUBDIR=$(echo $SUBDIR | sed s/$PROJ_RE//)
1414

15-
repo=$(echo $(grep "url = " "$dir/.git/config") | \
15+
repo=$(grep "url = " "$dir/.git/config" | \
1616
sed 's/.*url = //' | \
1717
sed 's/[email protected]:\([^\/]*\)\//git:\/\/github.com\/\1\//' )
1818

Diff for: git-clone.sh

+5-12
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,21 @@
33
# this script clones a repository, including all its remote branches
44
# Author: julianromera
55

6-
GIT=$(command -v git)
7-
8-
if [ "$1" = "" -o "$2" = "" ];then
6+
if [[ -z "$1" || -z "$2" ]];then
97
echo "use: $0 <git_repository_to_clone> <directory>"
108
exit 1
119
fi
1210

13-
if [ "$GIT" = "" ];then
14-
echo "No git command found. install it"
15-
fi
1611

1712
function clone {
1813

19-
$GIT clone -q "$1" "$2"
20-
res=$?
21-
14+
git clone -q "$1" "$2"
2215
cd "$2"
2316

24-
$GIT pull --all
17+
git pull --all
2518

26-
for remote in $($GIT branch -r | grep -v \>); do
27-
$GIT branch --track "${remote#origin/}" "$remote";
19+
for remote in $(git branch -r | grep -v \>); do
20+
git branch --track "${remote#origin/}" "$remote";
2821
done
2922
}
3023

Diff for: git-each

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
DIRS="."
4+
dirs="."
55
if [[ "$1" == --dir ]]; then
6-
shift 1
7-
DIRS="$1"
8-
shift 1
6+
dirs="$2"
7+
shift 2
98
fi
109

11-
exec find $DIRS \( -path '*/.git/config' -o \
10+
exec find $dirs \( -path '*/.git/config' -o \
1211
-regex '.*/.git/.*/config' \) -type f -print0 \
13-
| parallel -0 --bar -j0 --delay 1 -k "git --git-dir={//} $@"
12+
| parallel -0 --bar -j0 --delay 1 -k "git --git-dir={//} $*"

Diff for: git-fat-objects

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ git rev-list --all --objects | \
66
grep blob | \
77
sort -n -k 3 | \
88
tail -n40 | \
9-
while read -r hash type size; do
9+
while read -r hash _type size; do
1010
echo -n "-e s/$hash/$size/p ";
1111
done) | \
1212
sort -n -k1

Diff for: git-find-children

-12
This file was deleted.

Diff for: git-fire-subtree/git-fire

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fire() {
4949
done
5050

5151
for sha in $(git rev-list -g stash); do
52-
git push origin "$sha":refs/heads/"$(current_branch $initial_branch)"-stash-"$sha"
52+
git push origin "$sha":refs/heads/"$(current_branch "$initial_branch")"-stash-"$sha"
5353
done
5454

5555
printf "\n\nLeave building!\n"

Diff for: git-pulltree

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env bash
2-
git subtree pull --prefix $1 ext/$(basename $1) master --squash
2+
git subtree pull --prefix "$1" "ext/$(basename "$1")" master --squash

Diff for: git-pushtree

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env bash
2-
git subtree push --prefix $1 fork/$(basename $1) master
2+
git subtree push --prefix "$1" "fork/$(basename "$1")" master

Diff for: git-remote-in-sync.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
# written by Dieter Plaetinck
1414

15-
list="$@"
15+
list="$*"
1616
[ -z "$list" ] && list=$(git remote)
1717
ret=0
1818

1919
if [ -z "$(git branch)" ]
2020
then
21-
if [ $(cd "$(git root)" && ls -Al | egrep -v "^(.git|total)" | wc -l) -gt 0 ]
21+
if [ "$(cd "$(git root)" && ls -Al | grep -Ev "^(.git|total)" | wc -l)" -gt 0 ]
2222
then
2323
echo "WARN: This repo doesn't contain any branch, but contains a bunch of files!" >&2
2424
ls -Alh "$(git root)"
@@ -39,10 +39,10 @@ then
3939
echo "WARN: At least one branch, but no remotes found! The content here might be unique!" >&2
4040
ret=1
4141
else
42-
if [ -n "$@" ]
42+
if [ -n "$*" ]
4343
then
44-
echo "INFO: working with remote(s): $@"
45-
echo "INFO: fyi, all remotes: "$(git remote)
44+
echo "INFO: working with remote(s): $*"
45+
echo "INFO: fyi, all remotes: $(git remote)"
4646
else
4747
echo "INFO: working with all remotes: $list"
4848
fi
@@ -86,13 +86,13 @@ do
8686
IFS=$IFS_BACKUP
8787

8888
# Check tags
89-
out=$(git push --tags -n $remote 2>&1)
89+
out=$(git push --tags -n "$remote" 2>&1)
9090
if [ "$out" != 'Everything up-to-date' ];
9191
then
9292
echo -e " WARN: Some tags are not in $remote!\n$out" >&2
9393
ret=1
9494
else
95-
echo " INFO: All tags ("$(git tag)") exist at $remote as well"
95+
echo " INFO: All tags ($(git tag)) exist at $remote as well"
9696
fi
9797
done
9898

@@ -122,7 +122,7 @@ then
122122
fi
123123

124124
# Check stash
125-
if [ $(git stash list | wc -l) -gt 0 ];
125+
if [ "$(git stash list | wc -l)" -gt 0 ];
126126
then
127127
echo "WARN: Dirty stash:" >&2
128128
GIT_PAGER= git stash list >&2

Diff for: git-standup

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

33
if [[ $# -gt 2 ]] ; then
4-
>&2 echo "Usage: $0 [fullname] [weekstart-weekend]\nExample: $0 \"John Doe\" MON-FRI"
4+
>&2 printf '%s\n%s' "Usage: $0 [fullname] [weekstart-weekend]" "Example: $0 \"John Doe\" MON-FRI"
55
exit 1
66
fi
77

0 commit comments

Comments
 (0)