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

Add support cd - got to prev directory #167

Merged
merged 2 commits into from
Nov 19, 2019
Merged

Add support cd - got to prev directory #167

merged 2 commits into from
Nov 19, 2019

Conversation

kirillsalykin
Copy link
Contributor

@kirillsalykin kirillsalykin commented Nov 12, 2019

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 builtin terminal doesn't.
(I am on mac os)

For me iTerm2 behavior feels more natural, but maybe you have other thoughts?

Thanks.

Copy link
Owner

@dundalek dundalek left a 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.

(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]]}))
Copy link
Owner

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?

Copy link
Contributor Author

@kirillsalykin kirillsalykin Nov 13, 2019

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.

Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Owner

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.

@dundalek dundalek merged commit 8ee01aa into dundalek:master Nov 19, 2019
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.

Support cd - to go to previous directory
2 participants