Skip to content

Commit 75d0dbf

Browse files
authored
chore: Various Bash improvements (#1029)
1 parent 9c3343d commit 75d0dbf

25 files changed

+95
-95
lines changed

bin/git-archive-file

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ BRANCH=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
55

66
# get name of the most top folder of current directory, used for the
77
# output filename
8-
ARCHIVE_NAME=$(basename "$(pwd)")
8+
ARCHIVE_NAME=$(basename "$PWD")
99

1010
if [[ $BRANCH = tags* ]]; then
1111
BRANCH=$(git describe)
@@ -28,7 +28,7 @@ fi
2828
FILENAME=${FILENAME//\//-}
2929
FILENAME=${FILENAME//\\/-}
3030
# combine path and filename
31-
OUTPUT=$(pwd)/$FILENAME
31+
OUTPUT=$PWD/$FILENAME
3232

3333
# building archive
3434
git archive --format zip --output "$OUTPUT" "$BRANCH"

bin/git-bulk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ function executBulkOp () {
132132
parseWsName "$workspacespec"
133133
if [[ -n $wsname ]] && [[ $rwsname != "$wsname" ]]; then continue; fi
134134
eval cd "\"$rwsdir\""
135-
local actual=$(pwd)
135+
local actual=$PWD
136136
[ "${quiet?}" != "true" ] && echo 1>&2 "Executing bulk operation in workspace ${inverse}$actual${reset}"
137137

138138
allGitFolders=( $(eval find -L . -name ".git") )
139139

140140
for line in ${allGitFolders[@]}; do
141141
local gitrepodir=${line::${#line}-5} # cut the .git part of find results to have the root git directory of that repository
142142
eval cd "\"$gitrepodir\"" # into git repo location
143-
local curdir=$(pwd)
143+
local curdir=$PWD
144144
local leadingpath=${curdir#${actual}}
145145
guardedExecution "$@"
146146
eval cd "\"$rwsdir\"" # back to origin location of last find command

bin/git-clear-soft

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

33
echo -n "Sure? - This command may delete files that cannot be recovered. Files and directories in .gitignore will be preserved [y/N]: "
4-
read ans
5-
if [ "$ans" == "y" ]
4+
read -r ans
5+
if [ "$ans" == "y" ]
66
then git clean -d -f && git reset --hard
77
fi

bin/git-delete-submodule

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test ! -f '.gitmodules' && abort 2 '.gitmodules file not found'
1515

1616
NAME="${1%/}"
1717
test -z "$(git config --file='.gitmodules' "submodule.$NAME.url")" \
18-
&& abort 3 'Submodule not found'
18+
&& abort 3 'Submodule not found'
1919

2020
# 1. Handle the .git directory
2121
# 1.a. Delete the relevant section from .git/config

bin/git-feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@ else
6262

6363
if [[ -n $remote ]] && [[ -z $start_point ]]
6464
then
65-
git create-branch -r $remote $branch
65+
git create-branch -r "$remote" "$branch"
6666
fi
6767

6868
if [[ -z $remote ]] && [[ -z $start_point ]]
6969
then
70-
git create-branch $branch
70+
git create-branch "$branch"
7171
fi
7272

7373
if [[ -n $remote ]] && [[ -n $start_point ]]
7474
then
75-
git create-branch -r $remote --from $start_point $branch
75+
git create-branch -r "$remote" --from "$start_point" "$branch"
7676
fi
7777

7878
if [[ -z $remote ]] && [[ -n $start_point ]]
7979
then
80-
git create-branch --from $start_point $branch
80+
git create-branch --from "$start_point" "$branch"
8181
fi
8282
fi

bin/git-fresh-branch

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
branch=$1
44

5-
test -z $branch && echo "branch required." 1>&2 && exit 1
5+
test -z "$branch" && echo "branch required." 1>&2 && exit 1
66

7-
changes=`git status --porcelain`
7+
changes=$(git status --porcelain)
88

99
clean()
1010
{
11-
git symbolic-ref HEAD refs/heads/$branch
11+
git symbolic-ref HEAD "refs/heads/$branch"
1212
rm .git/index
1313
git clean -fdx
1414
}
1515

16-
if [ ! -z "$changes" ]; then
17-
read -p "All untracked changes will be lost. Continue [y/N]? " res
16+
if [ -n "$changes" ]; then
17+
read -rp "All untracked changes will be lost. Continue [y/N]? " res
1818
case $res in
1919
[Yy]* ) ;;
2020
* ) exit 0;;

bin/git-graft

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
src=$1
44
dst=$2
55

6-
test -z $src && echo "source branch required." 1>&2 && exit 1
7-
test -z $dst && echo "destination branch required." 1>&2 && exit 1
6+
test -z "$src" && echo "source branch required." 1>&2 && exit 1
7+
test -z "$dst" && echo "destination branch required." 1>&2 && exit 1
88

9-
git checkout $dst \
10-
&& git merge --no-ff $src \
11-
&& git branch -d $src
9+
git checkout "$dst" \
10+
&& git merge --no-ff "$src" \
11+
&& git branch -d "$src"

bin/git-guilt

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

3-
for param in $*
3+
for param in "$@"
44
do
55
case $param in
66
-h)
@@ -44,11 +44,11 @@ for file in $(git diff --name-only "$@")
4444
do
4545
test -n "$DEBUG" && echo "git blame $file"
4646
# $1 - since $2 - until
47-
git blame $NOT_WHITESPACE --line-porcelain "$1" -- "$file" 2> /dev/null |
48-
LC_ALL=C sed -n "$PATTERN" | sort | uniq -c | LC_ALL=C sed 's/^\(.\)/- \1/' >> $MERGED_LOG
47+
git blame $NOT_WHITESPACE --line-porcelain "$1" -- "$file" 2> /dev/null |
48+
LC_ALL=C sed -n "$PATTERN" | sort | uniq -c | LC_ALL=C sed 's/^\(.\)/- \1/' >> "$MERGED_LOG"
4949
# if $2 not given, use current commit as "until"
5050
git blame $NOT_WHITESPACE --line-porcelain "${2-@}" -- "$file" 2> /dev/null |
51-
LC_ALL=C sed -n "$PATTERN" | sort | uniq -c | LC_ALL=C sed 's/^\(.\)/+ \1/' >> $MERGED_LOG
51+
LC_ALL=C sed -n "$PATTERN" | sort | uniq -c | LC_ALL=C sed 's/^\(.\)/+ \1/' >> "$MERGED_LOG"
5252
done
5353

5454
DEBUG="$DEBUG" awk '
@@ -71,8 +71,8 @@ END {
7171
printf("%d %s\n", contributors[people], people)
7272
}
7373
}
74-
}' $MERGED_LOG | sort -nr | # only gawk supports built-in sort function
75-
while read line
74+
}' $MERGED_LOG | sort -nr | # only gawk supports built-in sort function
75+
while read -r line
7676
do
7777
people=${line#* }
7878
num=${line%% *}

bin/git-ignore-io

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ print_in_alphabetical_order() {
1717
for ignorable in $(echo "$gi_list" | sort);
1818
do
1919
first_character=${ignorable:0:1}
20-
if [[ $first_character = $previous_first_character ]]; then
20+
if [[ $first_character = "$previous_first_character" ]]; then
2121
printf " %s" "$ignorable"
2222
elif [[ $first = true ]]; then
2323
previous_first_character=$first_character

bin/git-info

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ echon "${COLOR_TITLE}## Local Branches:${NORMAL}"
6565
echon "$(local_branches)"
6666

6767
SUBMODULES_LOG=$(submodules)
68-
if [ ! -z "$SUBMODULES_LOG" ]; then
68+
if [ -n "$SUBMODULES_LOG" ]; then
6969
echon "${COLOR_TITLE}## Submodule(s):${NORMAL}"
7070
echon "$SUBMODULES_LOG"
7171
fi
7272

7373
echon "${COLOR_TITLE}## Most Recent Commit:${NORMAL}"
7474
echon "$(most_recent_commit)"
7575

76-
if [ ! -z "$HIDE_CONFIG" ]; then
76+
if [ -n "$HIDE_CONFIG" ]; then
7777
echon "${COLOR_TITLE}## Configuration (.git/config):${NORMAL}"
7878
echon "$(get_config)"
7979
fi

0 commit comments

Comments
 (0)