skip to Main Content

I want to pass a hash value of ${cwd} to invoke tmux new -A -s in an integrated terminal profile.

I tried various forms of "$(…)", like so:

    "terminal.integrated.profiles.osx": {
        "tmux": {
            "path": "/usr/local/bin/tmux",
            "args": [
                "new",
                "-A",
                "-s",
                "$(md5sum <<<${cwd} | cut -d ' ' -f 1)"
            ]
        },
    },

When this profile is invoked, a tmux session does start, but its name is the literal $(md5sum <<</Users/USER/PATH/TO/CWD | cut -d ' ' -f 1), which is hard to work with.

2

Answers


  1. Chosen as BEST ANSWER

    Using @starball's suggestion, I wrote a simple wrapper:

    #! /bin/zsh
    exec tmux new -A -s $(md5sum <<<$1 | cut -d ' ' -f 1)
    

    and its invocation via settings.json:

        "terminal.integrated.profiles.osx": {
            "tmux": {
                "path": "${userHome}/local/bin/tmux-vscode",
                "args": [
                    "${cwd}"
                ]
            },
        },
    

    Now I have:

    $ tmux ls
    231309d1a2b2cc0f38adf8e95440c11b: 1 windows (created Mon Nov  6 08:56:18 2023) (attached)
    cc0c79461a3bc1ffe210da0d763d93b3: 1 windows (created Mon Nov  6 08:54:23 2023) (attached)
    

  2. I’d suggest to try writing a wrapper script for that command and use that wrapper script in the path property. You’ll probably need to give your wrapper script a shebang for the shell it needs. Also, in case you need it, here‘s the VS Code variable reference.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search