Skip to content

Improve primary shell activation heuristics #43

@MatthijsBurgh

Description

@MatthijsBurgh

I asked our friends from ChatGPT for a robust check.

It suggested the following:

import os
import subprocess

def parent_process_name():
    ppid = os.getppid()
    try:
        return subprocess.check_output(
            ["ps", "-p", str(ppid), "-o", "comm="],
            text=True
        ).strip()
    except Exception:
        return None

parent = parent_process_name()
print(parent)  # likely "pwsh"

os.getppid should also be available on Windows. I am not so sure about ps. Depending on the availability of ps on Windows, this check can also be used on Windows, otherwise only on unix systems.

update: It is not available on Windows.

I think this is an improvement compared to the current heuristics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions