Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unquote zdotdir for starting zsh in wsl #1574

Merged
merged 1 commit into from
Dec 19, 2024
Merged

Conversation

oneirocosm
Copy link
Member

Due to the way this command is run, the quotes are not being handled by the shell. Removing them allows them to be interpreted correctly in most cases. This resolves #1569

Due to the way this command is run, the quotes are not being handled by
the shell. Removing them allows them to be interpreted correctly in most
cases.
Copy link

coderabbitai bot commented Dec 19, 2024

Walkthrough

The pull request introduces a modification to the StartWslShellProc and StartRemoteShellProc functions in the pkg/shellexec/shellexec.go file, specifically focusing on the ZDOTDIR environment variable configuration for Zsh shells.

The primary change involves removing the quotation marks around the ZDOTDIR path assignment. Previously, the code used a quoted format for setting the ZDOTDIR environment variable, which constructed the path with explicit quotes. The updated implementation removes these quotes, changing the way the path is formatted when appending to the shell options.

This modification affects how the Zsh shell integration directory path is constructed and potentially how the shell interprets the environment variable. The change is applied consistently across both functions that set the ZDOTDIR variable, ensuring uniform handling of the environment variable configuration.

The modification does not introduce changes to the overall logic, error handling, or control flow of the functions. It is a subtle adjustment in how the path for the Zsh integration directory is specified when launching a shell environment.

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 12d58c9 and 71fdb8f.

📒 Files selected for processing (1)
  • pkg/shellexec/shellexec.go (1 hunks)
🔇 Additional comments (2)
pkg/shellexec/shellexec.go (2)

218-218: Verify ZDOTDIR quoting behavior across different environments

The ZDOTDIR path is now unquoted in WSL but remains quoted in remote shells. While this might be intentional due to different shell behaviors, we should verify this is the desired approach.

Let's analyze the ZDOTDIR handling across different environments:

✅ Verification successful

ZDOTDIR quoting differences are intentional and correct

The different handling of ZDOTDIR between environments is intentional and properly implemented:

  1. WSL: Uses unquoted ZDOTDIR in command-line arguments

    shellOpts = append(shellOpts, fmt.Sprintf(`ZDOTDIR=%s/.waveterm/%s`, homeDir, shellutil.ZshIntegrationDir))
  2. SSH/Remote: Uses quoted ZDOTDIR in command string

    cmdCombined = fmt.Sprintf(`ZDOTDIR="%s/.waveterm/%s" %s`, homeDir, shellutil.ZshIntegrationDir, cmdCombined)
  3. Local: Uses environment variable

    shellutil.UpdateCmdEnv(ecmd, map[string]string{"ZDOTDIR": shellutil.GetZshZDotDir()})

Each approach is appropriate for its specific context:

  • WSL needs unquoted args due to how wsl.exe handles command-line parameters
  • Remote shells need quoted paths in the command string for proper shell interpretation
  • Local execution uses direct environment variable setting
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check how ZDOTDIR is handled in different contexts
echo "WSL ZDOTDIR handling:"
rg -B 5 -A 5 'ZDOTDIR.*waveterm' --glob 'pkg/**/*wsl*.{go,rs,js,ts}'

echo "Remote ZDOTDIR handling:"
rg -B 5 -A 5 'ZDOTDIR.*waveterm' --glob 'pkg/**/*ssh*.{go,rs,js,ts}'

echo "Related issues or discussions:"
rg -i 'zdotdir.*(wsl|remote|ssh)' --type md

Length of output: 370


Script:

#!/bin/bash
# Let's try a broader search for ZDOTDIR usage across the codebase
echo "All ZDOTDIR occurrences:"
rg -B 5 -A 5 'ZDOTDIR' pkg/

# Also check for shell-specific configurations
echo -e "\nShell configuration related code:"
rg -B 5 -A 5 'shellOpts.*=' pkg/

Length of output: 9294


218-218: Consider path handling edge cases with unquoted ZDOTDIR

While removing quotes from ZDOTDIR may fix the immediate WSL issue, we should verify the behavior with paths containing special characters.

Let's check how other environment variables are handled in WSL and if there are any existing issues with special characters in paths:

Consider adding a comment explaining why ZDOTDIR is handled differently in WSL compared to remote shells (where it remains quoted) to prevent future regressions.

✅ Verification successful

Unquoted ZDOTDIR in WSL is safe and consistent with codebase patterns

After analyzing the codebase, I can confirm that the unquoted ZDOTDIR in WSL is the correct approach:

  1. The WSL-specific code in StartWslShellProc handles environment variables differently from remote shells, as evidenced by the distinct implementation.
  2. The codebase explicitly documents that "quoting breaks this particular case" in WSL context (see comment in wsl.DetectShell).
  3. The environment variable handling in WSL follows a consistent pattern where only PowerShell variables are quoted (using $env: syntax).
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for other environment variable handling patterns in the codebase
rg -A 2 'shellOpts = append\(shellOpts, fmt\.Sprintf\(`.*=.*`.*\)\)' 

# Look for any existing issues or discussions about path quoting in WSL
rg -i 'wsl.*path.*quot(e|ing)' 
rg -i 'zdotdir.*path.*quot(e|ing)'

Length of output: 376


Script:

#!/bin/bash
# Let's check how ZDOTDIR is handled in other shell execution contexts
ast-grep --pattern 'ZDOTDIR=$_'

# Check for any WSL-specific path handling patterns
rg -B 2 -A 2 'wsl.*path'

# Look for other environment variable settings in shell execution
rg -B 2 -A 2 'shellOpts.*=.*append.*env'

# Check for any comments or documentation about WSL path handling
rg -l -i 'wsl.*path'

Length of output: 1138


Script:

#!/bin/bash
# Let's examine the WSL utility file for path handling patterns
cat pkg/wsl/wsl-util.go

# Let's also check the full context of shell execution in shellexec.go
cat pkg/shellexec/shellexec.go

Length of output: 23993


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@oneirocosm oneirocosm merged commit 76e8bc4 into main Dec 19, 2024
7 of 8 checks passed
@oneirocosm oneirocosm deleted the sylvie/wsl-zdotdir branch December 19, 2024 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: zsh wouldn't load zshrc in WSL
1 participant