MCPcopy
hub / github.com/wavetermdev/waveterm / InitRcFiles

Function InitRcFiles

pkg/util/shellutil/shellutil.go:357–427  ·  view source on GitHub ↗

absWshBinDir must be an absolute, expanded path (no ~ or $HOME, etc.) it will be hard-quoted appropriately for the shell

(waveHome string, absWshBinDir string)

Source from the content-addressed store, hash-verified

355// absWshBinDir must be an absolute, expanded path (no ~ or $HOME, etc.)
356// it will be hard-quoted appropriately for the shell
357func InitRcFiles(waveHome string, absWshBinDir string) error {
358 // ensure directories exist
359 zshDir := filepath.Join(waveHome, ZshIntegrationDir)
360 err := wavebase.CacheEnsureDir(zshDir, ZshIntegrationDir, 0755, ZshIntegrationDir)
361 if err != nil {
362 return err
363 }
364 bashDir := filepath.Join(waveHome, BashIntegrationDir)
365 err = wavebase.CacheEnsureDir(bashDir, BashIntegrationDir, 0755, BashIntegrationDir)
366 if err != nil {
367 return err
368 }
369 fishDir := filepath.Join(waveHome, FishIntegrationDir)
370 err = wavebase.CacheEnsureDir(fishDir, FishIntegrationDir, 0755, FishIntegrationDir)
371 if err != nil {
372 return err
373 }
374 pwshDir := filepath.Join(waveHome, PwshIntegrationDir)
375 err = wavebase.CacheEnsureDir(pwshDir, PwshIntegrationDir, 0755, PwshIntegrationDir)
376 if err != nil {
377 return err
378 }
379
380 var pathSep string
381 if runtime.GOOS == "windows" {
382 pathSep = ";"
383 } else {
384 pathSep = ":"
385 }
386 params := map[string]string{
387 "WSHBINDIR": HardQuote(absWshBinDir),
388 "WSHBINDIR_PWSH": HardQuotePowerShell(absWshBinDir),
389 "PATHSEP": pathSep,
390 }
391
392 // write files to directory
393 err = utilfn.WriteTemplateToFile(filepath.Join(zshDir, ".zprofile"), ZshStartup_Zprofile, params)
394 if err != nil {
395 return fmt.Errorf("error writing zsh-integration .zprofile: %v", err)
396 }
397 err = utilfn.WriteTemplateToFile(filepath.Join(zshDir, ".zshrc"), ZshStartup_Zshrc, params)
398 if err != nil {
399 return fmt.Errorf("error writing zsh-integration .zshrc: %v", err)
400 }
401 err = utilfn.WriteTemplateToFile(filepath.Join(zshDir, ".zlogin"), ZshStartup_Zlogin, params)
402 if err != nil {
403 return fmt.Errorf("error writing zsh-integration .zlogin: %v", err)
404 }
405 err = utilfn.WriteTemplateToFile(filepath.Join(zshDir, ".zshenv"), ZshStartup_Zshenv, params)
406 if err != nil {
407 return fmt.Errorf("error writing zsh-integration .zshenv: %v", err)
408 }
409 err = utilfn.WriteTemplateToFile(filepath.Join(bashDir, ".bashrc"), BashStartup_Bashrc, params)
410 if err != nil {
411 return fmt.Errorf("error writing bash-integration .bashrc: %v", err)
412 }
413 err = os.WriteFile(filepath.Join(bashDir, "bash_preexec.sh"), []byte(BashStartup_Preexec), 0644)
414 if err != nil {

Callers 2

InstallRcFilesFunction · 0.92

Calls 5

CacheEnsureDirFunction · 0.92
WriteTemplateToFileFunction · 0.92
HardQuoteFunction · 0.85
HardQuotePowerShellFunction · 0.85
WriteFileMethod · 0.80

Tested by

no test coverage detected