fix bin/sort.gitignore.sh and bin/sgi.sh

We added ._.DS_Store to `.gitignore`, and generalized the `/archive/historic/`
year sub-directories into a single pattern line.

We fix `bin/sgi.sh` to properly sort, canonically, `.gitignore` files
including `._.DS_Store` lines.  The tool now stories stdin content
into a temporary file, then prints 6 classes of files from the
temporary file to stdout.

Changed `bin/sgi.sh` VERSION from "1.1.3 2024-08-18"
to "1.2 2024-09-05".

Fixed a bug in `bin/sort.gitignore.sh` that prevented it from
finding the `bin/sgi.sh` tool.

Changed `bin/sort.gitignore.sh` VERSION from "1.1.8 2024-07-28"
to "1.2 2024-09-05".

Performed `make sort_gitignore` to test the above under macOS.

NOTE: The above canonically sorted:

- 2004/hibachi/.gitignore
- 2005/mynx/.gitignore
- 2011/vik/.gitignore
- 2013/dlowe/.gitignore
- 2020/otterness/.gitignore
This commit is contained in:
Landon Curt Noll committed 2024-09-05 16:56:47 -07:00
1 parent a6c34f57cf
commit 69bef8add2
8 files changed
+80 -51

No files matched your search

+64 -9
View File
@@ -1,11 +1,16 @@
#!/usr/bin/env bash
#
# sgi.sh - sort .gitignore content from stdin to stdout
# sgi.sh - sort .gitignore canonically from stdin to stdout
#
# We sort with lines starting with # first.
# We sort with lines starting with * second.
# We sort with lines that do not start with [#!*] third.
# We sort with lines starting with ! fourth.
# We canonicalize .gitignore lines as follows:
#
# We print lines # in the order they appear, 1st.
# We dictionary sort with lines starting with * 2nd.
# We dictionary sort with lines starting with ! 3rd.
# We dictionary sort with lines starting with / 4th.
# We dictionary sort all other lines 5th.
#
# For each step past the 1st step, we remove duplicate lines.
#
# Example usage in vim with a keyboard macro <escape>f:
#
@@ -47,8 +52,58 @@
# Share and enjoy! :-)
# sort .gitignore content on stdin to stdout
# load stdin into a temporary gitignore file
#
sed -e '/^#/s/.*/0 &/' -e '/^*/s/.*/1 &/' -e '/^[^01*!]/s/.*/2 &/' -e '/^!/s/.*/3 &/' |
LC_ALL=C sort -u -k 1n -k 2d |
sed 's/[0123] //'
export VERSION="1.2 2024-09-05"
NAME=$(basename "$0")
export NAME
export TMP_GITIGNORE=".tmp.$NAME.GITIGNORE.$$.tmp"
trap 'rm -f $TMP_GITIGNORE; exit' 0 1 2 3 15
rm -f "$TMP_GITIGNORE"
if [[ -e $TMP_GITIGNORE ]]; then
echo "$0: ERROR: cannot remove temporary gitignore file: $TMP_GITIGNORE" 1>&2
exit 10
fi
cat > "$TMP_GITIGNORE"
if [[ ! -e $TMP_GITIGNORE ]]; then
echo "$0: ERROR: cannot create temporary gitignore file: $TMP_GITIGNORE" 1>&2
exit 11
fi
# step 0: print .gitignore comment lines in order
#
grep '^#' "$TMP_GITIGNORE"
# print unique lines from the following 5 steps to stdout
#
# These 5 types of .gitignore lines are printed in
# step order as part of our .gitignore canonization.
#
{
# step 1: print * lines, sorted by dictionary
#
grep '^\*' "$TMP_GITIGNORE" | LC_ALL=C sort -d
# step 2: print ! lines, sorted by dictionary
#
grep '^!' "$TMP_GITIGNORE" | LC_ALL=C sort -d
# step 3: print . lines, sorted by dictionary
#
grep '^\.' "$TMP_GITIGNORE" | LC_ALL=C sort -d
# step 4: print / lines, sorted by dictionary
#
grep '^/' "$TMP_GITIGNORE" | LC_ALL=C sort -d
# step 5: print all other lines, sorted by dictionary
#
grep '^[^#*!./]' "$TMP_GITIGNORE" | LC_ALL=C sort -d
} | uniq
# All Done!!! All Done!!! -- Jessica Noll, Age 2
#
exit 0
+4 -4
View File
@@ -101,7 +101,7 @@ shopt -s globstar # enable ** to match all files and zero or more directories an
# set variables referenced in the usage message
#
export VERSION="1.1.8 2024-07-28"
export VERSION="1.2 2024-09-05"
NAME=$(basename "$0")
export NAME
export V_FLAG=0
@@ -272,15 +272,15 @@ export BIN_DIR="bin"
# verify that the bin/sgi.sh tool is executable
#
export SGI_TOOL="$BIN_DIR/sgi.sh"
if [[ ! -e $SGI_TOOL.sh ]]; then
if [[ ! -e $SGI_TOOL ]]; then
echo "$0: ERROR: bin/sgi.sh does not exist: $SGI_TOOL.sh" 1>&2
exit 5
fi
if [[ ! -f $SGI_TOOL.sh ]]; then
if [[ ! -f $SGI_TOOL ]]; then
echo "$0: ERROR: bin/sgi.sh is not a regular file: $SGI_TOOL.sh" 1>&2
exit 5
fi
if [[ ! -x $SGI_TOOL.sh ]]; then
if [[ ! -x $SGI_TOOL ]]; then
echo "$0: ERROR: bin/sgi.sh is not an executable file: $SGI_TOOL.sh" 1>&2
exit 5
fi