Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions client/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ func configureFish(homedir, binaryPath string, skipConfigModification bool) erro
if fishIsConfigured {
return nil
}

// Add to fishrc
if _, err := exec.LookPath("fish"); err != nil && skipConfigModification {
// fish is not installed, so avoid prompting the user to configure fish
Expand All @@ -313,15 +314,21 @@ func getFishConfigFragment(homedir string) string {
}

func isFishConfigured(homedir string) (bool, error) {
_, err := os.Stat(path.Join(homedir, ".config/fish/config.fish"))
fishConfigPath := ".config/fish/config.fish"
_, err := os.Stat(path.Join(homedir, fishConfigPath))
if errors.Is(err, os.ErrNotExist) {
return false, nil
}
fishConfig, err := os.ReadFile(path.Join(homedir, ".config/fish/config.fish"))

fishConfig, err := os.ReadFile(path.Join(homedir, fishConfigPath))
if err != nil {
return false, fmt.Errorf("failed to read ~/.config/fish/config.fish: %w", err)
return false, fmt.Errorf("failed to read %s: %w",
fishConfigPath, err)
}
return strings.Contains(string(fishConfig), getFishConfigFragment(homedir)), nil

return strings.Contains(string(fishConfig),
getFishConfigFragment(homedir),
), nil
}

func getZshConfigPath(homedir string) string {
Expand All @@ -338,7 +345,9 @@ func configureZshrc(homedir, binaryPath string, skipConfigModification bool) err
}
configContents = testConfig
}
err := os.WriteFile(getZshConfigPath(homedir), []byte(configContents), 0o644)

zshConfigPath := getZshConfigPath(homedir)
err := os.WriteFile(zshConfigPath, []byte(configContents), 0o644)
if err != nil {
return fmt.Errorf("failed to write config.zsh file: %w", err)
}
Expand All @@ -350,8 +359,11 @@ func configureZshrc(homedir, binaryPath string, skipConfigModification bool) err
if zshIsConfigured {
return nil
}

// Add to zshrc
return addToShellConfig(getZshRcPath(homedir), getZshConfigFragment(homedir), skipConfigModification)
return addToShellConfig(getZshRcPath(homedir),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally understand the preference for wrapping lines, however, keeping git history clean and meaningful can be really helpful for tracking actual code changes versus formatting updates.

Would you mind reverting the line wrapping in this PR in case they don't change the code? I think it would help maintain consistency and make future diffs easier to follow. Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it is lint commit and does not change any logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my mistake, I read the code but didn’t check the title, sorry about that. That said, this change still affects git history, making it harder to follow without adding much value.

If the goal is to improve formatting, would it be possible to standardize and automate it? I see there's a make fmt command, which seems like a convenient way to keep formatting the same for everyone. Otherwise, if everyone will adjust formatting based on personal preference, it will lead only to inconsistencies, not improvements.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind reverting it.

getZshConfigFragment(homedir),
skipConfigModification)
}

func getZshRcPath(homedir string) string {
Expand All @@ -370,11 +382,11 @@ func isZshConfigured(homedir string) (bool, error) {
if errors.Is(err, os.ErrNotExist) {
return false, nil
}
bashrc, err := os.ReadFile(getZshRcPath(homedir))
zshrc, err := os.ReadFile(getZshRcPath(homedir))
if err != nil {
return false, fmt.Errorf("failed to read zshrc: %w", err)
}
return strings.Contains(string(bashrc), getZshConfigFragment(homedir)), nil
return strings.Contains(string(zshrc), getZshConfigFragment(homedir)), nil
}

func getBashConfigPath(homedir string) string {
Expand All @@ -391,6 +403,7 @@ func configureBashrc(homedir, binaryPath string, skipConfigModification bool) er
}
configContents = testConfig
}

err := os.WriteFile(getBashConfigPath(homedir), []byte(configContents), 0o644)
if err != nil {
return fmt.Errorf("failed to write config.sh file: %w", err)
Expand All @@ -400,12 +413,14 @@ func configureBashrc(homedir, binaryPath string, skipConfigModification bool) er
if err != nil {
return fmt.Errorf("failed to check ~/.bashrc: %w", err)
}

if !bashRcIsConfigured {
err = addToShellConfig(path.Join(homedir, ".bashrc"), getBashConfigFragment(homedir), skipConfigModification)
if err != nil {
return err
}
}

// Check if we need to configure the bash_profile and configure it if so
if doesBashProfileNeedConfig(homedir) {
_, err := os.Stat(path.Join(homedir, ".bash_profile"))
Expand Down