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