Skip to content

Commit d57d5fc

Browse files
authored
Merge pull request jwiegley#50 from hyperupcall/some-improvements
2 parents 1997296 + 96e66fb commit d57d5fc

20 files changed

+61
-61
lines changed

git-closest-match

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ range=${3:-30} # 'all' or most recent <num> in current branch?. 'all' can be qui
88
if [ "$range" = 'all' ]; then
99
all=$(git rev-list --all | awk '/^commit/ {print $NF}')
1010
else
11-
all=$(git log -n $range | awk '/^commit/ {print $NF}')
11+
all=$(git log -n "$range" | awk '/^commit/ {print $NF}')
1212
fi
1313

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
20-
git log --no-walk $commit | cat -
21-
git diff -M $spec $commit | cat -
20+
git log --no-walk "$commit" | cat -
21+
git diff -M "$spec" "$commit" | cat -
2222
else
2323
printf '%s\n' "$commit: "
24-
git diff -M $spec $commit | wc -l
24+
git diff -M "$spec" "$commit" | wc -l
2525
fi

git-cmpdir

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if [[ "$1" == "--stat" ]]; then
66
shift 1
77
fi
88

9-
git checkout $1
9+
git checkout "$1"
1010
sync
1111
echo ----------------------------------------------------------------------
1212

git-contr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
filePath=$1
44

5-
git blame --line-porcelain -C $filePath | sed -n 's/^author //p' |
5+
git blame --line-porcelain -C "$filePath" | sed -n 's/^author //p' |
66
sort | uniq -c | sort -rn

git-current

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ else
88
fi
99
current="$ancestor"
1010

11-
ancestor=$(git rev-parse $ancestor)
11+
ancestor=$(git rev-parse "$ancestor")
1212

1313
for head in $(git rev-parse --branches); do
14-
if [[ $head != $ancestor ]]; then
15-
if git rev-list -30 $head | grep -q $ancestor; then
16-
current="$current $(git describe --all --abbrev=0 $head | sed 's/heads\///')"
17-
fi
14+
if [[ $head != "$ancestor" ]]; then
15+
if git rev-list -30 "$head" | grep -q "$ancestor"; then
16+
current="$current $(git describe --all --abbrev=0 "$head" | sed 's/heads\///')"
17+
fi
1818
fi
1919
done
2020

21-
git show-branch $current
21+
git show-branch "$current"

git-delete-branch

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
# remove remote git branch
33

4-
git branch -D $1 && git push origin :$1
4+
git branch -D "$1" && git push origin ":$1"

git-delete-tag

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
22
# remove remote git tag
33

4-
git tag -d $1
5-
git push origin :refs/tags/$1
4+
git tag -d "$1"
5+
git push origin ":refs/tags/$1"

git-diff-directory

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fi
88

99
HERE=$(pwd)
1010

11-
(cd "$1" && git --git-dir=$HERE/.git diff ${2:-HEAD}) | \
11+
(cd "$1" && git --git-dir="$HERE/.git" diff "${2:-HEAD}") | \
1212
if [[ $stat == true ]]; then \
1313
diffstat | grep -v only$; \
1414
else \

git-discover-large-blobs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
#set -x
2+
#set -x
33

44
# Shows you the largest objects in your repo's pack file.
55
#
@@ -18,9 +18,9 @@
1818
IFS=$'\n';
1919

2020
# find top-level dir of a non-bare repo
21-
_GIT_DIR=`git rev-parse --show-toplevel` || exit 1
21+
_GIT_DIR=$(git rev-parse --show-toplevel) || exit 1
2222

