|
1 | | -#!/bin/sh |
| 1 | +#!/bin/bash |
2 | 2 | # |
3 | 3 | # git-prune-branches |
4 | 4 | # |
|
14 | 14 | # License: MIT |
15 | 15 | # Original source: https://github.com/jut-io/git-scripts/blob/master/bin/git-prune-branches |
16 | 16 |
|
17 | | -merged=`git branch --no-color --merged master | grep -v master | sed 's/\*/ /'` |
| 17 | +merged=$(git branch --no-color --merged master | grep -v master | sed 's/\*/ /') |
18 | 18 |
|
19 | 19 | if [ ! -z "$merged" ] ; then |
20 | 20 | echo "Deleting the following merged branches:" |
21 | 21 | for branch in $merged ; do |
22 | | - echo " " $branch |
| 22 | + echo " " "$branch" |
23 | 23 | done |
24 | 24 |
|
25 | 25 | all=n |
26 | 26 | delete=n |
27 | 27 | for branch in $merged ; do |
28 | | - if [ $all = 'n' ] ; then |
29 | | - delete=n |
30 | | - read -p "Delete $branch (y=yes, n=no, a=all)? " prompt |
31 | | - echo "all=$all delete=$delete prompt=$prompt" |
32 | | - if [ "$prompt" = 'a' ] ; then |
33 | | - delete=y |
34 | | - all=y |
35 | | - elif [ "$prompt" = 'y' ]; then |
36 | | - delete=y |
37 | | - fi |
38 | | - fi |
| 28 | + if [ $all = 'n' ] ; then |
| 29 | + delete=n |
| 30 | + # shellcheck disable=SC2162 |
| 31 | + read -p "Delete $branch (y=yes, n=no, a=all)? " prompt |
| 32 | + echo "all=$all delete=$delete prompt=$prompt" |
| 33 | + if [ "$prompt" = 'a' ] ; then |
| 34 | + delete=y |
| 35 | + all=y |
| 36 | + elif [ "$prompt" = 'y' ]; then |
| 37 | + delete=y |
| 38 | + fi |
| 39 | + fi |
39 | 40 |
|
40 | | - if [ "$delete" = 'y' ] ; then |
41 | | - git branch -d $branch |
42 | | - fi |
| 41 | + if [ "$delete" = 'y' ] ; then |
| 42 | + git branch -d "$branch" |
| 43 | + fi |
43 | 44 | done |
44 | 45 | fi |
45 | 46 |
|
46 | | -remotes=`git remote` |
| 47 | +remotes=$(git remote) |
47 | 48 | for remote in $remotes ; do |
48 | 49 | prompt=n |
| 50 | + # shellcheck disable=SC2162 |
49 | 51 | read -p "Prune deleted branches from remote '$remote' (y=yes n=no)? " prompt |
50 | 52 | if [ "$prompt" = 'y' ] ; then |
51 | | - git remote prune $remote |
| 53 | + git remote prune "$remote" |
52 | 54 | fi |
53 | 55 | done |
0 commit comments