Copy became script to target directory.
[profile.git] / opt / bin / ktmux
1 #!/bin/bash
2 #
3 # ktmux: Start tmux and ktmux_helper.
4 # Usage: ktmux [options]
5 # Options: -I <path>   Pass path to kinit through to ktmux_helper.
6 #          -L <path>   Pass path to klist through to ktmux_helper.
7 #          -R <path>   Pass path to krenew through to ktmux_helper.
8 #          -S <path>   Socket path for tmux.
9 #          -T <path>   Path to tmux.
10 #          -n <name>   Window name for new tmux session.
11 #          -s <name>   Session name for new tmux session.
12 #          -t <name>   Target session name for new tmux session.
13 #
14
15 tmux=tmux
16 helper_opts=
17 tmux_opts=
18 session_opts=
19 while getopts ":I:L:R:S:T:n:s:t:" opt; do
20   case $opt in
21     I|L|R) helper_opts="$helper_opts -$opt $OPTARG";;
22     T) tmux="$OPTARG"; helper_opts="$helper_opts -$opt $OPTARG";;
23     n|s|t) session_opts="$session_opts -$opt $OPTARG";;
24     S) tmux_opts="$tmux_opts -$opt $OPTARG";;
25   esac
26 done
27 shift $((OPTIND-1))
28
29 if [ -z "$KRB5CCNAME" ]; then
30   krb5ccname="$KRB5CCNAME"
31   [ -z "$krb5ccname" ] && krb5ccname=FILE:${TMPDIR:-/tmp}/krb5cc_${UID}_ktmux_$$
32   export KRB5CCNAME="$krb5ccname"
33 fi
34 klist -s || kinit
35
36 exec $tmux ${tmux_opts## } new-session ${session_opts## } -d ';' set-environment KRB5CCNAME "$KRB5CCNAME" ';' attach ';' run-shell "ktmux_helper ${helper_opts## }"