nushell / nushell/nushell

Platform-dependent command to detect if nushell is running in the foreground or background

Open
#15,445 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

category:enhancement status:needs-triage
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-

  1. Implement an is-foreground boolean function, in the same style as is-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.

  1. On Linux it might also be desirable to implement an is-interactive test, as I believe foreground, interactive, and connected to controlling terminal (the is-terminal command) 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.