ly/Makefile: Sort variables
[sunny256-utils.git] / ga-tree
blob7c9e46c214ca2028d4ce6dcb9ff5a1fd37792ff9
1 #!/usr/bin/env bash
3 #=======================================================================
4 # ga-tree
5 # File ID: 9aa77afc-3550-11e2-9816-00c0a8deee11
7 # Tree view of a subdirectory structure, optimised for git-annex.
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
13 progname=ga-tree
14 VERSION=0.3.0
16 ARGS="$(getopt -o "\
22 " -l "\
23 colour,\
24 directories,\
25 help,\
26 quiet,\
27 verbose,\
28 version,\
29 " -n "$progname" -- "$@")"
30 test "$?" = "0" || exit 1
31 eval set -- "$ARGS"
33 opt_colour=0
34 opt_directories=0
35 opt_help=0
36 opt_quiet=0
37 opt_verbose=0
38 while :; do
39 case "$1" in
40 -C|--colour) opt_colour=1; shift ;;
41 -d|--directories) opt_directories=1; shift ;;
42 -h|--help) opt_help=1; shift ;;
43 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
44 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
45 --version) echo $progname $VERSION; exit 0 ;;
46 --) shift; break ;;
47 *) echo $progname: Internal error >&2; exit 1 ;;
48 esac
49 done
50 opt_verbose=$(($opt_verbose - $opt_quiet))
52 if test "$opt_help" = "1"; then
53 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
54 cat <<END
56 Tree view of a subdirectory structure, optimised for git-annex.
57 Arguments and options after " -- " are delivered to tree(1).
59 Usage: $progname [options] [ -- OPTIONS_TO_tree(1) ]
61 Options:
63 -C, --colour
64 Use colours.
65 -d, --directories
66 Only list directories.
67 -h, --help
68 Show this help.
69 -q, --quiet
70 Be more quiet. Can be repeated to increase silence.
71 -v, --verbose
72 Increase level of verbosity. Can be repeated.
73 --version
74 Print version information.
76 END
77 exit 0
80 if test "$opt_colour" = "1"; then
81 colour_str=' -C'
82 else
83 colour_str=''
86 if test "$opt_directories" = "1"; then
87 directories_str=' -d'
88 else
89 directories_str=''
92 tree --charset UTF-8$colour_str$directories_str -N "$@" |
93 perl -pe 's/^(.*)( -> \.\..*)/$1/' |
94 less -r