Skip to content

Commit

Permalink
lib: Address shellcheck warnings and format with shfmt
Browse files Browse the repository at this point in the history
`shfmt -w -s -i 4 -ci -bn -sr .`
  • Loading branch information
echoix committed Nov 17, 2024
1 parent 5b1e1b4 commit d4fcd17
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 101 deletions.
44 changes: 22 additions & 22 deletions lib/init/grass-xterm-mac
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
# -William Kyngesburye

# just in case accidentally called on another system
SYSTEMOSX=`uname -s | grep "Darwin"`
SYSTEMOSX=$(uname -s | grep "Darwin")

if [ "$SYSTEMOSX" ] ; then
if [ "$SYSTEMOSX" ]; then
# manually transfer the necessary env vars
TMPSCRIPT="/tmp/grassxterm_$$"
(
cat <<-EOF
cat <<- EOF
#!/bin/sh
DISPLAY="$DISPLAY"
PATH="$PATH"
Expand All @@ -25,32 +25,32 @@ if [ "$SYSTEMOSX" ] ; then
export DISPLAY PATH GIS_LOCK GISRC GISBASE GRASS_VERSION GRASS_PAGER DYLD_LIBRARY_PATH GRASS_LD_LIBRARY_PATH GRASS_HTML_BROWSER GRASS_HTML_BROWSER_MACOSX
EOF

if [ "$GRASS_ADDON_PATH" ] ; then
echo "GRASS_ADDON_PATH=\"$GRASS_ADDON_PATH\""
echo "export GRASS_ADDON_PATH"
fi
if [ "$GRASS_ADDON_PATH" ]; then
echo "GRASS_ADDON_PATH=\"$GRASS_ADDON_PATH\""
echo "export GRASS_ADDON_PATH"
fi

if [ -z "$MANPATH" ] ; then
echo "MANPATH=\"$GISBASE/docs/man:`manpath`\""
else
echo "MANPATH=\"$GISBASE/docs/man:$MANPATH\""
fi
echo "export MANPATH"
if [ -z "$MANPATH" ]; then
echo "MANPATH=\"$GISBASE/docs/man:$(manpath)\""
else
echo "MANPATH=\"$GISBASE/docs/man:$MANPATH\""
fi
echo "export MANPATH"

# get command, ignore all other xterm flags
while true ; do
if [ "$1" = "-e" ] ; then break ; fi
shift
done
shift
# and add it to end of script
echo "$@"
# get command, ignore all other xterm flags
while true; do
if [ "$1" = "-e" ]; then break; fi
shift
done
shift
# and add it to end of script
echo "$@"
) > "$TMPSCRIPT.sh"
chmod +x "$TMPSCRIPT.sh"

# execute
# save current active app/window, return to it when script finishes.
osascript - <<EOF
osascript - << EOF
--tell application "System Events"
-- set save_app to item 1 of (get name of processes whose frontmost is true)
--end tell
Expand Down
2 changes: 1 addition & 1 deletion lib/init/grass.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

trap "echo 'User break!' ; exit" 2 3 9 15

if [ -z "$GRASS_PYTHON" ] ; then
if [ -z "$GRASS_PYTHON" ]; then
GRASS_PYTHON=python3
fi
export GRASS_PYTHON
Expand Down
12 changes: 6 additions & 6 deletions lib/init/html_browser_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
# For html files, when using app path method, open still wants to open the
# file in the system default browser, so we're left with signatures-only.

if [ ! "$GRASS_HTML_BROWSER_MACOSX" ] ; then
# default to Help Viewer
GRASS_HTML_BROWSER_MACOSX="-b com.apple.helpviewer"
if [ ! "$GRASS_HTML_BROWSER_MACOSX" ]; then
# default to Help Viewer
GRASS_HTML_BROWSER_MACOSX="-b com.apple.helpviewer"
fi

if [ "`echo \"$1\" | grep 'https\?://'`" ] && [ "$GRASS_HTML_BROWSER_MACOSX" = "-b com.apple.helpviewer" ] ; then
open "$1"
if [ "$(echo \""$1"\" | grep 'https\?://')" ] && [ "$GRASS_HTML_BROWSER_MACOSX" = "-b com.apple.helpviewer" ]; then
open "$1"
else
open $GRASS_HTML_BROWSER_MACOSX "$1"
open "$GRASS_HTML_BROWSER_MACOSX" "$1"
fi
87 changes: 66 additions & 21 deletions lib/vector/dglib/examples/rtest01.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,71 +15,116 @@
rm -f A B A.txt B.txt

