f2b768fc206e94c96ceaafb9587bca569db1fe0f
[feisty_meow.git] / scripts / opensim / list_sims.sh
1 #!/bin/bash
2
3 # we guess at some nice values to use in the list.  if these are too small, we'll
4 # adjust them before printing anything.
5 max_name=14
6 max_port=10
7 max_location=12
8
9 # column headings, and a placeholder to be fixed later.
10 names=(Region hold)
11 numbers=(Port hold)
12 locats=('Grid Coords' hold)
13
14 # run through and get the data first...
15 for region_ini in $HOME/opensim/bin/Regions/*; do
16   name="$(grep "\[.*\]" <"$region_ini" | tr -d \[\] | sed -e 's/[\r\n]//g' )"
17   if [ ${#name} -gt $max_name ]; then max_name=${#name}; fi
18   names[${#names[*]}]=$name
19   port="$(grep "InternalPort" <"$region_ini" | sed -e 's/InternalPort *= *//' -e 's/[\r\n]//g' )"
20   if [ ${#port} -gt $max_port ]; then max_port=${#port}; fi
21   numbers[${#numbers[*]}]=$port
22   location="$(grep "Location" <"$region_ini" | sed -e 's/Location *= *//' -e 's/[\r\n]//g' )"
23   if [ ${#location} -gt $max_location ]; then max_location=${#location}; fi
24   locats[${#locats[*]}]=$location
25 done
26
27 dash=
28 while [ ${#dash} -lt $max_name ]; do dash+='='; done
29 names[1]=$dash
30 dash=
31 while [ ${#dash} -lt $max_port ]; do dash+='='; done
32 numbers[1]=$dash
33 dash=
34 while [ ${#dash} -lt $max_location ]; do dash+='='; done
35 locats[1]=$dash
36
37 #echo names list is ${names[*]}
38 #echo ports list is ${numbers[*]}
39 #echo locations list is ${locats[*]}
40
41 # now print the data in a pleasant fashion...
42 indy=0
43 for region_ini in header line $HOME/opensim/bin/Regions/*; do
44   # indy is a zero-based array index.
45   name=${names[$indy]}
46   port=${numbers[$indy]}
47   location=${locats[$indy]}
48   while [ ${#name} -lt $max_name ]; do name+=' '; done
49   while [ ${#port} -lt $max_port ]; do port+=' '; done
50   while [ ${#location} -lt $max_location ]; do location+=' '; done
51   if [ "$region_ini" == "header" ]; then
52     region_ini='Region Config File'
53   elif [ "$region_ini" == "line" ]; then
54     region_ini='===================='
55   fi
56   echo "$name $port $location $(basename "$region_ini")";
57   ((indy++))
58 done
59
60 exit 0
61