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