Skip to main content
portability for shells using test.
Source Link
Chris Down
  • 130.3k
  • 26
  • 277
  • 268

You can emulate this with a shell function, this should work for any POSIX-compliant shell:

tmux() {
    if [ "$1" == -z ]; then
        shift
        command tmux detach 2>/dev/null
        command tmux attach "$@" || command tmux new-session "$@"
    else
        command tmux "$@"
    fi
}
tmux() {
    if [ "$#" -ge 1 ] && [ "$1" = -z ]; then
        shift
        command tmux detach 2>/dev/null
        command tmux attach "$@" || command tmux new-session "$@"
    else
        command tmux "$@"
    fi
}

Now if you launch it as tmux -z, it should perform the actions you're looking for.

You can emulate this with a shell function, this should work for any POSIX-compliant shell:

tmux() {
    if [ "$1" == -z ]; then
        shift
        command tmux detach 2>/dev/null
        command tmux attach "$@" || command tmux new-session "$@"
    else
        command tmux "$@"
    fi
}

Now if you launch it as tmux -z, it should perform the actions you're looking for.

You can emulate this with a shell function, this should work for any POSIX-compliant shell:

tmux() {
    if [ "$#" -ge 1 ] && [ "$1" = -z ]; then
        shift
        command tmux detach 2>/dev/null
        command tmux attach "$@" || command tmux new-session "$@"
    else
        command tmux "$@"
    fi
}

Now if you launch it as tmux -z, it should perform the actions you're looking for.

Source Link
Chris Down
  • 130.3k
  • 26
  • 277
  • 268

You can emulate this with a shell function, this should work for any POSIX-compliant shell:

tmux() {
    if [ "$1" == -z ]; then
        shift
        command tmux detach 2>/dev/null
        command tmux attach "$@" || command tmux new-session "$@"
    else
        command tmux "$@"
    fi
}

Now if you launch it as tmux -z, it should perform the actions you're looking for.