You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New terminal opens always in home directory when called from Tilix #2649
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:
Install tilix
Set nushell as the default shell with chsh
Open terminal in tilix
Navigate to some directory
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
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?
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.
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.
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 :(
Also related to this is likely that when Open in Terminal is used on a directory in Gnome, if you set nushell as the shell, it will open only in the home directory (presumably because it uses PWD to indicate where to open at). Should this have a separate issue, or perhaps should this issue be renamed?
This issue is being marked stale because it has been open for 30 days without activity. If you feel that this is in error, please comment below and we will keep it marked as active.
This issue has been marked stale for more than 10 days without activity. Closing this issue, but if you find that the issue is still valid, please reopen.
Depending on the system you're using (on Linux, most distributions apart from Fedora and its derivatives), this issue can potentially affect all terminals based on GNOME VTE. Therefore not only Tilix but also GNOME Terminal and many others.
The problem is well described in the Tilix documentation, together with two possible solutions. However, solution 1 can only be used with Bash or Zsh, while solution 2 (using a login shell) has significant drawbacks. For instance on most distributions (apart from Fedora and its derivatives) a Bash login shell does not source ~/.bashrc.
Fish developers have dealt with the same issue in the past, and it was fixed with this PR. Now Fish notifies VTE at every working directory change. Current code is here.
To fix this issue in Linux, Nushell should behave like Fish.
Theoretically one could construct an osc 7 alias/def and put it in the prompt block that would maybe fix this with people having this issue. Something along the lines of $"(ansi osc)7;file://(localhost)/($nu.cwd)(ansi esc)\"
I tried issuing command printf "\033]7;file://HOSTNAME/CURRENT/DIR\033\\" manually (of course with my actual hostname and working directory), and it works! All following new shells within the same terminal (for instance in new tabs) open in the last issued working directory.
I wonder however why Fish checks the terminal type, and issues this command only on supported terminals. Is it only for performance reasons, or could this command give problems on other systems? I can check it only on Linux and it works flawlessly, maybe you should verify it also on Windows and macOS. I suggest to reopen this issue and fix it.
The terminals have to support osc 7 in order for it to work. I'm not sure how common that is so it may be good to leave it in the hands of the users via a prompt block.
Many Linux terminal emulators are based on VTE. IMHO it would be unfair to treat Linux users differently than the rest of the audience, requiring a hack to make this work. Actually I would expect most of Nushell users to be on Linux, but maybe I'm wrong.
What happens if the OSC 7 escape sequence is printed on a terminal that does not support it? If this is a potential problem, Nushell could check for supported terminals like Fish does.
Hm not sure if this is the same "issue" but just as a hint: I sometimes use the "Open in terminal" in the context menu of the file explorer nautilus. When I switched to nu, I set the default command to /home/myuser/.cargo/bin/nu in the terminal profile of the GNOME terminal. However that opened the shell always in the home directory (as reported for Tilix here) and not in the directory that I wanted it to open in.
The solution was a setting in the GNOME terminal, nothing in nu. Here is a screenshot (sry for the German, it's my private machine). The important setting was "Keep working directory: Always".
Maybe this points someone in the right direction. At least searching for my issue led me to this bug here.
Reacted by Locke Bircher
Reacted by Magnus, Austyn, Taylor Richberger, ROUQUETTE Loïc, Fauzan F A and Locke Bircher
Apple terminal preferences include this helpful description:
The working directory may be set using the Operating System Command (OSC) escape sequence:
ESC ] Ps ; Pt BEL
The parameter Ps is 7 (working directory) and Pt is a “file:” URL. The URL should include a hostname to disambiguate local and remote paths, and characters must be percent-encoded as appropriate.
So what do I need to put into my nushell config? Can I register some callback/closure function whenever it changes directories?
However, OSC7 should just work if you have shell_integration set to true in your config.nu file. Are you saying you have that set and it still doesn't work?
Activity
fdncred commentedon 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 commentedon Oct 21, 2020
It seems like tilix is just calling
PWD=~/dirto 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 commentedon 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
PWDon startup. Although, I did notice that whenset_pathis called it sets thePWDenv var. I'm guessing that somewhere innu-cli/src/cli.rs, perhaps in thefn cli()one would need to check thePWDenv var and use it if found, for this functionality to work like you want it to.zbraniecki commentedon Nov 30, 2020
@fdncred the intro you provided is enough to get new
nushellto use$PWD, yes!This makes the following work:
~/projectsnunushell in~/projectscd my-projectnushell in~/projects/my-projectsThat's exactly as expected!
The final piece of the puzzle I am missing is how does the shell augment the value of
$PWDfor other (newly created) shells?In other words, this doesn't work:
nu~/projectsnushell in~/projectsIt 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
$PWDin a new shell.Anyone has an idea how to approach it?
fdncred commentedon Nov 30, 2020
My guess would be to call
set_pathevery time one uses thecdcommand so that thePWDenv var gets set. I'm not sure that would work but it may be worth a try.zbraniecki commentedon Nov 30, 2020
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
PWDwhen you change directory changesPWDin 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 settingPWDdoes not trigger this cross-session passing ofPWD.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+ais pressed, and passing it to the new terminal asPWD.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 :(
sousajo-cc commentedon Dec 31, 2020
Maybe get the cwd of the parent process and pass it to the new prompt?
ilius commentedon Feb 11, 2021
LXTerminal and xfce4-terminal also work, from bash to nu, and sh to nu!
I think the terminal should set the current directly when running / forking the shell.
And
tilixdoes not do that?I'm not familiar with D language.
But Python has such feature when running a process:
subprocess.Popenhascwdargument.Also here there is a
workDirargument:https://dlang.org/library/std/process/spawn_process.html
Should be possible to fix in
tilix.vadixidav commentedon Apr 9, 2021
Also related to this is likely that when
Open in Terminalis used on a directory in Gnome, if you set nushell as the shell, it will open only in the home directory (presumably because it uses PWD to indicate where to open at). Should this have a separate issue, or perhaps should this issue be renamed?zbraniecki commentedon Jun 18, 2021
I am setting a new machine and was able to reproduce this in Tilix+bash!
Tilix showed a warning pointing at https://gnunn1.github.io/tilix-web/manual/vteconfig/
When I switched to "Run command as login shell" the bug is fixed in bash, but not in nushell.
github-actions commentedon Jul 19, 2021
This issue is being marked stale because it has been open for 30 days without activity. If you feel that this is in error, please comment below and we will keep it marked as active.
vadixidav commentedon Jul 19, 2021
This is still an issue. Including with
Open in Terminalwith Gnome.1 remaining item
github-actions commentedon Oct 29, 2021
This issue has been marked stale for more than 10 days without activity. Closing this issue, but if you find that the issue is still valid, please reopen.
lucatrv commentedon Mar 5, 2022
Depending on the system you're using (on Linux, most distributions apart from Fedora and its derivatives), this issue can potentially affect all terminals based on GNOME VTE. Therefore not only Tilix but also GNOME Terminal and many others.
The problem is well described in the Tilix documentation, together with two possible solutions. However, solution 1 can only be used with Bash or Zsh, while solution 2 (using a login shell) has significant drawbacks. For instance on most distributions (apart from Fedora and its derivatives) a Bash login shell does not source
~/.bashrc.Fish developers have dealt with the same issue in the past, and it was fixed with this PR. Now Fish notifies VTE at every working directory change. Current code is here.
To fix this issue in Linux, Nushell should behave like Fish.
fdncred commentedon Mar 5, 2022
WezTerm has a good writeup on this too https://wezfurlong.org/wezterm/shell-integration.html#osc-7-escape-sequence-to-set-the-working-directory.
Theoretically one could construct an osc 7 alias/def and put it in the prompt block that would maybe fix this with people having this issue. Something along the lines of
$"(ansi osc)7;file://(localhost)/($nu.cwd)(ansi esc)\"lucatrv commentedon Mar 5, 2022
I tried issuing command
printf "\033]7;file://HOSTNAME/CURRENT/DIR\033\\"manually (of course with my actual hostname and working directory), and it works! All following new shells within the same terminal (for instance in new tabs) open in the last issued working directory.I wonder however why Fish checks the terminal type, and issues this command only on supported terminals. Is it only for performance reasons, or could this command give problems on other systems? I can check it only on Linux and it works flawlessly, maybe you should verify it also on Windows and macOS. I suggest to reopen this issue and fix it.
fdncred commentedon Mar 5, 2022
The terminals have to support osc 7 in order for it to work. I'm not sure how common that is so it may be good to leave it in the hands of the users via a prompt block.
lucatrv commentedon Mar 5, 2022
Many Linux terminal emulators are based on VTE. IMHO it would be unfair to treat Linux users differently than the rest of the audience, requiring a hack to make this work. Actually I would expect most of Nushell users to be on Linux, but maybe I'm wrong.
What happens if the OSC 7 escape sequence is printed on a terminal that does not support it? If this is a potential problem, Nushell could check for supported terminals like Fish does.
endigma commentedon Aug 23, 2022
This is still an issue, is there a fix planned?
fdncred commentedon Aug 23, 2022
Have you tried the -e argument to nu?
endigma commentedon Aug 23, 2022
as my login shell?
sgasse commentedon Jan 26, 2023
Hm not sure if this is the same "issue" but just as a hint: I sometimes use the "Open in terminal" in the context menu of the file explorer
nautilus. When I switched tonu, I set the default command to/home/myuser/.cargo/bin/nuin the terminal profile of the GNOME terminal. However that opened the shell always in the home directory (as reported for Tilix here) and not in the directory that I wanted it to open in.The solution was a setting in the GNOME terminal, nothing in
nu. Here is a screenshot (sry for the German, it's my private machine). The important setting was "Keep working directory: Always".Maybe this points someone in the right direction. At least searching for my issue led me to this bug here.

mb21 commentedon Nov 28, 2023
Apple terminal preferences include this helpful description:
So what do I need to put into my nushell config? Can I register some callback/closure function whenever it changes directories?
Adapting @fdncred's comment from March 2022, I do:
But then new tabs just have the prompt
38;5;14mso I must be doing something wrong :Sfdncred commentedon Nov 28, 2023
This is not right
Here's another translation of what I originally said (note the trailing \) - This is called ST or string terminator. All of this is called OSC 7.
However, OSC7 should just work if you have shell_integration set to true in your config.nu file. Are you saying you have that set and it still doesn't work?
mb21 commentedon Nov 28, 2023
Oh, this indeed does the trick on its own:
Thanks a lot for the quick reply!