Skip to content

docs: add OSC-7 working-directory tracking documentation #2211

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ryderstorm
Copy link

Background & Motivation

After installing Wave Terminal, new tabs and splits always started in my home folder instead of the current project directory, contrary to expectations from other terminals I've used. For context, I use bash for my shell.

The existing documentation did not provide guidance about the required OSC 7 setup, so I had to dig into GitHub issues and source code to discover that Wave relies on a terminal escape sequence to track the shell’s working directory. This confusion represents a barrier for first-time users.

Description

This PR introduces a new documentation page—Tracking Your Shell’s Working Directory—which:

  1. Explains why Wave uses the OSC 7 escape sequence to keep its internal cmd:cwd metadata in sync with your shell.
  2. Provides copy-and-paste snippets to enable OSC 7 in Bash, Zsh, and Fish.
  3. Details verification steps in the Wave UI to confirm correct CWD tracking.

By making this enhancement, users can:

  • Open new tabs or split panes with their current working directory.
  • Avoid the ERRCWD invalid cwd errors in some shell configurations.
  • Spend less time troubleshooting and more time working.

Changes

  • Added docs/docs/track-cwd.mdx (new page to enable OSC 7).
  • Updated docs/docs/index.mdx (linked the new page under Other References).

Related Issues

Testing & Review

  1. Local build

    cd waveterm
    yarn
    task docsite
    • Confirm the new “Tracking Your Shell’s Working Directory” page appears in the sidebar.
    • Verify the instructions and code samples render correctly.
  2. Content review

    • Are the shell snippets accurate?
    • Is the enable → verify flow clear and complete?

I have followed the contributing guidelines and used a conventional commit message.

@CLAassistant
Copy link

CLAassistant commented Jun 27, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

coderabbitai bot commented Jun 27, 2025

Walkthrough

A new FAQ section was added to the documentation, addressing how to make new tabs or splits inherit the shell’s current directory in Wave. The section explains the use of the OSC 7 escape sequence for tracking and propagating the working directory, and provides shell-specific configuration instructions for Bash, Zsh, and Fish. It also describes how to verify the functionality using wsh getmeta. Additionally, a minor correction was made to a link reference in the ARM64 warning FAQ, updating it from ./config.mdx to ./config. No changes were made to exported or public entities.


📜 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 e465f54 and 756e12e.

📒 Files selected for processing (1)
  • docs/docs/faq.mdx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/docs/faq.mdx

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
docs/docs/index.mdx (1)

70-76: Alphabetise or group reference links consistently

The new “Tracking Your Shell’s Working Directory” entry is inserted between Configuration and Custom Widgets, which keeps the list roughly alphabetical by title, but other sections historically group items by topic rather than strict alpha order. Double-check that the ordering logic you want is applied consistently across the whole list so future additions remain predictable.

docs/docs/track-cwd.mdx (3)

40-46: Zsh snippet: emit on prompt as well

Hooking only chpwd means the OSC 7 sequence isn’t sent when a command (e.g., git checkout) changes the directory, or when you first get a prompt after Wave starts in a non-interactive shell startup. Consider also attaching to precmd:

add-zsh-hook precmd _wave_emit_cwd

That guarantees the escape is sent before every prompt.


58-65: Fish snippet: avoid duplicate emissions

Because the --on-variable PWD handler already fires at startup, the explicit call to _wave_emit_cwd right after the function definition can double-emit the sequence. You can drop the explicit call:

-# Emit on startup
-_wave_emit_cwd

Minor, but avoids redundant output.


67-88: wsh getmeta example: clarify BlockId placeholder

The placeholder <block-id> could be mistaken for literally requiring angle brackets. Add back-ticks or an explanatory note, e.g.:

wsh getmeta --block <BLOCK_ID>   # replace <BLOCK_ID> without the <>

Small docs polish that prevents copy-paste errors.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0d339af and a8638ea.

