| 50 | } |
| 51 | |
| 52 | func (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 | |
| 87 | func (z zsh) installCompletion() error { |
| 88 | if err := dirs.CleanTmpFilesDir(); err != nil { |