Skip to content

Make nushell set/forward/proxy currently running process like other shells #6156

Closed

Description

@rawsp33d

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

  1. rgwood commented on Jul 27, 2022

    @rgwood
    Contributor

    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 nvim personally; screenshots might help?

  2. nibon7 commented on Jul 28, 2022

    @nibon7
    Contributor
    • xterm+zsh+nvim
      Screenshot from 2022-07-28 08-21-05

    • xterm+nu+nvim
      Screenshot from 2022-07-28 08-21-22

  3. nibon7 commented on Jul 28, 2022

    @nibon7
    Contributor
    • xterm+tmux+zsh+nvim
      Screenshot from 2022-07-28 08-29-48

    • xterm+tmux+nu+nvim
      Screenshot from 2022-07-28 08-30-32

  4. WindSoilder commented on Jul 28, 2022

    @WindSoilder
    Contributor
  5. fdncred commented on Jul 28, 2022

    @fdncred
    Contributor

    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.

  6. rawsp33d commented on Jul 28, 2022

    @rawsp33d
    Author

    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() where child comes from Command@spawn, but I wasn't able to get it working.

  7. fdncred commented on Jul 28, 2022

    @fdncred
    Contributor

    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.

  8. rawsp33d commented on Jul 29, 2022

    @rawsp33d
    Author

    @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 bash and the bottom is nushell.

    • neovim

    Screen Shot 2022-07-28 at 10 15 17 PM

    • vim

    Screen Shot 2022-07-28 at 10 17 48 PM

    Screen Shot 2022-07-28 at 10 19 50 PM

    • sleep 1 - no screenshot but you get the idea. Bash and other shells show sleep, 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.

  9. rawsp33d commented on Jul 29, 2022

    @rawsp33d
    Author

    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, and sleep.
    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 😅.

  10. rawsp33d commented on Jul 29, 2022

    @rawsp33d
    Author

    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.

    • just in the shell

    Screen Shot 2022-07-28 at 11 29 27 PM

    • neovim

    Screen Shot 2022-07-28 at 11 32 26 PM

    • vim

    Screen Shot 2022-07-28 at 11 33 20 PM

    • sleep 10

    Screen Shot 2022-07-28 at 11 34 10 PM

  11. fdncred commented on Jul 29, 2022

    @fdncred
    Contributor

    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.

    1. process only
    2. full path process name
    3. user@host: process only
    4. pwd: process
    5. and on and on
  12. rawsp33d commented on Jul 29, 2022

    @rawsp33d
    Author

    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.

  13. fdncred commented on Jul 29, 2022

    @fdncred
    Contributor

    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.

  14. added this to the v0.67.0 milestone on Aug 2, 2022
  15. reopened this on Aug 9, 2022
  16. reopened this on Aug 9, 2022
  17. fdncred commented on Aug 9, 2022

    @fdncred
    Contributor

    #6206 appears to be the cause of weird inconsistent testing failures and also intermittently suspending nushell when executing commands.

  18. modified the milestones: v0.67.0, v0.68.0 on Aug 17, 2022
  19. WindSoilder commented on Sep 13, 2022

    @WindSoilder
    Contributor

    We need to reopen this due to #6273 is reverted

  20. reopened this on Sep 13, 2022
  21. webbedspace commented on Oct 27, 2022

    @webbedspace
    Contributor

    Quick question: is there something preventing this feature from being applied to Windows systems?

  22. WindSoilder commented on Oct 27, 2022

    @WindSoilder
    Contributor

    Windows doesn't have the scenario like this, so the pr shouldn't affect anything on windows

  23. WindSoilder commented on Oct 27, 2022

    @WindSoilder
    Contributor

    (oh, this issue can be closed I think)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions