swiftlang / swiftlang/swift-subprocess

[Feature] Support "shell" parameter to `Executable.file`

Open
#69 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Swift
Stars
734
Forks
68
Avg merge
9d 2h
Merged PRs (30d)
6

Description

Is your feature request related to a problem? Please describe.

It's quite common to need to run a command through the user's shell - in order to get access to whatever path they have set up in their various profile scripts.

Let's say the user has cowsay installed via homebrew (likely installed at /opt/homebrew/bin/ on Apple Silicon Macs) then:

try await run(.name("cowsay"))

Will fail because it can't find cowsay in the user's path.

Describe the solution you'd like

What I think is the best solution to this would to provide an API like that works like this:

try await run(.name("cowsay", shell: .user))

The shell parameter would instruct Subprocess to look up the user's shell via getpwuid and effectively convert the command into the following, selecting the user's shell as appropriate, and running it through the shell with -l as a login shell.

/opt/homebrew/bin/fish -l -c cowsay

Describe alternatives you've considered

It's possible for user code to do themselves or to provide UI for the user to specify their shell. But this feels something that Subprocess should provide.

Additional context
I am not sure how this should work on Windows.
Also the -l -c and/or other shell arguments impose some complexity on how the final arguments are constructed.

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 at the Executable.file API and the run entry point, then trace the platform-specific process-spawning paths. Decide how the user-shell lookup and shell arguments should work across supported platforms, including Windows; done means the API behavior and argument construction are defined and covered by appropriate tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.