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

Method registerRunCommand

completion/bash.go:147–173  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

145}
146
147func (b bash) registerRunCommand() error {
148 bashrcPath := filepath.Join(b.homeDir, ".bashrc")
149 if !fileio.PathExists(bashrcPath) {
150 return fmt.Errorf("no .bashrc file found in home dir")
151 }
152
153 // Check if already contains the line.
154 content, err := os.ReadFile(bashrcPath)
155 if err != nil {
156 return fmt.Errorf("failed to read ~/.bashrc -> %w", err)
157 }
158 if strings.Contains(string(content), b.registerBinary) {
159 return nil
160 }
161
162 // Append to end of .bashrc
163 file, err := os.OpenFile(bashrcPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
164 if err != nil {
165 return fmt.Errorf("failed to open ~/.bashrc -> %w", err)
166 }
167 defer file.Close()
168
169 if _, err := file.WriteString("\n" + b.registerBinary); err != nil {
170 return fmt.Errorf("failed to write to ~/.bashrc -> %w", err)
171 }
172 return nil
173}
174
175func (b bash) unregisterRunCommand() error {
176 // Check if .bashrc exists

Callers 1

RegisterMethod · 0.95

Calls 1

PathExistsFunction · 0.92

Tested by

no test coverage detected