echo "create a version-1 digraph and save it to 'A'"
(./cr_large_graph -g A > /dev/null) || (echo "error"; return 1) || exit 1
(./cr_large_graph -g A > /dev/null) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "read 'A'; unflatten ; flatten back again and save it to 'B'"
(./unflatten -g A -o B > /dev/null) || (echo "error"; return 1) || exit 1
(./unflatten -g A -o B > /dev/null) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "convert 'A' to 'A.txt'"
(./view -g A > A.txt) || (echo "error"; return 1) || exit 1
(./view -g A > A.txt) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "convert 'B' to 'B.txt'"
(./view -g B > B.txt) || (echo "error"; return 1) || exit 1
(./view -g B > B.txt) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "compare 'A.txt' with 'B.txt'"
(diff -q A.txt B.txt && \
echo "'A.txt' and 'B.txt' are identical") ||
(echo "'A.txt' and 'B.txt' differ"; exit 1) || exit 1
(diff -q A.txt B.txt \
&& echo "'A.txt' and 'B.txt' are identical") \
|| (
echo "'A.txt' and 'B.txt' differ"
exit 1
) || exit 1

rm -f A B A.txt B.txt

echo "create a version-2 digraph and save it to 'A'"
(./cr_large_graph -g A -v 2 > /dev/null) || (echo "error"; return 1) || exit 1
(./cr_large_graph -g A -v 2 > /dev/null) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "read 'A'; unflatten ; flatten back again and save it to 'B'"
(./unflatten -g A -o B > /dev/null) || (echo "error"; return 1) || exit 1
(./unflatten -g A -o B > /dev/null) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "convert 'A' to 'A.txt'"
(./view -g A > A.txt) || (echo "error"; return 1) || exit 1
(./view -g A > A.txt) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "convert 'B' to 'B.txt'"
(./view -g B > B.txt) || (echo "error"; return 1) || exit 1
(./view -g B > B.txt) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "compare 'A.txt' with 'B.txt'"
(diff -q A.txt B.txt && \
echo "'A.txt' and 'B.txt' are identical") ||
(echo "'A.txt' and 'B.txt' differ"; exit 1) || exit 1
(diff -q A.txt B.txt \
&& echo "'A.txt' and 'B.txt' are identical") \
|| (
echo "'A.txt' and 'B.txt' differ"
exit 1
) || exit 1

rm -f A B A.txt B.txt

echo "create a version-3 graph and save it to 'A'"
(./cr_large_graph -g A -v 2 > /dev/null) || (echo "error"; return 1) || exit 1
(./cr_large_graph -g A -v 2 > /dev/null) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "read 'A'; unflatten ; flatten back again and save it to 'B'"
(./unflatten -g A -o B > /dev/null) || (echo "error"; return 1) || exit 1
(./unflatten -g A -o B > /dev/null) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "convert 'A' to 'A.txt'"
(./view -g A > A.txt) || (echo "error"; return 1) || exit 1
(./view -g A > A.txt) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "convert 'B' to 'B.txt'"
(./view -g B > B.txt) || (echo "error"; return 1) || exit 1
(./view -g B > B.txt) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "compare 'A.txt' with 'B.txt'"
(diff -q A.txt B.txt && \
echo "'A.txt' and 'B.txt' are identical") ||
(echo "'A.txt' and 'B.txt' differ"; exit 1) || exit 1
(diff -q A.txt B.txt \
&& echo "'A.txt' and 'B.txt' are identical") \
|| (
echo "'A.txt' and 'B.txt' differ"
exit 1
) || exit 1

rm -f A B A.txt B.txt

Expand Down
29 changes: 22 additions & 7 deletions lib/vector/dglib/examples/rtest02.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,38 @@
rm -f A A.txt B B.txt

echo "create a large graph and save it to 'A'"
(./cr_large_graph -g A > /dev/null) || (echo "error"; return 1) || exit 1
(./cr_large_graph -g A > /dev/null) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "convert 'A' to 'A.txt'"
(./view -g A > A.txt) || (echo "error"; return 1) || exit 1
(./view -g A > A.txt) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "import 'A.txt' to 'B'"
(./parse -i A.txt -o B) || (echo "error"; return 1) || exit 1
(./parse -i A.txt -o B) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "convert 'B' to 'B.txt'"
(./view -g B > B.txt) || (echo "error"; return 1) || exit 1
(./view -g B > B.txt) || (
echo "error"
return 1
) || exit 1
echo "done"

echo "compare 'A.txt' with 'B.txt'"
(diff -q A.txt B.txt && \
echo "'A.txt' and 'B.txt' are identical") ||
(echo "'A.txt' and 'B.txt' differ"; exit 1) || exit 1
(diff -q A.txt B.txt \
&& echo "'A.txt' and 'B.txt' are identical") \
|| (
echo "'A.txt' and 'B.txt' differ"
exit 1
) || exit 1
exit 0
Loading

0 comments on commit d4fcd17

Please sign in to comment.