Skip to content

Commit ddf9fde

Browse files
Put newline in shell docstring and simplify logic
1 parent 1ef02c0 commit ddf9fde

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

src/pyhf/cli/complete.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ def cli(shell):
2020
Bash:
2121
mkdir -p ~/.completions
2222
_PYHF_COMPLETE=bash_source pyhf > ~/.completions/pyhf-complete.sh
23-
echo ". ~/.completions/pyhf-complete.sh" >> ~/.bashrc
23+
echo -e "\n. ~/.completions/pyhf-complete.sh" >> ~/.bashrc
2424
2525
\b
2626
Zsh:
2727
mkdir -p ~/.completions
2828
_PYHF_COMPLETE=zsh_source pyhf > ~/.completions/pyhf-complete.zsh
29-
echo ". ~/.completions/pyhf-complete.zsh" >> ~/.zshrc
29+
echo -e "\n. ~/.completions/pyhf-complete.zsh" >> ~/.zshrc
3030
3131
\b
3232
Fish:
@@ -38,29 +38,25 @@ def cli(shell):
3838

3939
click.echo(f"To enable {shell} completion for pyhf run in your {shell} shell:\n")
4040

41-
if shell == "bash":
42-
click.echo(
43-
click.style(
44-
"mkdir -p ~/.completions\n"
45-
+ "_PYHF_COMPLETE=bash_source pyhf > ~/.completions/pyhf-complete.sh\n"
46-
+ 'echo -e "\\n. ~/.completions/pyhf-complete.sh" >> ~/.bashrc\n',
47-
bold=True,
48-
)
49-
)
50-
elif shell == "zsh":
51-
click.echo(
52-
click.style(
53-
"mkdir -p ~/.completions\n"
54-
+ "_PYHF_COMPLETE=zsh_source pyhf > ~/.completions/pyhf-complete.zsh\n"
55-
+ 'echo -e "\\n. ~/.completions/pyhf-complete.zsh" >> ~/.zshrc\n',
56-
bold=True,
57-
)
58-
)
59-
elif shell == "fish":
60-
click.echo(
61-
click.style(
62-
"_PYHF_COMPLETE=fish_source pyhf >> ~/.config/fish/completions/pyhf.fish\n",
63-
bold=True,
64-
)
41+
instructions = {
42+
"bash": (
43+
"mkdir -p ~/.completions\n"
44+
"_PYHF_COMPLETE=bash_source pyhf > ~/.completions/pyhf-complete.sh\n"
45+
'echo -e "\\n. ~/.completions/pyhf-complete.sh" >> ~/.bashrc\n'
46+
),
47+
"zsh": (
48+
"mkdir -p ~/.completions\n"
49+
"_PYHF_COMPLETE=zsh_source pyhf > ~/.completions/pyhf-complete.zsh\n"
50+
'echo -e "\\n. ~/.completions/pyhf-complete.zsh" >> ~/.zshrc\n'
51+
),
52+
"fish": (
53+
"_PYHF_COMPLETE=fish_source pyhf >> ~/.config/fish/completions/pyhf.fish\n"
54+
),
55+
}
56+
click.echo(
57+
click.style(
58+
instructions[shell],
59+
bold=True,
6560
)
61+
)
6662
click.echo("and then source your shell configuration or restart your shell.")

0 commit comments

Comments
 (0)