]> git.madduck.net Git - etc/tmux.git/blobdiff - .bin/tmux

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

linger after a client exits
[etc/tmux.git] / .bin / tmux
index d6ff4b27d0493d3bc36eb134cdf8b4cd345dbb54..93837e017c0fc8661b9be6eff30c736ce29c1b78 100755 (executable)
--- a/.bin/tmux
+++ b/.bin/tmux
@@ -13,14 +13,16 @@ real_tmux() {
 
 single_tmux_session() {
   local id; id="$1"; shift
 
 single_tmux_session() {
   local id; id="$1"; shift
-  real_tmux new -t "$id" "$@"
+  local flag; flag=t
+  real_tmux list-sessions | grep -q "^${id}:" || flag=s
+  real_tmux new -$flag "$id" "$@"
 }
 
 tmux_session_exists() {
   _tmux_eval_only=1 real_tmux has-session -t "$1"
 }
 
 }
 
 tmux_session_exists() {
   _tmux_eval_only=1 real_tmux has-session -t "$1"
 }
 
-if [ "${1:-}" = --connect-to-last ]; then
+if [ "${1:-}" = last ]; then
   shift
   if [ -f "$LASTSESSIONIDFILE" ]; then
     UUID="$(cat $LASTSESSIONIDFILE)"
   shift
   if [ -f "$LASTSESSIONIDFILE" ]; then
     UUID="$(cat $LASTSESSIONIDFILE)"
@@ -34,13 +36,27 @@ if [ "${1:-}" = --connect-to-last ]; then
     echo >&2 W: No tmux session ID stored, generating a new one…
   fi
 
     echo >&2 W: No tmux session ID stored, generating a new one…
   fi
 
-elif [ -n "${1:-}" ]; then
-  real_tmux "$@"
+else
+  case "${1:-;}" in
+    (\;) :;;
+    (*) real_tmux "$@";;
+  esac
 fi
 
 # only without argument create a new session with a random name/id to which we
 # can then attach
 
 fi
 
 # only without argument create a new session with a random name/id to which we
 # can then attach
 
+hascmd() { command -v "$@" >/dev/null;}
+
+if   hascmd uuid; then alias uuidgen=uuid
+elif hascmd uuidgen; then :
+elif hascmd python3; then
+  uuidgen() { python3 -c 'import uuid; print(uuid.uuid1())'; }
+elif hascmd python; then
+  uuidgen() { python -c 'import uuid; print(uuid.uuid1())'; }
+else
+  uuidgen() { dd if=/dev/urandom bs=16 count=1 status=none | base64; }
+fi
 UUID=$(uuidgen)
 echo "$UUID" > $LASTSESSIONIDFILE
 
 UUID=$(uuidgen)
 echo "$UUID" > $LASTSESSIONIDFILE