-
Notifications
You must be signed in to change notification settings - Fork 391
feat(__load_completion): search more paths based on the command location #696
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
60f592a
docs(README): add a disclaimer about external completion installation
akinomyoga 530017d
docs(README): describe the local installation of external completions
nurupo be0085a
fix(README): elaborate description of search order
akinomyoga 12cff41
feat(__load_completion): look more places for completion files
akinomyoga c7d526d
feat(__load_completion): load in-tree before system data dirs
scop 1984040
fix(__load_completion): lower the precedence of the completion "_cmd"
akinomyoga 388a8ce
test(__load_completion): check user dir precedence over PATH
scop b22af05
test(__load_completion): check in-tree precedence over PATH
scop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../prefix1/bin/cmd1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../prefix1/sbin/cmd2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
echo cmd1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
echo sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
echo cmd2 |
1 change: 1 addition & 0 deletions
1
test/fixtures/__load_completion/prefix1/share/bash-completion/completions/cmd1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
echo 'cmd1: sourced from prefix1' |
1 change: 1 addition & 0 deletions
1
test/fixtures/__load_completion/prefix1/share/bash-completion/completions/cmd2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
echo 'cmd2: sourced from prefix1' |
1 change: 1 addition & 0 deletions
1
test/fixtures/__load_completion/prefix1/share/bash-completion/completions/sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
echo 'sh: sourced from prefix1' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
echo 'cmd1: sourced from userdir1' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
echo 'cmd2: sourced from userdir2' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import pytest | ||
|
||
from conftest import assert_bash_exec, bash_env_saved | ||
|
||
|
||
@pytest.mark.bashcomp(cmd=None, cwd="__load_completion") | ||
class TestLoadCompletion: | ||
def test_userdir_1(self, bash): | ||
with bash_env_saved(bash) as bash_env: | ||
bash_env.write_variable( | ||
"BASH_COMPLETION_USER_DIR", | ||
"$PWD/userdir1:$PWD/userdir2:$BASH_COMPLETION_USER_DIR", | ||
quote=False, | ||
) | ||
bash_env.write_variable( | ||
"PATH", "$PWD/prefix1/bin:$PWD/prefix1/sbin", quote=False | ||
) | ||
output = assert_bash_exec( | ||
bash, "__load_completion cmd1", want_output=True | ||
) | ||
assert output.strip() == "cmd1: sourced from userdir1" | ||
output = assert_bash_exec( | ||
bash, "__load_completion cmd2", want_output=True | ||
) | ||
assert output.strip() == "cmd2: sourced from userdir2" | ||
|
||
def test_PATH_1(self, bash): | ||
with bash_env_saved(bash) as bash_env: | ||
bash_env.write_variable( | ||
"PATH", "$PWD/prefix1/bin:$PWD/prefix1/sbin", quote=False | ||
) | ||
output = assert_bash_exec( | ||
bash, "__load_completion cmd1", want_output=True | ||
) | ||
assert output.strip() == "cmd1: sourced from prefix1" | ||
output = assert_bash_exec( | ||
bash, "__load_completion cmd2", want_output=True | ||
) | ||
assert output.strip() == "cmd2: sourced from prefix1" | ||
|
||
def test_cmd_path_1(self, bash): | ||
output = assert_bash_exec( | ||
bash, "__load_completion prefix1/bin/cmd1", want_output=True | ||
) | ||
assert output.strip() == "cmd1: sourced from prefix1" | ||
output = assert_bash_exec( | ||
bash, "__load_completion prefix1/sbin/cmd2", want_output=True | ||
) | ||
assert output.strip() == "cmd2: sourced from prefix1" | ||
output = assert_bash_exec( | ||
bash, "__load_completion bin/cmd1", want_output=True | ||
) | ||
assert output.strip() == "cmd1: sourced from prefix1" | ||
output = assert_bash_exec( | ||
bash, "__load_completion bin/cmd2", want_output=True | ||
) | ||
assert output.strip() == "cmd2: sourced from prefix1" | ||
|
||
def test_cmd_path_2(self, bash): | ||
with bash_env_saved(bash) as bash_env: | ||
bash_env.write_variable("PATH", "$PWD/bin:$PATH", quote=False) | ||
output = assert_bash_exec( | ||
bash, "__load_completion cmd1", want_output=True | ||
) | ||
assert output.strip() == "cmd1: sourced from prefix1" | ||
output = assert_bash_exec( | ||
bash, "__load_completion cmd2", want_output=True | ||
) | ||
assert output.strip() == "cmd2: sourced from prefix1" | ||
|
||
def test_cmd_intree_precedence(self, bash): | ||
""" | ||
Test in-tree, i.e. completions/$cmd relative to the main script | ||
has precedence over location derived from PATH. | ||
""" | ||
with bash_env_saved(bash) as bash_env: | ||
bash_env.write_variable("PATH", "$PWD/prefix1/bin", quote=False) | ||
# The in-tree `sh` completion should be loaded here, | ||
# and cause no output, unlike our `$PWD/prefix1/bin/sh` canary. | ||
assert_bash_exec(bash, "__load_completion sh", want_output=False) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.