diff --git a/.gitignore b/.gitignore index 58ffea6c6..1e2d25bb9 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/2004/hibachi/.gitignore b/2004/hibachi/.gitignore index 46f0de5a3..c34844d8d 100644 --- a/2004/hibachi/.gitignore +++ b/2004/hibachi/.gitignore @@ -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 diff --git a/2005/mynx/.gitignore b/2005/mynx/.gitignore index c11967e82..626fbbe43 100644 --- a/2005/mynx/.gitignore +++ b/2005/mynx/.gitignore @@ -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 diff --git a/2011/vik/.gitignore b/2011/vik/.gitignore index 172ea5777..674828636 100644 --- a/2011/vik/.gitignore +++ b/2011/vik/.gitignore @@ -1,4 +1,3 @@ - # # sort with: ../../bin/sgi.sh *.dSYM diff --git a/2013/dlowe/.gitignore b/2013/dlowe/.gitignore index 1331ecb95..4b9c47394 100644 --- a/2013/dlowe/.gitignore +++ b/2013/dlowe/.gitignore @@ -1,7 +1,7 @@ # # sort with: ../../bin/sgi.sh -1.txt *.dSYM +1.txt 2.txt dlowe dlowe.orig diff --git a/2020/otterness/.gitignore b/2020/otterness/.gitignore index 454f4b5d8..36aad4719 100644 --- a/2020/otterness/.gitignore +++ b/2020/otterness/.gitignore @@ -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 diff --git a/bin/sgi.sh b/bin/sgi.sh index 72b200152..9c4285833 100755 --- a/bin/sgi.sh +++ b/bin/sgi.sh @@ -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 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 diff --git a/bin/sort.gitignore.sh b/bin/sort.gitignore.sh index 87c095db8..c92476d13 100755 --- a/bin/sort.gitignore.sh +++ b/bin/sort.gitignore.sh @@ -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