From 7525226fe2fdf9ea2461311c98aa820fddc39e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Sat, 2 Jul 2016 14:10:56 +0200 Subject: less bashisms in fluxbox-generate_menu still works with bash or zsh, but fish (now) complains about "cat << EOF" ... no "grep -q" BUG: 961 echo is troublesome POSIX doesn't know a "local" keyword BUG: 975 seems double comments ## aren't supported everywhere BUG: 1057 --- util/fluxbox-generate_menu.in | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/util/fluxbox-generate_menu.in b/util/fluxbox-generate_menu.in index d319098..b00db10 100755 --- a/util/fluxbox-generate_menu.in +++ b/util/fluxbox-generate_menu.in @@ -35,9 +35,11 @@ # - don't use id -u or $UID, use whoami # - getopts won't work on all platforms, but the config-file can # compensate for that. -# - OpenBSD and Solaris grep do not have the -m option +# - OpenBSD and Solaris grep do not have the -m or -q options # - various software like grep/sed/perl may be not present or not # the version you have. for example grep '\W' only works on gnu-grep. +# - echo can lack several flags (notably -n) and might default to absent -e +# In doubt, use printf # Keep this in mind, use bare basic defaults. # - Do _NOT_ suggest to use #!/bin/bash. Not everybody uses bash. # Non portable features like getopts in this script can be achieved in @@ -186,7 +188,6 @@ convertIcon(){ return 0; fi - local BASENAME BASENAME="${1##*/}" # make sure it is an icon by checking if it has an extension @@ -246,7 +247,7 @@ removePath(){ doSearchLoop(){ for ICONPATH in "$@"; do - ## $dnlamVERBOSE ": $ICONPATH" >> $ICONMAPPING + # $dnlamVERBOSE ": $ICONPATH" >> $ICONMAPPING [ -d "$ICONPATH" ] || continue #echo -n "." # # $dnlamVERBOSE ":: $ICONPATH/$temp_icon" >> $ICONMAPPING @@ -257,7 +258,7 @@ doSearchLoop(){ # remove extension iconNOext="${temp_icon%%.*}" [ -d "$ICONPATH" ] && for ICONEXT in .xpm .png .gif ; do - ## echo "::: $ICONPATH/$iconNOext$ICONEXT" >> $ICONMAPPING + # echo "::: $ICONPATH/$iconNOext$ICONEXT" >> $ICONMAPPING realpath=`find "$ICONPATH" -type f -name "$iconNOext$ICONEXT" | head -n 1` if [ -n "$realpath" ]; then echo $realpath @@ -345,7 +346,7 @@ searchForIcon(){ # echo "^.${entry_exec}.[[:space:]]*<.*/${icon_base}\....>" if [ -f "$entry_icon" ]; then # if icon exists and entry does not already exists, add it - if ! grep -q -m 1 "^.${execname}.[[:space:]]*<.*/${icon_base}\....>" $ICONMAPPING 2> /dev/null; then + if ! grep "^.${execname}.[[:space:]]*<.*/${icon_base}\....>" $ICONMAPPING > /dev/null 2>&1; then printf "\"${execname}\" \t <${entry_icon}>\n" >> $ICONMAPPING else : echo "# mapping already exists for ${execname}" >> $ICONMAPPING @@ -417,7 +418,7 @@ lookupIcon() { fi if [ -z "$iconString" ] && [ -z "$PARSING_DESKTOP" ] ; then - ## $dnlamVERBOSE "lookupIcon: Searching ... should only be needed for icons not gotten from *.desktop (manual-created ones): $execname" >&2 + # $dnlamVERBOSE "lookupIcon: Searching ... should only be needed for icons not gotten from *.desktop (manual-created ones): $execname" >&2 searchForIcon "$execname" "$execname" [ -n "$entry_icon" ] && iconString="<$entry_icon>" fi @@ -432,7 +433,7 @@ append() { iconString="`echo $* | grep -o '<.*>'`" # echo "iconString=$iconString" >&2 if [ -z "$iconString" ] && [ -z "$NO_ICON" ]; then - echo -n " $* " >> ${MENUFILENAME} + printf " $* " >> ${MENUFILENAME} # get the program name between '{}' from parameters execname="$*" execname=${execname#*\{} @@ -576,7 +577,7 @@ WHOAMI=`whoami` [ "$WHOAMI" = root ] && PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin # Check for Imlib2-support -if @pkgprefix@fluxbox@pkgsuffix@@EXEEXT@ -info 2> /dev/null | grep -q "^IMLIB"; then +if @pkgprefix@fluxbox@pkgsuffix@@EXEEXT@ -info 2> /dev/null | grep "^IMLIB" >/dev/null 2>&1; then PNG_ICONS="yes" else # better assume to assume "no" @@ -1473,7 +1474,7 @@ if [ -z "${INSTALL}" ] && [ -z "${NO_ICON}" ]; then checkDirs(){ #echo checkDirs: $* >&2 - local CHECKED_DIRS="" + CHECKED_DIRS="" for DIR in "$@"; do if [ -d "$DIR" ]; then # todo: should check if there are duplicates -- cgit v0.11.2