├── git-track ├── grb ├── git-defbranch ├── gh-merged-branches └── setup.sh /git-track: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_BRANCH=`git symbolic-ref --short -q HEAD` 4 | REMOTE_BRANCH="origin/${CURRENT_BRANCH}" 5 | 6 | git branch -u "$REMOTE_BRANCH" 7 | -------------------------------------------------------------------------------- /grb: -------------------------------------------------------------------------------- 1 | DEFBRANCH=$(git defbranch) 2 | 3 | git co "$DEFBRANCH" 4 | git pull 5 | git branch --merged "$DEFBRANCH" | grep -v "\* $DEFBRANCH" | grep -v master | xargs -n 1 git branch -d 6 | gh-merged-branches | grep -v "\* $DEFBRANCH" | grep -v master | xargs -n 1 git branch -D 7 | git remote prune origin 8 | -------------------------------------------------------------------------------- /git-defbranch: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | TOKEN=`cat ~/.config/hub | grep 'oauth_token:' | sed s/oauth_token://g | xargs echo -n` 6 | GITHUB_REPO=`git remote -v | perl -nle 'if (/.*git\@github.com:([^\s]*?)(.git)?\s+.*/) { print "$1"; exit }'` 7 | 8 | curl -s --user "fcoury:$TOKEN" "https://api.github.com/repos/$GITHUB_REPO" | jq '.default_branch' | sed s/\"//g 9 | -------------------------------------------------------------------------------- /gh-merged-branches: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | for b in $(git branch | grep -v '^*'); do 6 | PR_STATE=`gh pr list --state all --head "$b" --json state | jq -r '.[0].state'` 7 | if [ "$PR_STATE" == "MERGED" ]; then 8 | REMOTE_EXISTS=$(git ls-remote --heads origin "$b" | wc -l) 9 | if [ "$REMOTE_EXISTS" -eq "1" ]; then 10 | CM_STATES=(`git rev-list --left-right --count "$b"..."origin/$b"`) 11 | CM_LOCAL="${CM_STATES[0]}" 12 | CM_REMOTE="${CM_STATES[1]}" 13 | 14 | if [ "$CM_LOCAL" == "0" ] && [ "$CM_REMOTE" == "0" ]; then 15 | echo $b 16 | fi 17 | else 18 | echo $b 19 | fi 20 | fi 21 | done 22 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SCRIPT=$(basename $0) 4 | SCRIPT_PATH=$(pwd) 5 | LINK_TARGET="$HOME/.local/bin" 6 | 7 | mkdir -p "$LINK_TARGET" 8 | 9 | # Takes a path argument and returns it as an absolute path. 10 | # No-op if the path is already absolute. 11 | function to-abs-path { 12 | local target="$1" 13 | 14 | if [ "$target" == "." ]; then 15 | echo "$(pwd)" 16 | elif [ "$target" == ".." ]; then 17 | echo "$(dirname "$(pwd)")" 18 | else 19 | echo "$( 20 | cd "$(dirname "$1")" 21 | pwd 22 | )/$(basename "$1")" 23 | fi 24 | } 25 | 26 | link-path() { 27 | cd "$1" 28 | for f in "$1"/*; do 29 | if [ "$f" != "./$SCRIPT" ]; then 30 | SOURCE=$(to-abs-path $f) 31 | TARGET="${LINK_TARGET}/$1/$f" 32 | TARGET="$(echo "$TARGET" | gsed -r 's|\.\/||g')" 33 | if [ -f "${f}/.link" ]; then 34 | LINK_NAME=$(cat "${f}/.link") 35 | TARGET="${LINK_TARGET}/${LINK_NAME}" 36 | fi 37 | if [ -e "$TARGET" ]; then 38 | echo Skipping: $SOURCE 39 | else 40 | echo "Linking: $SOURCE -> $TARGET" 41 | ln -s "$SOURCE" "$TARGET" 42 | fi 43 | fi 44 | done 45 | } 46 | 47 | link-path "." 48 | --------------------------------------------------------------------------------