mdisk: Avoid delay when mounting disks with a `/.dontsleep/` directory
[sunny256-utils.git] / git-store-dirs
blobefe506475ba571a12a35b6542c6c123255402117
1 #!/bin/sh
3 #==============================================================================
4 # git-store-dirs
5 # File ID: 8853c3a0-6be6-11df-8fcb-90e6ba3022ac
7 # Store a list of all directories to $dirfile to be able to restore empty
8 # directories. The list is \0-separated in case there are some directory names
9 # containing (ugh) \n. Use git-restore-dirs(1) to recreate directories.
11 # Author: Øyvind A. Holm <sunny@sunbase.org>
12 # License: GNU General Public License version 2 or later.
13 #==============================================================================
15 progname=git-store-dirs
16 VERSION=0.3.0
18 opt_help=0
19 opt_local=0
20 opt_quiet=0
21 opt_verbose=0
22 while test -n "$1"; do
23 case "$1" in
24 -h|--help) opt_help=1; shift ;;
25 -l|--local) opt_local=1; shift ;;
26 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
27 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
28 --version) echo $progname $VERSION; exit 0 ;;
29 --) shift; break ;;
31 if printf '%s\n' "$1" | grep -q ^-; then
32 echo "$progname: $1: Unknown option" >&2
33 exit 1
34 else
35 break
37 break ;;
38 esac
39 done
40 opt_verbose=$(($opt_verbose - $opt_quiet))
42 dirfile=.emptydirs
44 if test "$opt_help" = "1"; then
45 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
46 cat <<END
48 Store a list of all directories to $dirfile to be able to restore empty
49 directories. The list is \\0-separated in case there are some directory
50 names containing (ugh) \\n. Use git-restore-dirs(1) to recreate
51 directories.
53 Usage: $progname [options]
55 Options:
57 -h, --help
58 Show this help.
59 -l, --local
60 Create $dirfile in the current subdirectory.
61 -q, --quiet
62 Be more quiet. Can be repeated to increase silence.
63 -v, --verbose
64 Increase level of verbosity. Can be repeated.
65 --version
66 Print version information.
68 END
69 exit 0
72 if test "$opt_local" != "1"; then
73 test -d .git/. || {
74 echo -n "$progname: Has to be run from the toplevel " >&2
75 echo of the working tree >&2
76 exit 1
79 find . -type d -empty -print0 |
80 grep -E -v -z '/\.git(/|$)' |
81 LC_ALL=C sort -z >$dirfile
82 test "$(cat $dirfile)" = "" &&
84 git reset $dirfile
85 rm $dirfile
86 echo "$0: No empty directories found, deleting $dirfile" >&2
87 ) || git add $dirfile
89 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :