]> git.mxchange.org Git - flightgear.git/blob - scripts/completion/fg-completion.bash
Merge branch 'jmt/gps' into next
[flightgear.git] / scripts / completion / fg-completion.bash
1 #!/bin/bash
2 # Tab completion for FlightGear command line options. To use it put
3 # this in your ~/.bashrc file:
4 #
5 #   export FG_HOME=$HOME/.fgfs/
6 #   [ -e $FG_HOME/fg-completion.bash ] && source $FG_HOME/fg-completion.bash
7 #
8 # Defining FG_HOME is only required if you don't like the default
9 # "$HOME/.fgfs/". The script doesn't offer all available airports
10 # for the --airport option, but only those listed in a file
11 # $FG_HOME/airport.list if available, or a short default list otherwise.
12 #
13 # After installing new aircraft you have to rebuild the aircraft list
14 # by typing   $ fgfs --aircraft=?<TAB>
15
16 __fgfs_root=${FG_ROOT:-/usr/local/share/FlightGear}
17 __fgfs_home=${FG_HOME:-$HOME/.fgfs}
18 [ -d "$__fgfs_home" ] || mkdir -p "$__fgfs_home"
19
20
21 __fgfs_ac_list="$__fgfs_home/aircraft.list"
22 __fgfs_apt_list="$__fgfs_home/airport.list"
23
24 __fgfs_options="
25         --help
26         --verbose
27         --disable-intro-music
28         --enable-intro-music
29         --units-feet
30         --units-meters
31         --disable-sound
32         --enable-sound
33         --disable-panel
34         --enable-panel
35         --disable-hud
36         --enable-hud
37         --disable-anti-alias-hud
38         --enable-anti-alias-hud
39         --disable-hud-3d
40         --enable-hud-3d
41         --hud-tris
42         --hud-culled
43         --disable-random-objects
44         --enable-random-objects
45         --disable-ai-models
46         --enable-ai-models
47         --disable-freeze
48         --enable-freeze
49         --disable-fuel-freeze
50         --enable-fuel-freeze
51         --disable-clock-freeze
52         --enable-clock-freeze
53         --disable-splash-screen
54         --enable-splash-screen
55         --disable-mouse-pointer
56         --enable-mouse-pointer
57         --fog-disable
58         --fog-fastest
59         --fog-nicest
60         --disable-enhanced-lighting
61         --enable-enhanced-lighting
62         --disable-distance-attenuation
63         --enable-distance-attenuation
64         --disable-specular-highlight
65         --enable-specular-highlight
66         --disable-fullscreen
67         --enable-fullscreen
68         --disable-game-mode
69         --enable-game-mode
70         --shading-flat
71         --shading-smooth
72         --disable-skyblend
73         --enable-skyblend
74         --disable-textures
75         --enable-textures
76         --disable-wireframe
77         --enable-wireframe
78         --notrim
79         --on-ground
80         --in-air
81         --enable-auto-coordination
82         --disable-auto-coordination
83         --show-aircraft
84         --time-match-real
85         --time-match-local
86         --disable-real-weather-fetch
87         --enable-real-weather-fetch
88         --disable-horizon-effect
89         --enable-horizon-effect
90         --enable-clouds
91         --disable-clouds
92         --enable-clouds3d
93         --disable-clouds3d
94         --atc610x
95         --enable-save-on-exit
96         --disable-save-on-exit
97         --ai-scenario=
98         --fg-root=
99         --fg-scenery=
100         --language=
101         --control=
102         --browser-app=
103         --config=
104         --failure=
105         --bpp=
106         --fov=
107         --callsign=
108         --aspect-ratio-multiplier=
109         --geometry=
110         --view-offset=
111         --aircraft=
112         --min-status=
113         --fdm=
114         --aero=
115         --model-hz=
116         --speed=
117         --aircraft-dir=
118         --timeofday=
119         --time-offset=
120         --start-date-sys=
121         --start-date-gmt=
122         --start-date-lat=
123         --airport=
124         --runway=
125         --carrier=
126         --parkpos=
127         --vor=
128         --ndb=
129         --fix=
130         --offset-distance=
131         --offset-azimuth=
132         --lon=
133         --lat=
134         --altitude=
135         --heading=
136         --roll=
137         --pitch=
138         --uBody=
139         --vBody=
140         --wBody=
141         --vc=
142         --mach=
143         --glideslope=
144         --roc=
145         --wp=
146         --flight-plan=
147         --nav1=
148         --nav2=
149         --adf=
150         --dme=
151         --visibility=
152         --visibility-miles=
153         --wind=
154         --turbulence=
155         --ceiling=
156         --multiplay=
157         --proxy=
158         --httpd=
159         --telnet=
160         --jpg-httpd=
161         --generic=
162         --garmin=
163         --joyclient=
164         --jsclient=
165         --native-ctrls=
166         --native-fdm=
167         --native=
168         --nmea=
169         --opengc=
170         --props=
171         --pve=
172         --ray=
173         --rul=
174         --log-level=
175         --trace-read=
176         --trace-write=
177         --season=
178         --vehicle=
179         --prop:
180 "
181
182
183 if [ ${BASH_VERSINFO[0]} -eq 2 ] && [[ ${BASH_VERSINFO[1]} = "05b" ]] \
184                 || [ ${BASH_VERSINFO[0]} -gt 2 ]; then
185         __fgfs_nospace="-o nospace"
186 fi
187
188 shopt -s progcomp
189
190
191 __fgfs_write_ac_list() {
192         rm -f $__fgfs_ac_list
193         for i in $__fgfs_root/Aircraft/*/*-set.xml; do
194                 i=${i%-set.xml}
195                 echo ${i##*/} >>$__fgfs_ac_list
196         done
197 }
198
199
200 [ -e $__fgfs_ac_list ] || __fgfs_write_ac_list
201
202
203 __fgfs_ai_scenario() {
204         local i
205         for i in $__fgfs_root/AI/*.xml; do
206                 i=${i%.xml}
207                 echo ${i##*/}
208         done
209 }
210
211
212 __fgfs_aircraft() {
213         while read i; do
214                 echo $i
215         done <$__fgfs_ac_list
216 }
217
218
219 __fgfs_offer() {
220         local i
221         for i in "$@"; do
222                 [ "$i" == "${i%=}" ] && i="$i "
223                 echo "$i"
224         done
225 }
226
227
228 __fgfs_options=$(__fgfs_offer $__fgfs_options)
229
230
231 __fgfs() {
232         COMPREPLY=()
233         local IFS=$'\n'$'\t' cur=${COMP_WORDS[COMP_CWORD]} alt
234
235         case "$cur" in
236         --ai-scenario=*)
237                 alt=$(__fgfs_offer $(__fgfs_ai_scenario))
238                 ;;
239         --aircraft=\?)
240                 __fgfs_write_ac_list
241                 ;;
242         --aircraft=*|--vehicle=*)
243                 alt=$(__fgfs_offer $(__fgfs_aircraft))
244                 ;;
245         --airport=*)
246                 if [ -e "$__fgfs_apt_list" ]; then
247                         alt=$(cat "$__fgfs_apt_list")
248                 else
249                         alt=$(__fgfs_offer khaf kpao koak kmry knuq ksjc kccr ksns krhv klvk o62 lpma)
250                 fi
251                 ;;
252         --carrier=*)
253                 alt=$(__fgfs_offer Nimitz Eisenhower Foch)
254                 ;;
255         --control=*)
256                 alt=$(__fgfs_offer joystick keyboard mouse)
257                 ;;
258         --failure=*)
259                 alt=$(__fgfs_offer pitot static vacuum electrical)
260                 ;;
261         --fdm=*)
262                 alt=$(__fgfs_offer jsbsim yasim uiuc larcsim ufo magic)
263                 ;;
264         --geometry=*)
265                 alt=$(__fgfs_offer 640x480 800x600 1024x768 1152x864 1600x1200)
266                 ;;
267         --log-level=*)
268                 alt=$(__fgfs_offer bulk debug info warn alert)
269                 ;;
270         --min-status=*)
271                 alt=$(__fgfs_offer alpha beta early-production production)
272                 ;;
273         --parkpos=*)
274                 alt=$(__fgfs_offer cat-1 cat-2 cat-3 cat-4 park-1)
275                 ;;
276         --season=*)
277                 alt=$(__fgfs_offer summer winter)
278                 ;;
279         --timeofday=*)
280                 alt=$(__fgfs_offer real dawn morning noon afternoon dusk evening midnight)
281                 ;;
282         --prop:*)
283                 return
284                 ;;
285         *)
286                 alt="$__fgfs_options"
287                 ;;
288         esac
289
290         COMPREPLY=($(compgen -W "$alt" -- ${cur#*=}))
291 }
292
293
294 complete -o default $__fgfs_nospace -F __fgfs fgfs signs fgfsterra
295