Showing 1 changed files with 36 additions and 11 deletions
+36 -11
.fgfs/fgfs_function
... ...
@@ -117,17 +117,42 @@ function fgfs () {
117 117
 ############ APPAREIL DANS FGADDON ?
118 118
             elif which sqlite3 > /dev/null 2>&1 \
119 119
             && test -r $FGADDON/fgaddon.db \
120
-            && test $(sqlite3 $FGADDON/fgaddon.db <<< "select count(file) from setxml where file is '${fgfs_arg}'") -eq 1; then
121
-                model=$(sqlite3 $FGADDON/fgaddon.db <<< "select name from aircrafts inner join setxml on aircrafts.id = setxml.variantof where setxml.file is '${fgfs_arg}'")
122
-                read -q "REPLY?download $model ? (y/N) "
123
-                if test -n "$REPLY" && test ${REPLY:l} = "y"; then
124
-                    svn co https://svn.code.sf.net/p/flightgear/fgaddon/trunk/Aircraft/$model $FGADDON/Aircraft/$model
125
-                    fgfs_args+=("--aircraft=$fgfs_arg")
126
-                    fgfs_args+=("--fg-aircraft=$FGADDON/Aircraft")
127
-                else
128
-                    echo "aircraft $fgfs_arg isn't installed"
129
-                    return
130
-                fi
120
+            && test $(sqlite3 $FGADDON/fgaddon.db <<< "select count(file) from setxml where file is '${fgfs_arg}'") -gt 0; then
121
+                local PS3='which aircraft ? (Ctrl-D to quit) '
122
+                local IFS=$'\n'
123
+                select ac in $(sqlite3 $FGADDON/fgaddon.db <<< "select distinct printf('%s [%s, %s]',
124
+                                                               aircrafts.name,
125
+                                                               hangars.name,
126
+                                                               date(aircrafts.date, 'unixepoch'))
127
+                                                 from aircrafts
128
+                                                 inner join setxml, hangars
129
+                                                 where
130
+                                                   aircrafts.hangar = hangars.id
131
+                                                 and
132
+                                                   setxml.variantof = aircrafts.id
133
+                                                 and
134
+                                                     setxml.file = '${fgfs_arg}'
135
+                                                 order by aircrafts.date desc"); do
136
+                    test -z "$ac" && continue
137
+                    read -q "REPLY?download ${${(@s/ /)ac}[1]} ? (y/N) "
138
+                    if test -n "$REPLY" && test ${REPLY:l} = "y"; then
139
+                        declare -A hangar
140
+                        eval $(sqlite3 $FGADDON/fgaddon.db <<< "select printf('hangar[type]=%s;hangar[url]=%s;', type, url)
141
+                                                                from hangars where name = '${${(@s/ /)ac}[2]:1:-1}'")
142
+                        case ${hangar[type]} in
143
+                            git)
144
+                                git -C $FGADDON/Aircraft clone https://github.com/FGMEMBERS/${${(@s/ /)ac}[1]}.git;;
145
+                            svn)
146
+                                svn checkout ${hangar[url]}/${${(@s/ /)ac}[1]} $FGADDON/Aircraft/${${(@s/ /)ac}[1]};;
147
+                        esac
148
+                        fgfs_args+=("--aircraft=$fgfs_arg")
149
+                        fgfs_args+=("--fg-aircraft=$FGADDON/Aircraft")
150
+                        unset -v hangar
151
+                    else
152
+                        echo "falling back to default"
153
+                    fi
154
+                    break
155
+                done
131 156
 
132 157
 ############ SERVEUR MULTIPLAY ?
133 158
             elif set -o BASH_REMATCH && [[ $fgfs_arg =~ "^mp([0-9]+)$" ]]; then