Skip to content

Commit

Permalink
bashrc: tmux: Match target sessions exactly
Browse files Browse the repository at this point in the history
See tmux/tmux#346.

From the tmux man page:

target-session is tried as, in order:

  1.   A session ID prefixed with a $.

  2.   An exact name of a session (as listed by the list-sessions
       command).

  3.   The start of a session name, for example `mysess' would match a
       session named `mysession'.

  4.   An fnmatch(3) pattern which is matched against the session name.

If the session name is prefixed with an `=', only an exact match is
accepted (so `=mysess' will only match exactly `mysess', not
`mysession').

If a single session is found, it is used as the target session; multiple
matches produce an error.  If a session is omitted, the current session
is used if available; if no cur- rent session is available, the most
recently used is chosen.
  • Loading branch information
serban committed Nov 12, 2018
1 parent 52e4a5c commit 3ee34a8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions bashrc
Expand Up @@ -531,19 +531,25 @@ ma() {
TARGET="${REPO//\./-}"
SESSION="z-${TARGET}-${RANDOM_NUMBER}"

if ! tmux has-session -t "${TARGET}" ; then
# From the tmux man page:
#
# "If the session name is prefixed with an `=', only an exact match is
# accepted (so `=mysess' will only match exactly `mysess', not `mysession')."
#
# This is intended behavior: https://github.com/tmux/tmux/issues/346
if ! tmux has-session -t "=${TARGET}" ; then
tmux new-session -d -s "${TARGET}" -c "${HOME}/src/${REPO}" -n Shell
fi

pushd "${HOME}/src/${REPO}" > /dev/null
tmux new-session -A -s "${SESSION}" -t "${TARGET}"
tmux kill-session -t "${SESSION}"
tmux new-session -A -s "${SESSION}" -t "=${TARGET}"
tmux kill-session -t "=${SESSION}"
popd > /dev/null
}

mc() {
while read -r session; do
tmux kill-session -t "${session}"
tmux kill-session -t "=${session}"
done < <(tmux list-sessions -F '#{session_name}' | grep '^z-')
}

Expand Down

0 comments on commit 3ee34a8

Please sign in to comment.