Slight UI improvements in 1996/gandalf/try.sh

Rather than showing something like:

    Showing diff between 'cmd' and 'cmd':
    Press any key to run: diff ...

it now shows instead (for example):

    $ diff hatcat.txt cathat.txt (diff between 'hatcat' and './cathat'):
    Press any key to continue:

The reason it's two lines is because having it on one line makes it a
kind long line. Probably not an issue with modern systems but I have
tried to keep the lines close to 80 columns and not doing it this way
would make it almost 90.

The script now has -C 1 used to show context. This way the file names
are shown in the output to help distinguish the files being compared. Of
course it might be possible to diff the command outputs themselves but
this works better because it will show the files that are the same
(when they are) rather than '.. and - are identical'.
This commit is contained in:
Cody Boone Ferguson committed 2024-01-24 05:34:40 -08:00
1 parent bff24da897
commit af05d9dac1
1 file changed
+12 -19
+12 -19
View File
@@ -41,13 +41,14 @@ trap 'rm -f hatcat.txt cathat.txt hatcat2.txt cathat2.txt hatcat3.txt cathat3.tx
show_diff()
{
if [[ "$#" -ne 2 ]]; then
if [[ "$#" -ne 3 ]]; then
echo "$0: show_diff expects two args, got: $#" 1>&2
exit 1
fi
read -r -n 1 -p "Press any key to run: diff $1 $2: "
echo "$ diff $1 $2 ($3): " 1>&2
read -r -n 1 -p "Press any key to continue: "
echo 1>&2
diff "$1" "$2" && echo "$1 and $2 are identical"
diff -C 1 "$1" "$2" && echo "$1 and $2 are identical"
echo 1>&2
}
@@ -72,8 +73,7 @@ echo 1>&2
cathat | tee cathat.txt
echo 1>&2
echo "Showing diff between the above two commands, 'hatcat' and './cathat':" 1>&2
show_diff hatcat.txt cathat.txt
show_diff hatcat.txt cathat.txt "diff between 'hatcat' and './cathat'"
read -r -n 1 -p "Press any key to run: ./hatcat | tee hatcat2.txt: "
echo 1>&2
@@ -83,8 +83,7 @@ read -r -n 1 -p "Press any key to run: ./cathat | tee cathat2.txt: "
echo 1>&2
./cathat | tee cathat2.txt
echo "Showing diff between running 'hatcat' and './hatcat':" 1>&2
show_diff hatcat.txt hatcat2.txt
show_diff hatcat.txt hatcat2.txt "diff between 'hatcat' and './hatcat'"
read -r -n 1 -p "Press any key to run: \$(pwd)/cathat | tee cathat3.txt: "
echo 1>&2
@@ -94,23 +93,17 @@ read -r -n 1 -p "Press any key to run: \$(pwd)/hatcat | tee hatcat3.txt: "
echo 1>&2
"$(pwd)"/hatcat | tee hatcat3.txt
echo "Showing diff between running './hatcat' and './cathat':" 1>&2
show_diff hatcat2.txt cathat2.txt
show_diff hatcat2.txt cathat2.txt "diff between './hatcat' and './cathat'"
echo "Showing diff between running '\$(pwd)/hatcat' and '\$(pwd)/cathat':" 1>&2
show_diff hatcat3.txt cathat3.txt
show_diff hatcat3.txt cathat3.txt "diff between '\$(pwd)/hatcat' and '\$(pwd)/cathat'"
echo "Showing diff between running '\$(pwd)/hatcat' and 'hatcat':" 1>&2
show_diff hatcat3.txt hatcat.txt
show_diff hatcat3.txt hatcat.txt "diff between '\$(pwd)/hatcat' and 'hatcat'"
echo "Showing diff between running '\$(pwd)/hatcat' and './hatcat':" 1>&2
show_diff hatcat3.txt hatcat2.txt
show_diff hatcat3.txt hatcat2.txt "diff between '\$(pwd)/hatcat' and './hatcat'"
echo "Showing diff between running '\$(pwd)/cathat' and 'cathat':" 1>&2
show_diff cathat3.txt cathat.txt
show_diff cathat3.txt cathat.txt "diff between \$(pwd)/cathat' and 'cathat'"
echo "Showing diff between running '\$(pwd)/cathat' and './cathat':" 1>&2
show_diff cathat3.txt cathat2.txt
show_diff cathat3.txt cathat2.txt "diff between '\$(pwd)/cathat' and './cathat'"
# remove temporary files
rm -f hatcat.txt cathat.txt hatcat2.txt cathat2.txt hatcat3.txt cathat3.txt