Check python version at runtime for completions

Some things like pyenv can change what `python` refers to, so what we
detect when we load the completions can become invalid later.

Also mentioned in #3840.
This commit is contained in:
Fabian Homborg 2017-02-11 16:03:29 +01:00
parent f9664f224d
commit 52648acdc8

View File

@ -17,14 +17,13 @@ complete -c python -s x -d 'Skip first line of source, allowing use of non-Unix
complete -c python -a "(__fish_complete_suffix .py)"
complete -c python -a '-' -d 'Read program from stdin'
switch (python -V 2>&1 | string replace -r '^.*\s([23])..*' '$1')[1]
case 2
complete -c python -s 3 -d 'Warn about Python 3.x incompatibilities that 2to3 cannot trivially fix'
complete -c python -s t --description "Warn on mixed tabs and spaces"
complete -c python -s Q -x -a "old new warn warnall" --description "Division control"
case 3
complete -c python -s q --description 'Don\'t print version and copyright messages on interactive startup'
complete -c python -s X -x -d 'Set implementation-specific option'
complete -c python -s b -d 'Issue warnings about str(bytes_instance), str(bytearray_instance) and comparing bytes/bytearray with str'
complete -c python -o bb -d 'Issue errors'
end
# Version-specific completions
# We have to detect this at runtime because pyenv etc can change
# what `python` refers to.
complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s2"' -s 3 -d 'Warn about Python 3.x incompatibilities that 2to3 cannot trivially fix'
complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s2"' -s t --description "Warn on mixed tabs and spaces"
complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s2"' -s Q -x -a "old new warn warnall" --description "Division control"
complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s3"' -s q --description 'Don\'t print version and copyright messages on interactive startup'
complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s3"' -s X -x -d 'Set implementation-specific option'
complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s3"' -s b -d 'Issue warnings about str(bytes_instance), str(bytearray_instance) and comparing bytes/bytearray with str'
complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s3"' -o bb -d 'Issue errors'