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

+2 -27
View File
@@ -1,35 +1,10 @@
#
# sort with: bin/sgi.sh
._.DS_Store
2024
.DS_Store
/NOTES
/archive/historic/1984
/archive/historic/1985
/archive/historic/1986
/archive/historic/1987
/archive/historic/1988
/archive/historic/1989
/archive/historic/1990
/archive/historic/1991
/archive/historic/1992
/archive/historic/1993
/archive/historic/1994
/archive/historic/1995
/archive/historic/1996
/archive/historic/1998
/archive/historic/2000
/archive/historic/2001
/archive/historic/2004
/archive/historic/2005
/archive/historic/2006
/archive/historic/2011
/archive/historic/2012
/archive/historic/2013
/archive/historic/2014
/archive/historic/2015
/archive/historic/2018
/archive/historic/2019
/archive/historic/2020
/archive/historic/[12][0-9][0-9][0-9]
.auth.json
author_wins.csv
author_wins.numbers
+5 -5
View File
@@ -8,14 +8,14 @@ indent
indent.c
indent.o
prog.orig
src/config.log
src/config.status
src/hibachi
src/hibachi.c
src/makefile
src-alt/config.log
src-alt/config.status
src-alt/hibachi
src-alt/hibachi.alt
src-alt/hibachi.alt.c
src-alt/makefile
src/config.log
src/config.status
src/hibachi
src/hibachi.c
src/makefile
+2 -2
View File
@@ -9,7 +9,7 @@ mynx.alt
mynx.alt2
mynx.orig
prog.orig
source/config.*
source/makefile
source-alt/config.*
source-alt/makefile
source/config.*
source/makefile
-1
View File
@@ -1,4 +1,3 @@
#
# sort with: ../../bin/sgi.sh
*.dSYM
+1 -1
View File
@@ -1,7 +1,7 @@
#
# sort with: ../../bin/sgi.sh
1.txt
*.dSYM
1.txt
2.txt
dlowe
dlowe.orig
+2 -2
View File
@@ -2,11 +2,11 @@
# sort with: ../../bin/sgi.sh
*.dSYM
*.mid
!cvikl.mid
!entertainer.mid
indent
indent.c
indent.o
prog
prog.alt
prog.orig
!cvikl.mid
!entertainer.mid
+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