Repository navigation
Description
Related problem
In most common or modern shells, when you run a program the foreground process name is the program that was run. For example, if you run nvim, the foreground process name in most shells becomes nvim.
After some light field research, I found this to be true for the following shells:
- bash
- zsh
- ion
- xonsh
And not true for the following shells:
- nushell
- elvish
In nushell, when I run nvim, the foreground process name remains /usr/bin/nu. The title also remains unchanged, which may or may not be related.
This may be the same problem brought up in #3861 though they explicitly tie the issue to tmux, while I believe it is more general than tmux. But it's possible the foreground process name and the "title" need to be handled differently, so consider this an issue solely for the former.
Describe the solution you'd like
When I run nvim or any other program, I would like the foreground process name to reflect the running/active process rather than always remaining /usr/bin/nu or whatever the nu path is in a given environment.
Describe alternatives you've considered
No response
Additional context and details
I get that it may be difficult to pull off but I think we should heavily consider it regardless, because it's one of those things that prevents nushell from doing things that most or all other shells do.
For example the entire vim-tmux-navigator workflow is extremely common for people that use vim and tmux, which makes mappings that do different things based on whether vim is the running process. This kind of thing is just not possible using nushell. As it stands, you cannot introspect running programs whatsoever and thus cannot make any sort of conditional mappings.
I did a little bit of research here prompted by @fdncred and @rgwood on discord. As I mentioned there, ion is an open-source shell that does this as expected and is also written in Rust, so it may be a good place to dig into for inspiration. I tried doing so for quite a few hours, trying various things with capctl, prctl, nix, proctitle, and whatever else I thought might be able to help us. In my case I think it's both a matter of not knowing what to do as well as not knowing where to do it, so I'm hoping somebody that knows much more about at least the latter can take this on.
Activity
rgwood commentedon Jul 27, 2022
Thanks for the issue, I apologize but I still have a very poor understanding of this. I'm not sure what you mean by "foreground process name" and how you're checking the foreground process name.
I don't use
nvimpersonally; screenshots might help?nibon7 commentedon Jul 28, 2022
xterm+zsh+nvim

xterm+nu+nvim

nibon7 commentedon Jul 28, 2022
xterm+tmux+zsh+nvim

xterm+tmux+nu+nvim

