fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Steve Walkerfix python completion #10943b574a5e4f

master
3.9 KiB53 linesraw
1# This function adjusts for options with arguments (-X, -W, etc.), ensures completions stop when a script/module is set (-c, -m, file, -)
2function __fish_python_no_arg
3    set -l num 1
4    set -l tokens (commandline -pxc)
5    set -l has_arg_list -X -W --check-hash-based-pycs
6    if contains -- - $tokens
7        set num (math $num - 1)
8    end
9    for has_arg in $has_arg_list
10        if contains -- $has_arg $tokens
11            set num (math $num + 1)
12        end
13    end
14    if test (__fish_number_of_cmd_args_wo_opts) -gt $num
15        return 1
16    end
17    return 0
18end
19
20complete -c python -n __fish_python_no_arg -s B -d 'Don\'t write .py[co] files on import'
21complete -c python -n __fish_python_no_arg -s c -x -d "Execute argument as command"
22complete -c python -n __fish_python_no_arg -l check-hash-based-pycs -a "default always never" -d "Control validation behaviour of pyc files"
23complete -c python -n __fish_python_no_arg -s d -d "Debug on"
24complete -c python -n __fish_python_no_arg -s E -d "Ignore all PYTHON* env vars"
25complete -c python -n __fish_python_no_arg -s h -s '?' -l help -d "Display help and exit"
26complete -c python -n __fish_python_no_arg -s i -d "Interactive mode after executing commands"
27complete -c python -n __fish_python_no_arg -s m -d 'Run library module as a script (terminates option list)' -xa '(python -c "import pkgutil; print(\'\n\'.join([p[1] for p in pkgutil.iter_modules()]))")'
28complete -c python -n __fish_python_no_arg -s O -d "Enable optimizations"
29complete -c python -n __fish_python_no_arg -o OO -d "Remove doc-strings in addition to the -O optimizations"
30complete -c python -n __fish_python_no_arg -s s -d 'Don\'t add user site directory to sys.path'
31complete -c python -n __fish_python_no_arg -s S -d "Disable import of site module"
32complete -c python -n __fish_python_no_arg -s u -d "Unbuffered input and output"
33complete -c python -n __fish_python_no_arg -s v -d "Verbose mode"
34complete -c python -n __fish_python_no_arg -o vv -d "Even more verbose mode"
35complete -c python -n __fish_python_no_arg -s V -l version -d "Display version and exit"
36complete -c python -n __fish_python_no_arg -s W -x -d "Warning control" -a "ignore default all module once error"
37complete -c python -n __fish_python_no_arg -s x -d 'Skip first line of source, allowing use of non-Unix forms of #!cmd'
38complete -c python -n __fish_python_no_arg -f -k -a "(__fish_complete_suffix .py)"
39complete -c python -n __fish_python_no_arg -f -a - -d 'Read program from stdin'
40
41# Version-specific completions
42# We have to detect this at runtime because pyenv etc can change
43# what `python` refers to.
44complete -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'
45complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s2"' -s t -d "Warn on mixed tabs and spaces"
46complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s2"' -s Q -x -a "old new warn warnall" -d "Division control"
47complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s3" && __fish_python_no_arg' -s q -d 'Don\'t print version and copyright messages on interactive startup'
48complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s3" && __fish_python_no_arg' -s X -x -d 'Set implementation-specific option'
49complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s3" && __fish_python_no_arg' -s b -d 'Warn when comparing bytes with str or int'
50complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s3" && __fish_python_no_arg' -o bb -d 'Error when comparing bytes with str or int'
51complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s3" && __fish_python_no_arg' -s R -d 'Turn on hash randomization'
52complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s3" && __fish_python_no_arg' -s I -d 'Run in isolated mode'
53complete -c python -n 'python -V 2>&1 | string match -rq "^.*\s3" && __fish_python_no_arg' -o VV -d 'Print further version info'