summaryrefslogtreecommitdiffstats
path: root/bin/t
diff options
context:
space:
mode:
Diffstat (limited to 'bin/t')
-rwxr-xr-xbin/t36
1 files changed, 36 insertions, 0 deletions
diff --git a/bin/t b/bin/t
new file mode 100755
index 0000000..c6a1be3
--- /dev/null
+++ b/bin/t
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+
+real_tmux() {
+ if [ -n "${REMOTE_USER}" -a -e "${HOME}/.${REMOTE_USER}/tmux/tmux.conf" ]; then
+ \tmux -f "${HOME}/.${REMOTE_USER}/tmux/tmux.conf" -S "${HOME}/.${REMOTE_USER}/tmux/socket" "$@"
+ else
+ \tmux "$@"
+ fi
+}
+
+exec_real_tmux() {
+ if [ -n "${REMOTE_USER}" -a -e "${HOME}/.${REMOTE_USER}/tmux/tmux.conf" ]; then
+ exec \tmux -f "${HOME}/.${REMOTE_USER}/tmux/tmux.conf" -S "${HOME}/.${REMOTE_USER}/tmux/socket" "$@"
+ else
+ exec \tmux "$@"
+ fi
+}
+
+if [[ "x$1" == x ]] ; then
+ real_tmux list-sessions ||
+ {
+ real_tmux new-session -d
+ }
+
+ exec_real_tmux attach-session -d
+fi
+
+if [ -z "$2" -a "$1" != "att" -a "$1" != "ls" ]; then
+ if real_tmux has-session -t "$1"; then
+ exec_real_tmux attach-session -t "$1"
+ else
+ exec_real_tmux new-session -s "$1"
+ fi
+fi
+
+exec_real_tmux $@