From 52648acdc8642b8dc4cfeec010cff4b3e2034148 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sat, 11 Feb 2017 16:03:29 +0100 Subject: [PATCH] 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. --- share/completions/python.fish | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/share/completions/python.fish b/share/completions/python.fish index d36aa9236..91565921d 100644 --- a/share/completions/python.fish +++ b/share/completions/python.fish @@ -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'