All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
3 # mtmux — initialise tmux session with multiple windows
6 # 1. mtmux [-n name] [-c cwd] -- cmd1 . windowname: cmd2 . shellname:
8 # Spawns a tmux session, optionally named "name", and optionally with the
9 # working directory set to "cwd", with three windows, one running cmd1,
10 # one running cmd2 and named "windowname", and one named "shellname"
11 # running the default command.
13 # 2. mtmux -n name -w 2
15 # Attach to session "name" and switch to window 2
17 # Copyright © 2020 martin f. krafft <madduck@madduck.net>
18 # Released under the WTFPL.
27 local exitcode; exitcode="$1"; shift
34 case "${state:-}:$i" in
37 [ -z "${cwd:-}" ] && cwd="$i" || err 1 "Option -c already specified"
43 [ -z "${name:-}" ] && name="$i" || err 1 "Option -n already specified"
49 [ -z "${window:-}" ] && window="$i" || err 1 "Option -w already specified"
53 (:--) shift; set -- "$@"; break;;
55 (:\;) cmds="$cmds \;";;
56 (:*) cmds="${cmds:+$cmds }$i";;
58 shift 2>/dev/null || break
62 if [ -n "${window:-}" ]; then
64 if [ -n "${cwd:-}" ]; then
65 warn "Both -w and -c don't make sense, ignoring -c"
69 warn "Ignoring commands specified with -w"
72 if [ -z "$name" ]; then
73 err 1 "Missing option -n, required with -w"
76 args="new -t $name \;${cmds:+ $cmds \;} select-window -t $window"
80 subcmd="new${name:+ -s $name}"
85 args="${args}${subcmd}${cwd:+ -c $cwd}${wname:+ -n $wname}${cmd:-} \; "
86 args="$args${cmds:+$cmds \; }"
90 (*) cmd="${cmd:-} $i";;