MCPcopy Create free account
hub / github.com/celer-pkg/celer / installBinary

Method installBinary

completion/zsh.go:52–85  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50}
51
52func (z zsh) installBinary() error {
53 executable, err := os.Executable()
54 if err != nil {
55 return fmt.Errorf("failed to get celer's path -> %w", err)
56 }
57
58 // Copy into `~/.local/bin`
59 if err := fileio.CopyFile(executable, filepath.Join(z.homeDir, ".local/bin/celer")); err != nil {
60 return fmt.Errorf("failed to copy celer to ~/.local/bin -> %w", err)
61 }
62 fmt.Println("[integrate] celer --> ~/.local/bin")
63
64 // Check if already contains the line.
65 zshrcPath := filepath.Join(z.homeDir, ".zshrc")
66 content, err := os.ReadFile(zshrcPath)
67 if err != nil {
68 return fmt.Errorf("failed to read ~/.zshrc -> %w", err)
69 }
70 if strings.Contains(string(content), z.registerBinary) {
71 return nil
72 }
73
74 // Append `export PATH=~/.local/bin:$PATH` to top of .zshrc
75 file, err := os.ReadFile(zshrcPath)
76 if err != nil && !os.IsNotExist(err) {
77 return fmt.Errorf("failed to read ~/.zshrc -> %w", err)
78 }
79 newContent := z.registerBinary + "\n" + string(file)
80 if err := os.WriteFile(zshrcPath, []byte(newContent), os.ModePerm); err != nil {
81 return fmt.Errorf("failed to write to ~/.zshrc -> %w", err)
82 }
83
84 return nil
85}
86
87func (z zsh) installCompletion() error {
88 if err := dirs.CleanTmpFilesDir(); err != nil {

Callers 1

RegisterMethod · 0.95

Calls 2

CopyFileFunction · 0.92
WriteFileMethod · 0.80

Tested by

no test coverage detected