Commit 135c6d05 authored by mattijs's avatar mattijs
Browse files

colouring; indentation

parent 805b45e8
......@@ -57,15 +57,15 @@ lockDir=$HOME/.wmakeScheduler
# count the total number of slots available and exit
if [ "$1" = "-count" ]
then
expr $(
for slotGroup in $WM_HOSTS
do
n=${slotGroup##*:}
[ "$n" = "${slotGroup%%:*}" ] && n=1 # missing ':'
echo "+ ${n:-1}"
done
)
exit 0
expr $(
for slotGroup in $WM_HOSTS
do
n=${slotGroup##*:}
[ "$n" = "${slotGroup%%:*}" ] && n=1 # missing ':'
echo "+ ${n:-1}"
done
)
exit 0
fi
# where to source WM_PROJECT settings in a remote shell
......@@ -76,11 +76,11 @@ fi
sourceFoam=false # fallback command
case $SHELL in
*/csh | */tcsh ) # [t]csh vs bash|ksh|sh
shellRc=cshrc
;;
shellRc=cshrc
;;
*)
shellRc=bashrc
;;
shellRc=bashrc
;;
esac
# check ~/.$WM_PROJECT/$WM_PROJECT_VERSION/
......@@ -88,18 +88,18 @@ esac
# check <installedProject>/etc/
if [ "$WM_PROJECT" ]
then
for i in \
$HOME/.$WM_PROJECT/$WM_PROJECT_VERSION \
$HOME/.$WM_PROJECT \
$WM_PROJECT_DIR/etc \
;
do
if [ -f "$i/$shellRc" ]
then
sourceFoam="$i/$shellRc"
break
fi
done
for i in \
$HOME/.$WM_PROJECT/$WM_PROJECT_VERSION \
$HOME/.$WM_PROJECT \
$WM_PROJECT_DIR/etc \
;
do
if [ -f "$i/$shellRc" ]
then
sourceFoam="$i/$shellRc"
break
fi
done
fi
# Construct test string for remote execution.
......@@ -107,18 +107,18 @@ fi
# attempt to preserve the installation directory 'FOAM_INST_DIR'
case $sourceFoam in
*/bashrc)
if [ "$FOAM_INST_DIR" ]
then
sourceFoam='[ "$WM_PROJECT" ] || '"FOAM_INST_DIR=$FOAM_INST_DIR . $sourceFoam"
else
sourceFoam='[ "$WM_PROJECT" ] || '". $sourceFoam"
fi
;;
if [ "$FOAM_INST_DIR" ]
then
sourceFoam='[ "$WM_PROJECT" ] || '"FOAM_INST_DIR=$FOAM_INST_DIR . $sourceFoam"
else
sourceFoam='[ "$WM_PROJECT" ] || '". $sourceFoam"
fi
;;
*/cshrc)
# TODO: csh equivalent to bash code (preserving FOAM_INST_DIR)
sourceFoam='if ( ! $?WM_PROJECT ) source '"$sourceFoam"
;;
# TODO: csh equivalent to bash code (preserving FOAM_INST_DIR)
sourceFoam='if ( ! $?WM_PROJECT ) source '"$sourceFoam"
;;
esac
# quote double-quotes for remote command line
......@@ -132,8 +132,8 @@ declare colourList
nColours=0
for col in $WM_COLOURS
do
colourList[$nColours]=$col
((nColours = $nColours + 1))
colourList[$nColours]=$col
((nColours = $nColours + 1))
done
# Bashism: make pipe fail early.
......@@ -147,19 +147,19 @@ set -o pipefail
#
colourPipe()
{
if [ "$1" ]
then
(
while read line
do
setterm -foreground $1
echo "$line"
done
setterm -foreground default
)
else
cat
fi
if [ "$1" ]
then
(
while read line
do
setterm -foreground $1
echo "$line"
done
setterm -foreground default
)
else
cat
fi
}
......@@ -167,56 +167,59 @@ colourIndex=0
while :
do
for slotGroup in $WM_HOSTS
do
# split 'host:N', but catch 'host:' and 'host' too
host=${slotGroup%%:*}
n=${slotGroup##*:}
[ "$n" = "$host" ] && n=1 # missing ':'
: ${n:=1}
i=0
while [ "$i" -lt "$n" ]
do
lockFile="$lockDir/$host:$i"
if lockfile -r0 "$lockFile" 2>/dev/null
then
if [ "$nColours" -gt 0 ]
for slotGroup in $WM_HOSTS
do
# split 'host:N', but catch 'host:' and 'host' too
host=${slotGroup%%:*}
n=${slotGroup##*:}
[ "$n" = "$host" ] && n=1 # missing ':'
: ${n:=1}
i=0
while [ "$i" -lt "$n" ]
do
lockFile="$lockDir/$host:$i"
if lockfile -r0 "$lockFile" 2>/dev/null
then
# Set colour and index to next colour
colour="${colourList[$colourIndex]}"
colourIndex=$(expr $colourIndex + 1)
[ "$colourIndex" -lt "$nColours" ] || colourIndex=0
if [ "$host" = "$HOST" ]; then
eval $* 2>&1 | colourPipe "$colour"
else
ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1 | colourPipe "$colour"
fi
retval=$?
else
if [ "$host" = "$HOST" ]; then
eval $* 2>&1
else
ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1
fi
retval=$?
if [ "$nColours" -gt 0 ]
then
# Set colour
colour="${colourList[$colourIndex]}"
if [ "$host" = "$HOST" ]; then
eval $* 2>&1 | colourPipe "$colour"
else
ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1 | colourPipe "$colour"
fi
retval=$?
else
if [ "$host" = "$HOST" ]; then
eval $* 2>&1
else
ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1
fi
retval=$?
fi
# Release lock
rm -f "$lockFile" 2>/dev/null
exit $retval
fi
i=$(expr $i + 1)
# Release lock
rm -f "$lockFile" 2>/dev/null
exit $retval
fi
i=$(expr $i + 1)
done
done
# Did not find any free slots. Rest a bit.
sleep 1
# Cycle through colours. Note: outside lock clause!
colourIndex=$(expr $colourIndex + 1)
[ "$colourIndex" -lt "$nColours" ] || colourIndex=0
done
done
# Did not find any free slots. Rest a bit.
sleep 1
done
if [ "$nColours" -gt 0 ]
then
setterm -foreground default
setterm -foreground default
fi
#------------------------------------------------------------------------------
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment