Platform-dependent command to detect if nushell is running in the foreground or background
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 40.5k
- Forks
- 2.3k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 79
Description
Related problem
A script or command may need to change behaviour depending on it's forground/background status, e.g. only printing debug output, progress info. or prompts for input when in the foreground (connected to a controlling terminal), vs. writing to the system log or journal when in the background.
This is non-trivial to determine (at least on Linux), and very platform-dependent.
This seems like a good candidate for a dedicated Nushell command to abstract out the platform-dependent elements.
Describe the solution you'd like
As an initial suggestion-
- Implement an
is-foregroundboolean function, in the same style asis-terminal. The underlying logic required, for Linux is:
To determine if the process is running in the foreground, check if the process group (pgrp) is the same as the process group id associated with the session's controlling terminal
(ref. How can a bash script detect if it is running in the background?)
On the Windows platform, a process running in the background can detect it's status by looking at the controlling Session ID, which is zero (0) for background tasks. It would seem reasonable to suggest this test can simply be negated (i.e. foreground = Session_ID > 0) but that would need to be confirmed.
- On Linux it might also be desirable to implement an
is-interactivetest, as I believeforeground,interactive, andconnected to controlling terminal(theis-terminalcommand) are distinct concepts. However I don't know how well those concepts translate across other platforms.
Describe alternatives you've considered
No response
Additional context and details
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing Nushell's existing is-terminal command and how platform-specific process information is accessed. Compare the proposed Linux process-group check with the Windows Session ID approach, and clarify how foreground, interactive, and controlling-terminal states should differ. Done means a documented cross-platform behavior and tests covering the supported platforms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli, operating-systems
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100