std sh til-kron
[sunny256-utils.git] / git-nocom
blobb47641accd48a5dc9b8b08d5b9e7302cde4b0d04
1 #!/usr/bin/env bash
3 #=======================================================================
4 # git-nocom
5 # File ID: 6553a34c-1194-11e2-97b0-fefdb24f8e10
7 # List all branches except those containing "commit-[0-9a-f]{40}" .
8 # Can be used for things like this:
10 # git log `git branch -a | git nocom`
12 # Author: Øyvind A. Holm <sunny@sunbase.org>
13 # License: GNU General Public License version 2 or later.
14 #=======================================================================
16 progname=git-nocom
17 VERSION=0.2.1
19 ARGS="$(getopt -o "\
24 " -l "\
25 help,\
26 quiet,\
27 reverse,\
28 verbose,\
29 version,\
30 " -n "$progname" -- "$@")"
31 test "$?" = "0" || exit 1
32 eval set -- "$ARGS"
34 opt_help=0
35 opt_quiet=0
36 opt_reverse=0
37 opt_verbose=0
38 while :; do
39 case "$1" in
40 -h|--help) opt_help=1; shift ;;
41 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
42 -r|--reverse) opt_reverse=1; shift ;;
43 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
44 --version) echo $progname $VERSION; exit 0 ;;
45 --) shift; break ;;
46 *) echo $progname: Internal error >&2; exit 1 ;;
47 esac
48 done
49 opt_verbose=$(($opt_verbose - $opt_quiet))
51 if test "$opt_help" = "1"; then
52 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
53 cat <<END
55 List all branches except those containing "commit-[0-9a-f]{40}" .
56 Can be used for things like this:
58 git log \`git branch -a | git nocom\`
60 Usage: $progname [options]
62 Options:
64 -h, --help
65 Show this help.
66 -q, --quiet
67 Be more quiet. Can be repeated to increase silence.
68 -r, --reverse
69 Reverse the behaviour, only display commit-* branches.
70 -v, --verbose
71 Increase level of verbosity. Can be repeated.
72 --version
73 Print version information.
75 END
76 exit 0
79 v_str=
80 test "$opt_reverse" = "1" || v_str=-v
81 grep -v "HEAD detached" |
82 fmt -1 |
83 tr -d '\t ' |
84 grep -v -E '^(->|\*|.*/HEAD)$' |
85 grep -E $v_str 'commit-[0-9a-f]{40}'