Browse Source

add tab completion for flask shell

pull/2608/head
Jonatan 7 years ago
parent
commit
94664c4279
No known key found for this signature in database
GPG Key ID: B739EADEBC511626
  1. 24
      flask/cli.py

24
flask/cli.py

@ -753,6 +753,30 @@ def shell_command():
app.instance_path,
)
ctx = {'__doc__': None, '__name__': '__flaskshell__'}
try:
import readline
import rlcompleter
except ImportError:
pass
else:
# Reading the initialization (config) file may not be enough to set a
# completion key, so we set one first and then read the file.
readline_doc = getattr(readline, '__doc__', '')
if readline_doc is not None and 'libedit' in readline_doc:
readline.parse_and_bind('bind ^I rl_complete')
else:
readline.parse_and_bind('tab: complete')
try:
readline.read_init_file()
except OSError:
# An OSError here could have many causes, but the most likely one
# is that there's no .inputrc file (or .editrc file in the case of
# Mac OS X + libedit) in the expected location. In that case, we
# want to ignore the exception.
pass
readline.set_completer(rlcompleter.Completer(ctx).complete)
# Support the regular Python interpreter startup script if someone
# is using it.

Loading…
Cancel
Save