From d5b0f3b2ef5070095a38d2905a999181e4c42b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Sun, 17 Nov 2024 03:28:08 +0000 Subject: [PATCH] macosx: Address shellcheck warnings and format with shfmt `shfmt -w -s -i 4 -ci -bn -sr .` --- macosx/app/build_gui_user_menu.sh | 86 ++++++++++--------- macosx/app/build_html_user_index.sh | 123 +++++++++++++--------------- macosx/app/python_wrapper | 26 +++--- 3 files changed, 113 insertions(+), 122 deletions(-) diff --git a/macosx/app/build_gui_user_menu.sh b/macosx/app/build_gui_user_menu.sh index e4bc6e7f250..713c5bcc457 100755 --- a/macosx/app/build_gui_user_menu.sh +++ b/macosx/app/build_gui_user_menu.sh @@ -11,7 +11,7 @@ # addon commands can't have spaces in them or sh for loop messes up. # may be my limited knowledge of sh scripting and there could be a way. -GRASS_MMVER=`cut -d . -f 1-2 "$GISBASE/etc/VERSIONNUMBER"` +GRASS_MMVER=$(cut -d . -f 1-2 "$GISBASE/etc/VERSIONNUMBER") BINDIR="$GISBASE_USER/Modules/bin" SCRIPTDIR="$GISBASE_USER/Modules/scripts" BINDIRG="$GISBASE_SYSTEM/Modules/bin" @@ -25,58 +25,56 @@ mkdir -p "$MENUDIR" echo "# generated by grass startup" > "$MENUDIR/xtnmenu.dat" # global addons: -if [ -d "$BINDIRG" ] ; then - cd "$BINDIRG" - CMDLISTG=`ls -1 2> /dev/null` +if [ -d "$BINDIRG" ]; then + cd "$BINDIRG" || exit + CMDLISTG=$(ls -1 2> /dev/null) else - CMDLISTG="" + CMDLISTG="" fi -if [ -d "$SCRIPTDIRG" ] ; then - cd "$SCRIPTDIRG" - CMDLISTG="$CMDLISTG"$'\n'"`ls -1 2> /dev/null`" +if [ -d "$SCRIPTDIRG" ]; then + cd "$SCRIPTDIRG" || exit + CMDLISTG="$CMDLISTG"$'\n'"$(ls -1 2> /dev/null)" fi -CMDLISTG=`echo "$CMDLISTG" | sort -u` +CMDLISTG=$(echo "$CMDLISTG" | sort -u) CMDGFOUND="" -if [ "$CMDLISTG" != "" ] ; then - for i in $CMDLISTG - do - if [ -f "$BINDIRG/$i" ] ; then - ftype="`file $BINDIRG/$i`" - else - ftype="`file $SCRIPTDIRG/$i`" - fi - if [ "`echo $ftype | grep 'Mach-O'`" ] || [ "`grep '#% *Module' $BINDIRG/$i 2> /dev/null`" ] || [ "`grep '#% *Module' $SCRIPTDIRG/$i 2> /dev/null`" ] ; then - echo "main:$i:$i:$i" >> "$MENUDIR/xtnmenu.dat" - CMDGFOUND="1" - fi - done +if [ "$CMDLISTG" != "" ]; then + for i in $CMDLISTG; do + if [ -f "$BINDIRG/$i" ]; then + ftype="$(file "$BINDIRG/$i")" + else + ftype="$(file "$SCRIPTDIRG/$i")" + fi + if [ "$(echo "$ftype" | grep 'Mach-O')" ] || [ "$(grep '#% *Module' "$BINDIRG/$i" 2> /dev/null)" ] || [ "$(grep '#% *Module' "$SCRIPTDIRG/$i" 2> /dev/null)" ]; then + echo "main:$i:$i:$i" >> "$MENUDIR/xtnmenu.dat" + CMDGFOUND="1" + fi + done fi # user addons: CMDFIRST="1" -cd "$BINDIR" -CMDLIST=`ls -1 2> /dev/null` -if [ -d "$SCRIPTDIR" ] ; then - cd "$SCRIPTDIR" - CMDLIST="$CMDLIST"$'\n'"`ls -1 2> /dev/null`" +cd "$BINDIR" || exit +CMDLIST=$(ls -1 2> /dev/null) +if [ -d "$SCRIPTDIR" ]; then + cd "$SCRIPTDIR" || exit + CMDLIST="$CMDLIST"$'\n'"$(ls -1 2> /dev/null)" fi -CMDLIST=`echo "$CMDLIST" | sort -u` +CMDLIST=$(echo "$CMDLIST" | sort -u) -if [ "$CMDLIST" != "" ] ; then - for i in $CMDLIST - do - if [ -f "$BINDIR/$i" ] ; then - ftype="`file $BINDIR/$i`" - else - ftype="`file $SCRIPTDIR/$i`" - fi - if [ "`echo $ftype | grep 'Mach-O'`" ] || [ "`grep '#% *Module' $BINDIR/$i 2> /dev/null`" ] || [ "`grep '#% *Module' $SCRIPTDIR/$i 2> /dev/null`" ] ; then - if [ "$CMDFIRST" ] && [ "$CMDGFOUND" ] ; then - echo "separator" >> "$MENUDIR/xtnmenu.dat" - CMDFIRST="" - fi - echo "main:$i:$i:$i" >> "$MENUDIR/xtnmenu.dat" - fi - done +if [ "$CMDLIST" != "" ]; then + for i in $CMDLIST; do + if [ -f "$BINDIR/$i" ]; then + ftype="$(file "$BINDIR/$i")" + else + ftype="$(file "$SCRIPTDIR/$i")" + fi + if [ "$(echo "$ftype" | grep 'Mach-O')" ] || [ "$(grep '#% *Module' "$BINDIR/$i" 2> /dev/null)" ] || [ "$(grep '#% *Module' "$SCRIPTDIR/$i" 2> /dev/null)" ]; then + if [ "$CMDFIRST" ] && [ "$CMDGFOUND" ]; then + echo "separator" >> "$MENUDIR/xtnmenu.dat" + CMDFIRST="" + fi + echo "main:$i:$i:$i" >> "$MENUDIR/xtnmenu.dat" + fi + done fi diff --git a/macosx/app/build_html_user_index.sh b/macosx/app/build_html_user_index.sh index 0dd7271f0b0..7ec3aa53bca 100755 --- a/macosx/app/build_html_user_index.sh +++ b/macosx/app/build_html_user_index.sh @@ -17,35 +17,34 @@ ############# nothing to configure below ############ # $1 is current path to GRASS.app/Contents/MacOS, defaults to /Applications -if [ "$1" != "" ] ; then - GISBASE=$1 +if [ "$1" != "" ]; then + GISBASE=$1 else - GISBASE="/Applications/GRASS-$GRASS_MMVER.app/Contents/MacOS" + GISBASE="/Applications/GRASS-$GRASS_MMVER.app/Contents/MacOS" fi -GRASS_MMVER=`cut -d . -f 1-2 "$GISBASE/etc/VERSIONNUMBER"` -GRASSVERSION=`cat "$GISBASE/etc/VERSIONNUMBER"` +GRASS_MMVER=$(cut -d . -f 1-2 "$GISBASE/etc/VERSIONNUMBER") +GRASSVERSION=$(cat "$GISBASE/etc/VERSIONNUMBER") HTMLDIR="$GISBASE_USER/Modules/docs/html" HTMLDIRG="$GISBASE_SYSTEM/Modules/docs/html" -write_html_header() -{ -# $1: filename -# $2: page title -# $3: is it main index +write_html_header() { + # $1: filename + # $2: page title + # $3: is it main index -echo " + echo "
Help Index | Full Index | Addon Index
" >> $1
-echo "© 2003-2008 GRASS Development Team
Help Index | Full Index | Addon Index
" >> "$1"
+ echo '© 2003-2008 GRASS Development Team