Skip to content

Feature request: Inherit CWD and runtime environment #241

@pbsds

Description

@pbsds

I love this. shpool is simple and really close to what I've been looking for.

Quite often however, I want something simple to prefix my commands with so I can reattach to it should I lose my connection or by accident close/crash the terminal emulator. With this in mind I find that shpool has two shortcomings:

  1. --cmd only accepts a single string and not a list of strings, meaning the caller has to escape their command.

    Tools like xargs and pueue accept a list of strings which it simply joins with a space, optionally escaping each part first.

  2. shpool runs the command without inheriting the current working directory nor the runtime environment variables, meaning such has to be re-established before the command can be run.

This is my current workaround in bash:

run_in_shpool() (
    TMP_ENV_FILE="$(mktemp)"
    { 
        declare -p # this one is overkill. Remove it if you don't need support for local bash variables, arrays and functions
        export -p 
    } >"$TMP_ENV_FILE"
    local uid="$(date '+%Y-%m-%d-%H:%M:%S')"
    set -x
    shpool attach "session-$uid" -c "bash -ilc \"source ${TMP_ENV_FILE%Q} 2>/dev/null; cd ${PWD%Q}; ${*@Q}\""
)

run_in_shpool echo foo bar baz

related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions