Skip to content

Commit 95d5d9e

Browse files
committed
update install script
1 parent 8051978 commit 95d5d9e

2 files changed

Lines changed: 105 additions & 0 deletions

File tree

install.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,38 @@ install() {
141141
fi
142142
log_info "Version $VERSION written to config"
143143

144+
# Install shell completions to config directory (not modifying user shell files)
145+
COMPLETION_DIR="$CONFIG_DIR/completions"
146+
mkdir -p "$COMPLETION_DIR"
147+
148+
# Detect current shell
149+
SHELL_NAME="$(basename "$SHELL" 2>/dev/null || echo "bash")"
150+
151+
case "$SHELL_NAME" in
152+
zsh)
153+
"$BINARY_NAME" completion zsh > "$COMPLETION_DIR/zsh"
154+
log_info "Zsh completion installed to $COMPLETION_DIR/zsh"
155+
log_info "Add to your .zshrc: source $COMPLETION_DIR/zsh"
156+
;;
157+
fish)
158+
"$BINARY_NAME" completion fish > "$COMPLETION_DIR/fish"
159+
log_info "Fish completion installed to $COMPLETION_DIR/fish"
160+
log_info "Add to your config.fish: source $COMPLETION_DIR/fish"
161+
;;
162+
bash)
163+
"$BINARY_NAME" completion bash > "$COMPLETION_DIR/bash"
164+
log_info "Bash completion installed to $COMPLETION_DIR/bash"
165+
log_info "Add to your .bashrc: source $COMPLETION_DIR/bash"
166+
;;
167+
*)
168+
# Install all completions
169+
"$BINARY_NAME" completion bash > "$COMPLETION_DIR/bash" 2>/dev/null || true
170+
"$BINARY_NAME" completion zsh > "$COMPLETION_DIR/zsh" 2>/dev/null || true
171+
"$BINARY_NAME" completion fish > "$COMPLETION_DIR/fish" 2>/dev/null || true
172+
log_info "Completions installed to $COMPLETION_DIR"
173+
;;
174+
esac
175+
144176
# Cleanup
145177
cd /
146178
rm -rf "$TEMP_DIR"

internal/commands/completion.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package commands
2+
3+
import (
4+
"os"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var completionCmd = &cobra.Command{
10+
Use: "completion [shell]",
11+
Short: "Generate shell completion scripts",
12+
Hidden: true,
13+
Long: `Generate shell completion scripts for menlo.
14+
15+
To load completions:
16+
17+
Bash:
18+
19+
$ source <(menlo completion bash)
20+
21+
# To load completions for each session, execute once:
22+
# Linux:
23+
$ menlo completion bash > /etc/bash_completion.d/menlo
24+
# macOS:
25+
$ menlo completion bash > /usr/local/etc/bash_completion.d/menlo
26+
27+
Zsh:
28+
29+
# If shell completion is not already enabled in your environment,
30+
# you will need to enable it. You can execute the following once:
31+
32+
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
33+
34+
# To load completions for each session, execute once:
35+
$ menlo completion zsh > "${fpath[1]}/_menlo"
36+
37+
# You will need to start a new shell for this setup to take effect.
38+
39+
Fish:
40+
41+
$ menlo completion fish | source
42+
43+
# To load completions for each session, execute once:
44+
$ menlo completion fish > ~/.config/fish/completions/menlo.fish
45+
46+
PowerShell:
47+
48+
PS> menlo completion powershell | Out-String | Invoke-Expression
49+
50+
# To load completions for every session, add the output of the previous
51+
# command to your powershell profile.
52+
`,
53+
DisableFlagsInUseLine: true,
54+
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
55+
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
56+
RunE: func(cmd *cobra.Command, args []string) error {
57+
switch args[0] {
58+
case "bash":
59+
return rootCmd.GenBashCompletion(os.Stdout)
60+
case "zsh":
61+
return rootCmd.GenZshCompletion(os.Stdout)
62+
case "fish":
63+
return rootCmd.GenFishCompletion(os.Stdout, true)
64+
case "powershell":
65+
return rootCmd.GenPowerShellCompletionWithDesc(os.Stdout)
66+
}
67+
return nil
68+
},
69+
}
70+
71+
func init() {
72+
rootCmd.AddCommand(completionCmd)
73+
}

0 commit comments

Comments
 (0)