23-
if [ -n ${_GIT_DIR} ] && [ -d ${_GIT_DIR}/.git/objects/pack ]; then
23+
if [ -n "${_GIT_DIR}" ] && [ -d "${_GIT_DIR}"/.git/objects/pack ]; then
2424
PACK_DIR=${_GIT_DIR}/.git/objects/pack
2525
elif [ -d ./objects/pack ]; then
2626
# bare repo
@@ -29,25 +29,25 @@ else
2929
echo "Cannot locate pack directory"
3030
exit 1
3131
fi
32-
32+
3333
# list all objects including their size, sort by size, take top 10
34-
objects=`git verify-pack -v ${PACK_DIR}/pack-*.idx | grep -v chain | sort -k3nr | head`
34+
objects=$(git verify-pack -v "${PACK_DIR}"/pack-*.idx | grep -v chain | sort -k3nr | head)
3535

3636
echo "All sizes are in kB's. The pack column is the size of the object, compressed, inside the pack file."
3737

3838
output="size,pack,SHA,location"
3939
for y in $objects
4040
do
4141
# extract the size in bytes
42-
size=$((`echo $y | cut -f 5 -d ' '`/1024))
42+
size=$(($(echo $y | cut -f 5 -d ' ')/1024))
4343
# extract the compressed size in bytes
44-
compressedSize=$((`echo $y | cut -f 6 -d ' '`/1024))
44+
compressedSize=$(($(echo $y | cut -f 6 -d ' ')/1024))
4545
# extract the SHA
46-
sha=`echo $y | cut -f 1 -d ' '`
46+
sha=$(echo $y | cut -f 1 -d ' ')
4747
# find the objects location in the repository tree
48-
other=`git rev-list --all --objects | grep $sha`
48+
other=$(git rev-list --all --objects | grep "$sha")
4949
#lineBreak=`echo -e "\n"`
5050
output="${output}\n${size},${compressedSize},${other}"
5151
done
5252

53-
echo -e $output | column -t -s ', '
53+
echo -e "$output" | column -t -s ', '

git-empty-branch

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

33
git stash
4-
git symbolic-ref HEAD refs/heads/$1
4+
git symbolic-ref HEAD "refs/heads/$1"
55
rm .git/index
66
git clean -f -d

git-fat-objects

+2-2
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 hash type size; do
9+
while read -r hash type size; do
1010
echo -n "-e s/$hash/$size/p ";
1111
done) | \
12-
sort -n -k1
12+
sort -n -k1

git-fetch-github

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22
REMOTE=${1:-origin}
3-
git config remote.${REMOTE}.fetch "+refs/pull/*:refs/remotes/${REMOTE}/pr/*"
3+
git config "remote.${REMOTE}.fetch" "+refs/pull/*:refs/remotes/${REMOTE}/pr/*"

git-filemerge

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ TMPDIR1=$(mktemp -d)
1414
git archive --format=tar $OLD | (cd "$TMPDIR1"; tar xf -)
1515
if test -z "$NEW"; then
1616
TMPDIR2=$(git rev-parse --show-cdup)
17-
test -z "$cdup" && TMPDIR2=.
17+
test -z "$TMPDIR2" && TMPDIR2=.
1818
else
1919
TMPDIR2=$(mktemp -d)
2020
git archive --format=tar $NEW | (cd "$TMPDIR2"; tar xf -)

git-find-blob

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ filename=$1
44

55
want=$(git hash-object "$filename")
66

7-
git rev-list --since="6 months ago" HEAD | while read commit ; do
8-
git ls-tree -r $commit | while read perm type hash filename; do
7+
git rev-list --since="6 months ago" HEAD | while read -r commit ; do
8+
git ls-tree -r "$commit" | while read -r perm type hash filename; do
99
if test "$want" = "$hash"; then
10-
echo matched $filename in commit $commit
10+
echo "matched $filename in commit $commit"
1111
fi
1212
done
1313
done

git-find-useful-dangling-trees

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ depth=${1:-all} # 'all' or number of depth
44
for i in $(git fsck --unreachable | grep -E 'tree|commit' | cut -d\ -f3)
55
do
66
echo -n "U:$i CM:"
7-
git-closest-match $i num $depth
7+
git-closest-match "$i" num "$depth"
88
done

