Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fish completion does not work with env vars in the program path #1306

Closed
marckhouzam opened this issue Dec 30, 2020 · 3 comments · Fixed by #1249
Closed

Fish completion does not work with env vars in the program path #1306

marckhouzam opened this issue Dec 30, 2020 · 3 comments · Fixed by #1249

Comments

@marckhouzam
Copy link
Collaborator

Using an environment variable or a ~ when using a path for the program breaks shell completion for fish.
For instance:

$HOME/testprog [TAB]
~/testprog [TAB]

currently don't work for fish. This is because of the use of type -q in the script.

marckhouzam added a commit to VilledeMontreal/cobra that referenced this issue Dec 31, 2020
Fixes spf13#1214
Fixes spf13#1306

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
@marckhouzam
Copy link
Collaborator Author

I've added a fix for this issue to #1249

marckhouzam added a commit to VilledeMontreal/cobra that referenced this issue Jan 3, 2021
Fixes spf13#1214
Fixes spf13#1306

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
marckhouzam added a commit to VilledeMontreal/cobra that referenced this issue Jan 25, 2021
Fixes spf13#1214
Fixes spf13#1306

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
marckhouzam added a commit to VilledeMontreal/cobra that referenced this issue Jan 30, 2021
Fixes spf13#1214
Fixes spf13#1306

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
marckhouzam added a commit to VilledeMontreal/cobra that referenced this issue Feb 14, 2021
Fixes spf13#1214
Fixes spf13#1306

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
marckhouzam added a commit to VilledeMontreal/cobra that referenced this issue Feb 15, 2021
Fixes spf13#1214
Fixes spf13#1306

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
@github-actions
Copy link

github-actions bot commented Mar 2, 2021

This issue is being marked as stale due to a long period of inactivity

@marckhouzam
Copy link
Collaborator Author

Waiting for the review of #1249

marckhouzam added a commit to VilledeMontreal/cobra that referenced this issue Mar 4, 2021
Fixes spf13#1214
Fixes spf13#1306

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
marckhouzam added a commit to VilledeMontreal/cobra that referenced this issue May 3, 2021
Fixes spf13#1214
Fixes spf13#1306

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
jpmcb pushed a commit that referenced this issue May 3, 2021
* Fix fish for ShellDirectiveNoSpace and file comp

For fish shell we achieve ShellDirectiveNoSpace by outputing a fake
second completion with an extra character.  However, this extra
character was being added after the description string, instead of
before.  This commit fixes that.

It also cleans up the script of useless code, now that fish completion
details are better understood.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

* Handle case when completion starts with a space

Fixes #1303

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

* Support fish completion with env vars in the path

Fixes #1214
Fixes #1306

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

* Update based on review

1- We use `set -l` for local variable to make sure there are no
   conflicts with global variables
2- We use `commandline -opc` which:
   a) splits the command line into tokens (-o)
   b) only considers the current command (-p) (e.g., echo hello; helm <TAB>)
   c) stops at the cursor (-c)
3- We extract the last arg with `commandline -ct` and escape it to handle
   the case where it is a space, or unmatched quote.
4- We avoid looping when filtering on prefix.
5- We don't add a fake comp for ShellCompDirectiveNoSpace when the
   completion ends with any of @=/:., as fish won't add a space

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
muscliary pushed a commit to muscliary/cobra that referenced this issue Sep 12, 2023
* Fix fish for ShellDirectiveNoSpace and file comp

For fish shell we achieve ShellDirectiveNoSpace by outputing a fake
second completion with an extra character.  However, this extra
character was being added after the description string, instead of
before.  This commit fixes that.

It also cleans up the script of useless code, now that fish completion
details are better understood.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

* Handle case when completion starts with a space

Fixes #1303

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

* Support fish completion with env vars in the path

Fixes spf13/cobra#1214
Fixes spf13/cobra#1306

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

* Update based on review

1- We use `set -l` for local variable to make sure there are no
   conflicts with global variables
2- We use `commandline -opc` which:
   a) splits the command line into tokens (-o)
   b) only considers the current command (-p) (e.g., echo hello; helm <TAB>)
   c) stops at the cursor (-c)
3- We extract the last arg with `commandline -ct` and escape it to handle
   the case where it is a space, or unmatched quote.
4- We avoid looping when filtering on prefix.
5- We don't add a fake comp for ShellCompDirectiveNoSpace when the
   completion ends with any of @=/:., as fish won't add a space

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant