Repository navigation
Description
Describe the bug
I found a problem that is hard to explain, so please bear with me. It seems like nushell doesn't notify other processes about its current directory, or doesn't start in the proper directory, or something.
If I'm in tmux and I open a new split in the current directory, it actually opens the split in the directory that the initial tmux session was created or joined from.
If I just make a split with my terminal, the same thing happens. I have tried in both wezterm and kitty in an effort to narrow it down and make sure this is actually a nushell problem.
How to reproduce
Here is a hopefully simple example with minimal dependencies.
Working:
- Configure tmux
default-shellto be/usr/bin/bash(even ifdefault-commandis nushell) - Create a new tmux session
cd some-folder- Run
tmux split-window -v -c "#{pane_current_path}"ortmux new-window -a -c "#{pane_current_path}"or something equivalent - Note that the current folder for the new pane is also
some-folderas expected
Not working:
- Configure tmux
default-shellto be/usr/bin/nu - Create a new tmux session
cd some-folder- Run
tmux split-window -v -c "#{pane_current_path}"ortmux new-window -a -c "#{pane_current_path}"or something equivalent - Note that the current folder for the new pane is the original folder, not
some-folder
In tmux specifically I just found that I can work around this issue by having default-command be nushell and default-shell be bash, but ironically I'm trying to phase out my usage of tmux and have not yet found a workaround for my terminal, in which the same problem exists.
Despite this, I used tmux for my example because it is more common, terminal-agnostic, and lets me test different shells without changing my login shell.
Expected behavior
I expect terminals and terminal multiplexers to open nushell at a specific path when using common "open new split/pane/tab/window/whatever in current directory" functionality.
Screenshots
No response
Configuration
| key | value |
|---|---|
| version | 0.60.0 |
| branch | makepkg |
| short_commit | 74af31a |
| commit_hash | 74af31a |
| commit_date | 2022-03-22 19:07:11 +00:00 |
| build_os | linux-x86_64 |
| rust_version | rustc 1.59.0 (Arch Linux rust 1:1.59.0-1) |
| cargo_version | cargo 1.59.0 |
| pkg_version | 0.60.0 |
| build_time | 2022-03-23 00:39:08 +00:00 |
| build_rust_channel | release |
| features | dataframe, default, trash, which, zip |
| installed_plugins |
Additional context
No response
Activity
kubouch commentedon Mar 31, 2022
The only time Nushell modifies external environment is when running an external. Otherwise, Nushell's environment variables are just normal values, like normal variables. Current directory is stored just as a plain PWD environment variable. So it might make sense that tmux does not respect cd because all of this information is internal within the Nushell process.
What we could do is during
merge_delta()(when you hit enter in the REPL), we could also set the current directory withstd::env::set_current_dir().rawsp33d commentedon Mar 31, 2022
Another facet of what you said that I found is that nushell does not seem to project what its currently-running command is.
So for example if you are in tmux and run
nvim, tmux still thinks the running process isnu. Same with a terminal, I just tested having wezterm tell me the foreground process name and even when I'm running vim the process is/usr/bin/nu. If I try the same tests in bash or zsh they both say/usr/bin/nvimis the running process.ryanpcmcquen commentedon Apr 1, 2022
Maybe this is related to my issue?
#4967
fdncred commentedon Apr 1, 2022
it appears that naming processes is a linux thing and not so much a Windows thing. Not sure about Mac.
https://stackoverflow.com/questions/6082189/change-process-name-in-linux - although this link points to a "multi-platform" implementation here.
But if you just want to set the window title, you can do what I do here https://github.com/nushell/nu_scripts/blob/7f8d633ac35064e7833617b4492b26481f589224/prompt/oh-my.nu#L512-L528
rawsp33d commentedon Apr 5, 2022
Well I definitely don't know exactly what I'm doing, but I did try setting the name with prctl in two places.
I tried both the
capctllibrary as well as the much olderprctllibrary.It's hard for me to tell whether I'm not using the libraries correctly, they do not work, I'm trying all of this in the wrong places, or something else entirely.
rawsp33d commentedon Apr 5, 2022
I don't currently understand the "longer" hack that chromium does nor how to implement it in nushell.
I'm just trying to do some exploratory R&D because I need nushell to behave like other shells in this way for my workflow.
kubouch commentedon Apr 5, 2022
Interesting, I would guess it would work by setting it in the
merge_delta()(there shouldn't be a need to put it inevaluate_repl()as well). Seems like setting cwd inmerge_delta()is already there so there must be something else we can do, but I have no idea.rawsp33d commentedon Apr 6, 2022
Okay so I misdiagnosed the second issue as potentially being related to the first. The main problem conveyed in my OP seems to be the same problem as #2649 (closed).
I can open an issue for the second issue I mentioned in a comment above in the future, ideally after I figure out more about it.
danjenson commentedon May 14, 2022
I'm finding this problem too, even using
tmux attach-session -c <dir> -t <sesh>it is reverting to the original tmux session's CWD; hard to say whether this is a nushell or tmux problem, or a combination of the two. Here is a relevant tmux issue: tmux/tmux#3186rawsp33d commentedon May 15, 2022
Yeah I found it only works in tmux if you set your tmux shell to anything other than
nu. By which I mean the internal shell setting. Then even though you're using nu for your shell, tmux uses bash behind the scenes. Unfortunately doesn't help my situation because I moved off tmux, but hopefully helps you.unional commentedon Jun 4, 2022
I think this is related to microsoft/vscode#150153
One problem is
$env.PWDis not commonly used by other processes in Windows environment. So it causes some weird cases as it is not automatically updated.WindSoilder commentedon Jun 11, 2022
@unional Can you please try the latest main build solve your issue?
I can't reproduce it in vscode.
unional commentedon Jun 11, 2022
Yes it is working. Thx!
rawsp33d commentedon Jun 14, 2022
As the issue creator I just wanted to weigh in and confirm: the changes work great! Thank you to everybody involved with this.
Southclaws commentedon Jul 10, 2023
Old ticket I know but I'm running into this on v0.77.1
It might be related to the documentation here https://learn.microsoft.com/en-us/windows/terminal/tutorials/new-tab-same-directory the post-prompt echo might fix it but I can't find any documentation on what exactly to do for NuShell + Windows Terminal.
Perhaps this is just a matter of documentation? Would love to get this working for split panes!
fdncred commentedon Jul 10, 2023
This works with how the link shows already (right click -> duplicate tab), but it doesn't work with split panes. I'm not sure why.
Update: I take it back. If nushell is launched as the shell versus a subshell of pwsh or cmd or whatever, and you right click the tab and click split pane, the new nushell will start in the same folder as your left pane.
Southclaws commentedon Jul 10, 2023
I'm not having any luck with either (both updated to latest version just now)
Recording.2023-07-10.152008.mp4
And the starting command for the actual shell is
nuitself, not a different shell running nu as a child process.Perhaps this is specific to Windows Terminal rather than a linuxy escape-sequence type thing though, is it worth opening a separate issue?
fdncred commentedon Jul 10, 2023
I think I may have figured it out. I'm running Windows Terminal Preview v1.18.1462.0. I bet you're running the normal Windows Terminal. I'm guessing OSC7 that sets this is not in Windows Terminal and only the preview maybe?