-
Notifications
You must be signed in to change notification settings - Fork 119
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
Introduce cd command #971
Introduce cd command #971
Conversation
0d273f3
to
4ac5305
Compare
I love this. Anytime I try to teach someone they can use |
HELP | ||
|
||
def execute(arg) | ||
case arg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about the cd -
case? As in, go to the previous but also push the current back on the stack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike the rest of the PR that's built on top of existing features, this requires adding new internal API and will not work nicely with other workspace commands like pushws
...etc. I implemented it anyway but I'll let other maintainers decide if it's worth the extra complexity.
lib/irb/command/cd.rb
Outdated
when ".." | ||
irb_context.pop_workspace | ||
when "-" | ||
irb_context.replace_workspace(irb_context.previous_workspace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To support this, we need a way to remember popped workspaces too. And because commands are not memoized, we can't use ivars here. So I needed to add a new previous_workspace
attribute to Context
just for this feature. Additionally, it will not work with other commands like pushws
or chws
without adding further complexities.
While I understand its use cases, I personally don't use it. So either keeping or dropping it is fine for me. Thoughts? @ruby/irb-reline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth adding, or maybe we can add it later. Not particular about keeping or dropping it at the first step.
Since cd
has a stack that represents directory-like model, I think cd -
should restore the whole stack, not just the current workspace.
cd 1 # 1
cd 2 # 1/2
cd 3 # 1/2/3
cd .. # 1/2
cd - # 1/2/3
cd # main
cd - # 1/2/3
cd .. # 1/2
And we need to consider irb_context.previous_workspace==nil
case.
$ irb
irb(main):001> cd -
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. I'll update my implementation 👍
I believe this is incorrect, based on both the assumption that this works similarly to when ".."
irb_context.pop_workspace Popping does not necessarily take you to the previous workspace. You could be where you are because of using |
Thanks for the great PR 💛 Currently, this PR doesn't support |
It'll be the previous workspace on the same workspace stack. In this context, previous means the previous value that's been added to the stack (array). I know it's not perfectly accurate, but I can't think of better description for it and I'm open to better ideas 🙂
Unfortunately I don't plan to introduce nested syntax atm, such as |
5c14c0e
to
00a1a3d
Compare
It's essentially a combination of pushws and popws commands that are easier to use. Help message: ``` Usage: cd ([target]|..) IRB uses a stack of workspaces to keep track of context(s), with `pushws` and `popws` commands to manipulate the stack. The `cd` command is an attempt to simplify the operation and will be subject to change. When given: - an object, cd will use that object as the new context by pushing it onto the workspace stack. - "..", cd will leave the current context by popping the top workspace off the stack. - no arguments, cd will move to the top workspace on the stack by popping off all workspaces. Examples: cd Foo cd Foo.new cd @ivar cd .. cd ```
00a1a3d
to
b10c68c
Compare
I couldn't 100% replicate Prys' |
(ruby/irb#971) It's essentially a combination of pushws and popws commands that are easier to use. Help message: ``` Usage: cd ([target]|..) IRB uses a stack of workspaces to keep track of context(s), with `pushws` and `popws` commands to manipulate the stack. The `cd` command is an attempt to simplify the operation and will be subject to change. When given: - an object, cd will use that object as the new context by pushing it onto the workspace stack. - "..", cd will leave the current context by popping the top workspace off the stack. - no arguments, cd will move to the top workspace on the stack by popping off all workspaces. Examples: cd Foo cd Foo.new cd @ivar cd .. cd ``` ruby/irb@4a0e0e89b7
Document `cd object` and `cd ..` commands introduced in 1.14.0 by ruby#971
Document `cd object` and `cd ..` commands introduced in 1.14.0 by ruby#971
Document `cd object` and `cd ..` commands introduced in 1.14.0 by ruby#971
Document `cd object` and `cd ..` commands introduced in 1.14.0 by ruby#971
Document `cd object` and `cd ..` commands introduced in 1.14.0 by ruby#971
Document `cd object` and `cd ..` commands introduced in 1.14.0 by #971
It's essentially a combination of
pushws
andpopws
commands that are easier to use.Help message:
Please note that it's not a replica of Pry's
cd
command as it doesn't support the/
argument, nor complicated navigation syntax.