git-flush

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# as possible, by dropping all reflogs, stashes, and other cruft that may
55
# be bloating your pack files.
66

7-
/bin/rm -fr .git/refs/original
8-
/bin/rm -fr .git/refs/snapshots
7+
rm -fr .git/refs/original
8+
rm -fr .git/refs/snapshots
99

1010
if [ -f .git/info/refs ]; then
1111
perl -i -ne 'print unless /refs\/original/;' .git/info/refs

git-follow

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

3-
CURRENT=$(basename $(pwd))
3+
CURRENT=$(basename "$(pwd)")
44

5-
git remote add -t master -f $1 git://github.com/$1/$CURRENT.git
5+
git remote add -t master -f "$1" "git://github.com/$1/$CURRENT.git"

git-hunt-and-seek

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

33
for hash in $(grep ^commit | awk '{print $2}'); do
4-
git diff-directory $1 $hash
4+
git diff-directory "$1" "$hash"
55
done

git-ignore-wizard

+13-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# basename
77

88
file=$1
9-
if [ -z "$file" -o ! -e "$file" ]
9+
if [[ -z "$file" || ! -e "$file" ]]
1010
then
1111
echo 'No such file or directory' >&2
1212
exit 2
@@ -21,24 +21,24 @@ exclude # specific to it's repo, but irrelevant to other devs
2121

2222
[ -z "$type" ] && echo 'Cancelled' && exit 0
2323

24-
dirname=$( dirname $file)
25-
basename=$(basename $file)
24+
dirname=$( dirname "$file")
25+
basename=$(basename "$file")
2626
case $type in
2727
.gitignore-root)
28-
root=$(git root $file) || exit 2
29-
dirname=$(readlink -f $dirname)
30-
relative_dir=$(echo $dirname | sed "s#^$root##") # ie: /src
31-
echo "$relative_dir/$basename" >> $root/.gitignore
28+
root=$(git root "$file") || exit 2
29+
dirname=$(readlink -f "$dirname")
30+
relative_dir=$(echo "$dirname" | sed "s#^$root##") # ie: /src
31+
echo "$relative_dir/$basename" >> "$root/.gitignore"
3232
;;
3333
.gitignore-dirname)
34-
git root $file >/dev/null || exit 2
35-
echo "$basename" >> $dirname/.gitignore
34+
git root "$file ">/dev/null || exit 2
35+
echo "$basename" >> "$dirname/.gitignore"
3636
;;
3737
exclude)
38-
root=$(git root $file) || exit 2
39-
dirname=$(readlink -f $dirname)
40-
relative_dir=$(echo $dirname | sed "s#^$root##")
41-
echo "$relative_dir/$basename" >> $root/info/exclude
38+
root=$(git root "$file") || exit 2
39+
dirname=$(readlink -f "$dirname")
40+
relative_dir=$(echo "$dirname" | sed "s#^$root##")
41+
echo "$relative_dir/$basename" >> "$root/info/exclude"
4242
;;
4343
.gitconfig)
4444
#TODO. git config --get-all ?, then another dmenu? how many such config keys are allowed?

git-igunk

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

3-
git ls-files --other --exclude-standard | while read path; do
3+
git ls-files --other --exclude-standard | while read -r path; do
44
echo "/$path" >> .gitignore
55
done

git-interactive-merge

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ then
66
fi
77
from=$1
88
to=$2
9-
git checkout $from
10-
git checkout -b ${from}_tmp
9+
git checkout "$from"
10+
git checkout -b "${from}_tmp"
1111
# drops you in an editor, pick the changes you want
12-
git rebase -i $to
13-
git checkout $to
14-
git pull . ${from}_tmp
15-
git branch -d ${from}_tmp
12+
git rebase -i "$to"
13+
git checkout "$to"
14+
git pull . "${from}_tmp"
15+
git branch -d "${from}_tmp"

0 commit comments

Comments
 (0)