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'