aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-01-10 17:01:13 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-01-10 17:01:13 +1300
commitb5b8f9b71e7cb067aef507d31aef280c798b2082 (patch)
treea532590663111c98a6e643f7fa94a57f5c0339db
parent3425b39cda52638ffa4940622d311b4a77e543ec (diff)
downloaddotfiles-b5b8f9b71e7cb067aef507d31aef280c798b2082.tar.gz
Move tmux() function to tm(1df)
No real reason for it to be a shell function
-rw-r--r--README.markdown4
-rwxr-xr-xbin/tm18
-rw-r--r--man/man1/tm.1df12
-rw-r--r--readline/inputrc4
-rw-r--r--sh/shrc.d/tmux.sh19
5 files changed, 34 insertions, 23 deletions
diff --git a/README.markdown b/README.markdown
index 97823267..b906c3f0 100644
--- a/README.markdown
+++ b/README.markdown
@@ -204,8 +204,6 @@ in `sh/shrc.d` to be loaded by any POSIX interactive shell. Those include:
* `scp()` tries to detect forgotten hostnames in `scp(1)` command calls.
* `sudo()` forces `-H` for `sudo(8)` calls so that `$HOME` is never
preserved; I hate having `root`-owned files in my home directory.
-* `tmux()` changes the default command for `tmux(1)` to `attach-session -d`
- if a session exists, or creates a new session if one doesn't.
* `tree()` colorizes GNU `tree(1)` output if possible (without having
`LS_COLORS` set).
* `vim()` defines three functions to always use `vim(1)` as my `ex(1)`,
@@ -501,6 +499,8 @@ Installed by the `install-bin` target:
`scp(1)`'s HOST:PATH format.
* `td(1df)` manages a to-do file for you with `$EDITOR` and `git(1)`; I used
to use Taskwarrior, but found it too complex and buggy.
+* `tm()` runs `tmux(1)` with `attach-session -d` if a session exists, and
+ `new-session` if it doesn't.
* `try(1df)` repeats a command up to a given number of times until it
succeeds, only printing error output if all three attempts failed. Good for
tolerating blips or temporary failures in `cron(8)` scripts.
diff --git a/bin/tm b/bin/tm
new file mode 100755
index 00000000..f2b51c63
--- /dev/null
+++ b/bin/tm
@@ -0,0 +1,18 @@
+#!/bin/sh
+# Attach to existing tmux session rather than create a new one if possible
+
+# If given any arguments, just use them as they are
+if [ "$#" -gt 0 ] ; then
+ :
+
+# If a session exists, just attach to it
+elif command tmux has-session 2>/dev/null ; then
+ set -- attach-session -d
+
+# Create a new session with an appropriate name
+else
+ set -- new-session -s "${TMUX_SESSION:-default}"
+fi
+
+# Execute with concluded arguments
+tmux "$@"
diff --git a/man/man1/tm.1df b/man/man1/tm.1df
new file mode 100644
index 00000000..125d69c1
--- /dev/null
+++ b/man/man1/tm.1df
@@ -0,0 +1,12 @@
+.TH TM 1df "January 2017" "Manual page for tm"
+.SH NAME
+.B tm
+\- tmux shortcut
+.SH SYNOPSIS
+.B tm
+.SH DESCRIPTION
+If arguments are given, pass them to tmux(1) unchanged. If not, check if a tmux
+session exists; if it does, attach to it. If not, create a new session with
+name given in environment variable $TMUX_SESSION, default "default".
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>
diff --git a/readline/inputrc b/readline/inputrc
index af82a65d..7e4b500d 100644
--- a/readline/inputrc
+++ b/readline/inputrc
@@ -74,8 +74,8 @@ $if Bash
# Alt-S (for set) to wrap current command in (set -x ; ...)
"\es": "\C-a(set -x ; \C-e)\C-b"
- # Alt-M (for muxer) to run tmux
- "\em": "\C-utmux\C-j\C-y"
+ # Alt-M (for muxer) to run tm(1df)
+ "\em": "\C-utm\C-j\C-y"
# Ctrl-Alt-B to move backward a shell-quoted word
"\e\C-b": shell-backward-word
diff --git a/sh/shrc.d/tmux.sh b/sh/shrc.d/tmux.sh
deleted file mode 100644
index bd954be8..00000000
--- a/sh/shrc.d/tmux.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-# Attach to existing tmux session rather than create a new one if possible
-tmux() {
-
- # If given any arguments, just use them as they are
- if [ "$#" -gt 0 ] ; then
- :
-
- # If a session exists, just attach to it
- elif command tmux has-session 2>/dev/null ; then
- set -- attach-session -d
-
- # Create a new session with an appropriate name
- else
- set -- new-session -s "${TMUX_SESSION:-default}"
- fi
-
- # Execute with concluded arguments
- command tmux "$@"
-}