Skip to content

feat(cd): add relative path navigation#14

Merged
Pawank06 merged 2 commits intomainfrom
feature/cd-relative-paths
Jan 9, 2026
Merged

feat(cd): add relative path navigation#14
Pawank06 merged 2 commits intomainfrom
feature/cd-relative-paths

Conversation

@Pawank06
Copy link
Owner

@Pawank06 Pawank06 commented Jan 9, 2026

summary

  • add support for changing directories using relative paths

notes

  • complements existing absolute path handling
  • brings cd closer to standard unix shell behavior

@coderabbitai
Copy link

coderabbitai bot commented Jan 9, 2026

📝 Walkthrough

Walkthrough

Unifies cd command path handling in src/main.rs by removing the absolute-path special case and always constructing, validating, and attempting to change to the computed path (existence and directory checks preserved; errors still reported with path and error).

Changes

Cohort / File(s) Summary
CD command path handling refactor
src/main.rs
Removed special-case branch for absolute paths; always builds full_path from args, checks exists() and is_dir(), then calls env::set_current_dir(full_path) with existing error reporting. Pay attention to path construction and error messages around set_current_dir.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

Poem

🐰 A path once tangled, now runs clean,
I hop through dirs with a single scene,
No forks to fret, no branches wide,
One tidy flow to guide my stride,
🥕✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title claims to 'add relative path navigation', but the actual changes unify path handling by removing special-case branches, not adding new relative path support. Revise the title to accurately reflect the refactoring work, such as 'refactor(cd): simplify path handling' or 'refactor(cd): unify absolute and relative path logic'.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@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

🤖 Fix all issues with AI agents
In @src/main.rs:
- Around line 84-86: Remove the unused local `query` by deleting the line `let
query = parts[1];` and keep the existing `let args = &parts[1..];` / `let
full_path = args.join(" ");` logic; verify no other references to `query` remain
(search for `query` usage) and run the build to ensure nothing else depends on
that variable.
🧹 Nitpick comments (1)
src/main.rs (1)

88-97: Unified path handling works correctly for both absolute and relative paths.

The refactored logic consolidates path validation and directory change into a single flow. The existence and directory type checks before attempting env::set_current_dir provide appropriate error handling.

Optional: Consider using full_path for consistency in the error message.

Line 95 uses path.display() while lines 90 and 92 use full_path directly. For consistency, consider:

♻️ Optional consistency improvement
                 if let Err(e) = env::set_current_dir(&full_path) {
-                    eprintln!("cd: {} {}", path.display(), e);
+                    eprintln!("cd: {}: {}", full_path, e);
                 }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a6226d5 and d5185d6.

📒 Files selected for processing (1)
  • src/main.rs

Copy link

@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: 0

🧹 Nitpick comments (1)
src/main.rs (1)

80-82: Consider supporting home directory navigation.

Standard Unix shells change to the home directory when cd is invoked without arguments. Currently, the shell simply continues without action.

This is an existing limitation not introduced by this PR, but enhancing it would align better with expected shell behavior.

💡 Potential enhancement
             "cd" => {
-                if parts.len() < 2 {
-                    continue;
-                }
+                let target_path = if parts.len() < 2 {
+                    // Default to HOME directory when no args provided
+                    match env::var("HOME") {
+                        Ok(home) => home,
+                        Err(_) => {
+                            eprintln!("cd: HOME not set");
+                            continue;
+                        }
+                    }
+                } else {
+                    let args = &parts[1..];
+                    args.join(" ")
+                };
 
-                let args = &parts[1..];
-                let full_path = args.join(" ");
+                let full_path = target_path;
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d5185d6 and ab44722.

📒 Files selected for processing (1)
  • src/main.rs
🔇 Additional comments (2)
src/main.rs (2)

84-85: Path construction correctly handles both absolute and relative paths.

The unified approach of joining arguments and using Path::new works correctly for both path types. Joining with spaces allows directory names containing spaces to work, which is reasonable given the simple whitespace-based tokenization.


87-96: Path validation logic correctly checks existence and directory status before directory change.

The code properly handles both absolute and relative paths. Path::new creates a Path object correctly, and env::set_current_dir resolves relative paths against the current working directory. Error messages are clear and the error handling on line 93 catches any issues that occur during the actual directory change operation.

Consider verifying the implementation with tests for various path formats:

  • Relative paths: ., .., ../subdir, subdir
  • Absolute paths: /tmp, /home/user
  • Paths with special characters

@Pawank06 Pawank06 merged commit e2a9ea3 into main Jan 9, 2026
2 checks passed
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.

1 participant