Comments (1)
Ok, turns out my initial patching attempt was incomplete. This works and fixes the issue:
diff --git a/click_completion/core.py b/click_completion/core.py
index 867085e..4f83e48 100644
--- a/click_completion/core.py
+++ b/click_completion/core.py
@@ -188,12 +188,8 @@ def do_fish_complete(cli, prog_name):
True if the completion was successful, False otherwise
"""
commandline = os.environ['COMMANDLINE']
- args = split_args(commandline)[1:]
- if args and not commandline.endswith(' '):
- incomplete = args[-1]
- args = args[:-1]
- else:
- incomplete = ''
+ args, incomplete = split_args(commandline)
+ args = args[1:]
for item, help in get_choices(cli, prog_name, args, incomplete):
if help:
diff --git a/click_completion/lib.py b/click_completion/lib.py
index fc195cd..ddee5da 100644
--- a/click_completion/lib.py
+++ b/click_completion/lib.py
@@ -101,23 +101,35 @@ def split_args(line):
Returns
-------
- [str]
- The line split in separated arguments
+ [str], str
+ The line split in separated arguments, plus the last incomplete argument (if any)
"""
lex = shlex.shlex(line, posix=True)
lex.whitespace_split = True
lex.commenters = ''
res = []
+ last_state = lex.state
try:
while True:
+ last_state = lex.state
res.append(next(lex))
except ValueError: # No closing quotation
- pass
+ return res, lex.token
except StopIteration: # End of loop
- pass
- if lex.token:
- res.append(lex.token)
- return res
+ if last_state is None:
+ return res[:-1], res[-1]
+ else:
+ return res, ''
+
+
+def test_split_args():
+ assert split_args("foo bar") == (["foo"], "bar")
+ assert split_args("foo bar ") == (["foo", "bar"], "")
+ assert split_args("foo 'bar") == (["foo"], "bar")
+ assert split_args("foo 'bar ") == (["foo"], "bar ")
+ assert split_args("foo 'bar baz'") == (["foo"], "bar baz")
+ assert split_args("foo 'bar baz' ") == (["foo", "bar baz"], "")
+ assert split_args("foo bar\\ ") == (["foo"], "bar ")
There's the obvious question if the same sort of fix should be applied to the other shells as well. Any thoughts?
from click-completion.
Related Issues (20)
- zsh completion with "inner" substrings HOT 2
- setup.py relies on old-style extras syntax
- Please tag 0.5.0 HOT 1
- Install fails when running PowerShell from emulated terminal cmder
- Don't suggest hidden commands HOT 1
- zsh: command not found: #compdef HOT 2
- psutil remains should be removed HOT 1
- file/path completion HOT 3
- 'install_requires' must be a string or list of string HOT 3
- Don't suggest hidden options
- Not working for options defined for comma separated values
- Problem with completion HOT 3
- Click's completion system has been rewritten HOT 1
- No support for PowerShell 7 (PowerShell Core)
- Clarify whether this repo is deprecated or not HOT 5
- How to run install command after pip install ? HOT 1
- click 8.0 compatible code? HOT 3
- Publish "wheel" package in PyPI
- How to apply part of this library to support Powershell completion for click v8.x HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from click-completion.