📒 Files selected for processing (2)
  • docs/docs/index.mdx (1 hunks)
  • docs/docs/track-cwd.mdx (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
docs/docs/track-cwd.mdx (1)
Learnt from: esimkowitz
PR: wavetermdev/waveterm#1790
File: cmd/wsh/cmd/wshcmd-readfile.go:34-34
Timestamp: 2025-01-22T01:04:20.614Z
Learning: Path sanitization in Wave Terminal is handled by individual fileshare client implementations rather than at the command level, as different file systems may have different path requirements and formats.
🔇 Additional comments (1)
docs/docs/track-cwd.mdx (1)

52-56: Fish version reference appears inaccurate

Fish is currently at major version 3; version 4.0.0 is not yet released. Stating that “Fish 4.0.0 and later emit OSC 7 by default” may confuse readers. Please verify the minimum version that ships OSC 7 (it’s 3.7+ at time of writing) or phrase it generically (“Fish releases after 3.7”).

Comment on lines 29 to 33
```bash
# Emit OSC 7 on each prompt
export PROMPT_COMMAND='printf "\033]7;file://$HOSTNAME$PWD\007"'
```

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Bash snippet: encode spaces + quote $PWD

printf "\033]7;file://$HOSTNAME$PWD\007" works but breaks when the working directory contains spaces or other URI-reserved chars. Consider URL-encoding the path (as you already do in the Zsh sample) or at least quoting $PWD.

-export PROMPT_COMMAND='printf "\033]7;file://$HOSTNAME$PWD\007"'
+export PROMPT_COMMAND='printf "\033]7;file://%s%s\007" "$HOSTNAME" "${PWD// /%20}"'

This keeps the examples consistent across shells and avoids silent failures in edge cases.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
```bash
# Emit OSC 7 on each prompt
export PROMPT_COMMAND='printf "\033]7;file://$HOSTNAME$PWD\007"'
```
# Emit OSC 7 on each prompt
export PROMPT_COMMAND='printf "\033]7;file://%s%s\007" "$HOSTNAME" "${PWD// /%20}"'
🤖 Prompt for AI Agents
In docs/docs/track-cwd.mdx around lines 29 to 33, the Bash snippet uses printf
with an unquoted $PWD, which can break if the working directory contains spaces
or URI-reserved characters. Fix this by quoting $PWD or applying URL encoding to
it, similar to the Zsh example, to ensure the path is correctly handled and the
example is consistent across shells.

- Updated Bash snippet to use a helper function for interactive shell checks and proper
  redirection to /dev/tty.
- Enhanced Zsh snippet with improved command formatting and added a hook for precmd to ensure
  directory updates before each prompt.
- Modified Fish snippet to align with Bash and Zsh examples by adding redirection to
  /dev/tty.
- Updated inline comments to better explain the purpose of the changes.
- Added a new FAQ section with step-by-step guidance and shell-specific code examples.
- Corrected configuration link from './config.mdx' to './config'.
- Removed the obsolete 'track-cwd.mdx' document
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
docs/docs/faq.mdx (2)

66-73: Variable name inconsistency may break hostname substitution

$HOST (used in Z sh) is not guaranteed to be set on all systems, whereas the Bash snippet uses $HOSTNAME. For portability and consistency, prefer $HOSTNAME (available by default in both Bash and Z sh) or fall back if unset:

printf "\033]7;file://%s%s\007" "${HOSTNAME:-$HOST}" "${PWD// /%20}" > /dev/tty

88-100: Clarify verification instructions to prevent confusion

Step 2 mentions “open a new tab (Alt T / Cmd T, Alt N / Cmd N)”, but earlier shortcuts list Alt N / Cmd N for terminal blocks and Alt T / Cmd T for browser tabs. Consider explicitly stating which shortcut applies to Wave terminal blocks to avoid readers thinking they pressed the wrong keys.

Example tweak:

After configuring, open a new terminal block (Alt N / Cmd N) or split the current pane (Cmd D / Cmd Shift D)…

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a8638ea and e465f54.

📒 Files selected for processing (1)
  • docs/docs/faq.mdx (1 hunks)

- Improved PROMPT_COMMAND handling to avoid clobbering existing values
- Corrected Zsh snippet by replacing $HOST with $HOSTNAME
- Added inline comments to better explain behavior and prevent unintended output
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.

2 participants