Skip to content

Commit f365f82

Browse files
committed
detect the correct shell gotfile
1 parent f6d31f8 commit f365f82

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

oks_cli/utils.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,11 @@ def find_shell_profile(home, shell_type):
917917
if os.path.exists(bash_profile) and os.path.exists(bashrc):
918918
return None
919919

920-
shell_profile = bash_profile or bashrc
920+
if os.path.exists(bash_profile):
921+
shell_profile = bash_profile
922+
923+
if os.path.exists(bashrc):
924+
shell_profile = bashrc
921925

922926
elif shell_type == "zsh":
923927

@@ -927,7 +931,11 @@ def find_shell_profile(home, shell_type):
927931
if os.path.exists(zshrc) and os.path.exists(profile):
928932
return None
929933

930-
shell_profile = zshrc or profile
934+
if os.path.exists(zshrc):
935+
shell_profile = zshrc
936+
937+
if os.path.exists(profile):
938+
shell_profile = profile
931939

932940
return shell_profile
933941

tests/test_shell_completion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_install_completion_zsh():
99

1010
result = runner.invoke(cli, ["install-completion", "--type", "zsh"])
1111
assert result.exit_code == 0
12-
assert "Autocompletion installed for zsh" in result.output
12+
assert "To activate autocompletion on login please add following lines into your .profile or .zshrc file" in result.output
1313

1414
completion_file = Path("~/.oks_cli/completions/oks-cli.sh").expanduser()
1515
assert completion_file.exists()
@@ -22,7 +22,7 @@ def test_install_completion_bash():
2222

2323
result = runner.invoke(cli, ["install-completion", "--type", "bash"])
2424
assert result.exit_code == 0
25-
assert "Autocompletion installed for bash" in result.output
25+
assert "To activate autocompletion on login please add following lines into your .bash_profile or .bashrc file" in result.output
2626

2727
completion_file = Path("~/.oks_cli/completions/oks-cli.sh").expanduser()
2828
assert completion_file.exists()

0 commit comments

Comments
 (0)