X Tutup
The Wayback Machine - https://web.archive.org/web/20201207141348/https://github.com/nushell/nushell/issues/2649
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

New terminal opens always in home directory when called from Tilix #2649

Open
zbraniecki opened this issue Oct 8, 2020 · 6 comments · May be fixed by #2771
Open

New terminal opens always in home directory when called from Tilix #2649

zbraniecki opened this issue Oct 8, 2020 · 6 comments · May be fixed by #2771

Comments

@zbraniecki
Copy link

@zbraniecki zbraniecki commented Oct 8, 2020

Describe the bug
When a terminal is open to some directory in Tilix and I open a new one, bash and zsh will open it in the same directory as the previous terminal, but after setting Nushell as the default it always opens in home directory.

To Reproduce
Steps to reproduce the behavior:

  1. Install tilix
  2. Set nushell as the default shell with chsh
  3. Open terminal in tilix
  4. Navigate to some directory
  5. Call New Terminal (ctrl+shift+a in my case)

Expected behavior
New terminal opens in the same directory as the previous one.

Configuration (please complete the following information):

  • OS (e.g. Windows): Ubuntu 20.04
  • Nu version (you can use the version command to find out): 0.20
@fdncred
Copy link
Collaborator

@fdncred fdncred commented Oct 8, 2020

It looks like tilix must be passing the path to the terminal but I'm not sure exactly how it works under the hood.

@zbraniecki
Copy link
Author

@zbraniecki zbraniecki commented Oct 21, 2020

It seems like tilix is just calling PWD=~/dir to set the current working dir and bash/zsh accept it while NuShell does not.

Gnome Terminal seems to be using some other strategy because it works with Nushell (a'ka, it opens new tab in the current dir). Can someone tell me how Nushell wants to be informed about the dir in which to open?

@fdncred
Copy link
Collaborator

@fdncred fdncred commented Oct 21, 2020

I looked into this a bit and it doesn't appear the nushell looks for or knows about an environment variable called PWD on startup. Although, I did notice that when set_path is called it sets the PWD env var. I'm guessing that somewhere in nu-cli/src/cli.rs, perhaps in the fn cli() one would need to check the PWD env var and use it if found, for this functionality to work like you want it to.

@zbraniecki
Copy link
Author

@zbraniecki zbraniecki commented Nov 30, 2020

@fdncred the intro you provided is enough to get new nushell to use $PWD, yes!

This makes the following work:

  • Open terminal with bash
  • go to ~/projects
  • Set in Tilix that new terminal is nu
  • ctrl+a to open new terminal
  • Tilix opens new terminal with nu shell in ~/projects
  • in bash cd my-project
  • ctrl+a
  • Tilix opens new terminal with nu shell in ~/projects/my-projects

That's exactly as expected!

The final piece of the puzzle I am missing is how does the shell augment the value of $PWD for other (newly created) shells?

In other words, this doesn't work:

  • Set in Tilix that new terminal is nu
  • Open terminal with nushell
  • go to ~/projects
  • ctrl+a to open new terminal
  • Tilix opens new terminal with nu shell in ~/projects

It seems that in Gnome there's some game around something called VTE:

I don't know how bash/zsh inform VTE to save the current directory so that it gets extracted as $PWD in a new shell.

Anyone has an idea how to approach it?

@zbraniecki zbraniecki linked a pull request that will close this issue Nov 30, 2020
@fdncred
Copy link
Collaborator

@fdncred fdncred commented Nov 30, 2020

My guess would be to call set_path every time one uses the cd command so that the PWD env var gets set. I'm not sure that would work but it may be worth a try.

@zbraniecki
Copy link
Author

@zbraniecki zbraniecki commented Nov 30, 2020

My guess would be to call set_path every time one uses the cd command so that the PWD env var gets set. I'm not sure that would work but it may be worth a try.

I tried to plug that into filesystem_shell.rs::cd and it didn't work. And I don't think it should. Environmental variables are per-shell-session, so setting PWD when you change directory changes PWD in that particular terminal session.

Opening a new one, somehow either Tilix would have to "pick up" the PWD of the previous session and pass it to the new one (I tested if Tilix passes any env::args - it doesn't), or there has to be some system that sets the default PWD value for a new terminal.

It seems to me that somehow bash/zsh do that and that's why with my patch newly opened nushell has the right PWD, but at the same time nushell just setting PWD does not trigger this cross-session passing of PWD.

My intuition tells me that since we don't want any new terminal to use the path, just the terminal opened from the given terminal, that it should be Tilix taking the PWD of the terminal in focus when ctrl+a is pressed, and passing it to the new terminal as PWD.

But, knowing POSIX, I expect my logic to not hold. :)

@gnunn1 - can you shed some light on how to do this properly? I suspect some black-VTE magic to be involved :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.
X Tutup