-
Notifications
You must be signed in to change notification settings - Fork 66
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
Add support cd -
got to prev directory
#167
Add support cd -
got to prev directory
#167
Conversation
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.
Very cool 👍 I have one question as inline comment.
src/common/closh/zero/builtin.cljc
Outdated
(process/chdir (str dir)) ; Extra (str ..) to handle case when directory name is a number | ||
(setenv "PWD" (process/cwd)) | ||
(when go-back? | ||
(core/shx "pwd" [] {:redir [[:set 0 :stdin] [:set 2 :stderr] [:set 1 :stdout]]})) |
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.
Do we need this or is it left over from debugging?
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.
We do need this.
According to the docs cd -
should behave as cd $OLDPWD && pwd
(besides settings env) - thus we need to print pwd (maybe in a different way tho).
(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cd.html
found here https://unix.stackexchange.com/questions/330876/difference-between-cd-and-cd)
Also, it seems a bit tricky how it can be tested (pwd
output)
Should stdout be mocked for each env?
Please advice how you think it can be tested.
Thanks.
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 see, that's a good point. Traditional shells print to stdout, but I think we could try to just return the new PWD
value instead of env/success
. It will still get printed out when used on the command line. And it should be easier to test.
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.
hey @dundalek ,
returning PWD
indeed prints it, but it is printed via prn
thus string is quoted, like this: "/Users/kirill.salykin/projects/closh"
. (which is not the way how other shells do this)
This is seems done by rebel.
What do you think?
Thanks.
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.
It may be fixed with something like this:
(defn repl-print
[& args]
(if (string? (first args))
(println (first args))
(when-not (or (nil? (first args))
(identical? (first args) env/success)
(process? (first args)))
(apply syntax-highlight-prn args))))
Shall I go for this?
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 I kinda like it that it is printed as a string, feels more structured. I think it is good for now, if it causes any trouble in the future we can change it to println.
closes #166
This PR add support for
cd -
.Implementation based on https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cd.html.
In case if
$OLDPWD
is not set up -~
used.iTerm2
also uses same approach (with~
as default), but builtinterminal
doesn't.(I am on mac os)
For me
iTerm2
behavior feels more natural, but maybe you have other thoughts?Thanks.