WindSoilder commentedon Jul 28, 2022
I think it's linux specific thing, and it's relative to these sys call after looks into
fishimplementation:fdncred commentedon Jul 28, 2022
If all we're doing ok a setting the window title based off of the last command ran, then it's no big deal. We're already setting the window title now with the abbreviated pwd.
rawsp33d commentedon Jul 28, 2022
From my earlier experimentation I think @WindSoilder may be correct. I was trying to set the process group but I couldn't figure out how to get the PID from the child process we spawn in run_external.rs. Based on the std lib docs it seemed like I should be able to call
child.id()wherechildcomes from Command@spawn, but I wasn't able to get it working.fdncred commentedon Jul 28, 2022
I'm just saying that the screenshots above look like they're just setting the title "user@host: cmd_line_app", which is easy to do and can be tested without changing any rust code since this relies on ansi escape sequences.
If we're wanting to make pid name changes, which seems bizarre to me (although linux does bizarre stuff regularly), then my first concert is about being cross platform. If windows isn't supported, which I doubt it is, then we might still allow a PR for Mac/Linux only.
Does vim do this? It doesn't seem to change when I launch Activity Monitor or ps on my Mac and run nu then run vim.
rawsp33d commentedon Jul 29, 2022
@fdncred it's not just a Linux thing. The same situation exists on Mac. I wouldn't say "vim does this" as much as "this happens with vim as well". Any program you run has its own process name, and most terminals on most OSs forward or proxy the name through to the point where it would show up as the foreground process.
Here are some screenshots from a brand new M1 Macbook that I just set up this week for work. In all of these, the top terminal is running
bashand the bottom isnushell.sleep 1- no screenshot but you get the idea. Bash and other shells showsleep, nushell does not.None of these examples are using tmux or doing anything weird, merely opening a terminal and running a command. I took them from my Macbook to show that this is not just a Linux situation. I didn't know that for what it's worth---I don't use my Mac nearly as much and tried it just now for science.
It's not my terminal, as I have tried this on many (can't easily screenshot from my Linux computer right now, but can provide if desired). It's not specific to Tmux like #3861 thought it was. It's not OS-specific, and it's not really program specific. I would expect any long-running process to have this behavior. Actually any process at all, but for short ones you just wouldn't see it.
The only difference is the shells.
rawsp33d commentedon Jul 29, 2022
Oh no! I got carried away with finding out this problem happens on Mac too and accidentally conflated two different things. What you see in my screenshots (in both the title bar and the tab bar) is actually the process "title". It's a subtle difference, or maybe it's not, but in the testing I was doing on Linux I was talking more about and caring more about the foreground process name. Nushell doesn't set/update/change either of them so it's easy to confuse the two.
The tangible difference is that the process name for those commands for Bash would be, in order:
nvim,vim,tig, andsleep.In Nushell they are:
/usr/bin/nu,/usr/bin/nu,/usr/bin/nu, and/usr/bin/nu.This was not captured in my screenshots because frankly I don't know my way around macos well enough to even inspect the processes 😅.
rawsp33d commentedon Jul 29, 2022
Okay here we go. I spent some time getting more familiar with the macbook and have some screenshots showing the process in addition to the title in order to avoid conflating the two again. In these, the process is in the top right in the red status bar thing. The left side in that red block is the basename of the process (which I'm stripping myself with regex for readability), and the right side in square brackets is the full unadulterated foreground process name. The titlebar and the tab name are both showing the title as they did in my prior screenshots.
sleep 10fdncred commentedon Jul 29, 2022
This last post is helpful @rosshadden. Thank you. It's much more explanatory. I'm still of the opinion that this can be accomplished or maybe simulated by getting the last command you type and setting it to the tab title. The question is what configuration should be used.
In these most recent screenshots it's just the process but it others it can have more information like.
rawsp33d commentedon Jul 29, 2022
I definitely want to stress that setting a title would not satisfy the full need here. Maybe it's a starting point, but without scripts being able to introspect what is running from nushell, it prevents doing many things people I guess take for granted in other shells.
My screenshots show both titles and the currently-running command. Both are useful for different purposes. If I had to give a concise difference I would say that title is more informational, whereas the command being run is much more useful for scripting and introspection. Conditional mappings, for example, wouldn't actually be reliable if based on the window title because anything can set the title to anything.
fdncred commentedon Jul 29, 2022
I appreciate your points. I do not have this need at all, but I do understand that you and other have this need in a shell. So, I'm not trying to diminish what you're asking for at all. I'm just trying to come up with easy fixes, so we don't have to do root canal on nushell or other processes.
Perhaps a cross platform way of doing this would be to set an environment variable that contains the "last ran command". That way you could see what command is running externally (not just a tab title), whether it's an internal nushell command or an external command.
If people require it be implemented by changing the process name (or however it's done) on Mac and Linux, then so be it. Personally, I have no problem with that. Someone just needs to figure out exactly how to do it and submit a PR for review (obviously). It may or may not be accepted. I figure it would, but it just depends on the impact and if we want to accept a non-cross platform change on a shell that claims to be cross platform.
fdncred commentedon Aug 9, 2022
#6206 appears to be the cause of weird inconsistent testing failures and also intermittently suspending nushell when executing commands.
WindSoilder commentedon Sep 13, 2022
We need to reopen this due to #6273 is reverted
webbedspace commentedon Oct 27, 2022
Quick question: is there something preventing this feature from being applied to Windows systems?
WindSoilder commentedon Oct 27, 2022
Windows doesn't have the scenario like this, so the pr shouldn't affect anything on windows
WindSoilder commentedon Oct 27, 2022
(oh, this issue can be closed I think)