Skip to content

Commit

Permalink
chore: More Bash improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Feb 22, 2023
1 parent 5b01da5 commit 9a2edb0
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 44 deletions.
2 changes: 1 addition & 1 deletion git-addsub
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ for dir in "$@"; do
SUBDIR=$(abspath "$dir")
SUBDIR=$(echo $SUBDIR | sed s/$PROJ_RE//)

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

Expand Down
17 changes: 5 additions & 12 deletions git-clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,21 @@
# this script clones a repository, including all its remote branches
# Author: julianromera

GIT=$(command -v git)

if [ "$1" = "" -o "$2" = "" ];then
if [[ -z "$1" || -z "$2" ]];then
echo "use: $0 <git_repository_to_clone> <directory>"
exit 1
fi

if [ "$GIT" = "" ];then
echo "No git command found. install it"
fi

function clone {

$GIT clone -q "$1" "$2"
res=$?

git clone -q "$1" "$2"
cd "$2"

$GIT pull --all
git pull --all

for remote in $($GIT branch -r | grep -v \>); do
$GIT branch --track "${remote#origin/}" "$remote";
for remote in $(git branch -r | grep -v \>); do
git branch --track "${remote#origin/}" "$remote";
done
}

Expand Down
11 changes: 5 additions & 6 deletions git-each
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env bash
set -e

DIRS="."
dirs="."
if [[ "$1" == --dir ]]; then
shift 1
DIRS="$1"
shift 1
dirs="$2"
shift 2
fi

exec find $DIRS \( -path '*/.git/config' -o \
exec find $dirs \( -path '*/.git/config' -o \
-regex '.*/.git/.*/config' \) -type f -print0 \
| parallel -0 --bar -j0 --delay 1 -k "git --git-dir={//} $@"
| parallel -0 --bar -j0 --delay 1 -k "git --git-dir={//} $*"
2 changes: 1 addition & 1 deletion git-fat-objects
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ git rev-list --all --objects | \
grep blob | \
sort -n -k 3 | \
tail -n40 | \
while read -r hash type size; do
while read -r hash _type size; do
echo -n "-e s/$hash/$size/p ";
done) | \
sort -n -k1
12 changes: 0 additions & 12 deletions git-find-children

This file was deleted.

2 changes: 1 addition & 1 deletion git-fire-subtree/git-fire
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fire() {
done

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

printf "\n\nLeave building!\n"
Expand Down
2 changes: 1 addition & 1 deletion git-pulltree
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
git subtree pull --prefix $1 ext/$(basename $1) master --squash
git subtree pull --prefix "$1" "ext/$(basename "$1")" master --squash
2 changes: 1 addition & 1 deletion git-pushtree
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
git subtree push --prefix $1 fork/$(basename $1) master
git subtree push --prefix "$1" "fork/$(basename "$1")" master
16 changes: 8 additions & 8 deletions git-remote-in-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

# written by Dieter Plaetinck

list="$@"
list="$*"
[ -z "$list" ] && list=$(git remote)
ret=0

if [ -z "$(git branch)" ]
then
if [ $(cd "$(git root)" && ls -Al | egrep -v "^(.git|total)" | wc -l) -gt 0 ]
if [ "$(cd "$(git root)" && ls -Al | grep -Ev "^(.git|total)" | wc -l)" -gt 0 ]
then
echo "WARN: This repo doesn't contain any branch, but contains a bunch of files!" >&2
ls -Alh "$(git root)"
Expand All @@ -39,10 +39,10 @@ then
echo "WARN: At least one branch, but no remotes found! The content here might be unique!" >&2
ret=1
else
if [ -n "$@" ]
if [ -n "$*" ]
then
echo "INFO: working with remote(s): $@"
echo "INFO: fyi, all remotes: "$(git remote)
echo "INFO: working with remote(s): $*"
echo "INFO: fyi, all remotes: $(git remote)"
else
echo "INFO: working with all remotes: $list"
fi
Expand Down Expand Up @@ -86,13 +86,13 @@ do
IFS=$IFS_BACKUP

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

Expand Down Expand Up @@ -122,7 +122,7 @@ then
fi

# Check stash
if [ $(git stash list | wc -l) -gt 0 ];
if [ "$(git stash list | wc -l)" -gt 0 ];
then
echo "WARN: Dirty stash:" >&2
GIT_PAGER= git stash list >&2
Expand Down
2 changes: 1 addition & 1 deletion git-standup
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

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

Expand Down

0 comments on commit 9a2edb0

Please sign in to comment.