4 # Copyright (c) 2013 Joerg Jaspert
5 # Author: Joerg Jaspert <joerg@debian.org>
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 local expl state curcontext="$curcontext"
33 function _tm_get_sessions {
34 typeset -ag _tm_sessions
35 if out=$(tmux list-sessions -F "#{session_name}" 2>/dev/null); then
36 for sess in ${=out}; do
37 _tm_sessions+="${sess}:Existing session ${sess}"
41 _tm_sess=$#_tm_sessions
43 local TMDIR=${TMDIR:-"${HOME}/.tmux.d"}
44 for file in ${TMDIR}/*; do
45 _tm_sessions+=${file##*/}:${(f)${(f)mapfile[$file]}[1]}
51 if [[ $_tm_sess -ne $(tmux list-sessions|wc -l) ]]; then
54 ((_tm_done)) || _tm_get_sessions
56 'ls:List running sessions'
57 's:Open ssh session to a single host'
58 'ms:Open ssh session to multiple hosts'
59 '-l:List running sessions'
60 '-s:Open ssh session to a single host'
61 '-m:Open ssh session to multiple hosts'
62 '-e:use existing session'
65 _describe action actions
68 function _tm_arguments() {
71 _arguments '::hostname:_hosts'
74 _arguments -C '*:hostnames:->hosts'
84 '-n[Open new multisession even if same exists]' \
85 '-c+[Setup session according to TMDIR file]:_tm_sessions: ' \
86 ':action:_tm_action' \
87 ':session:->session' \
88 '*::arguments:_tm_arguments'
92 _description hosts expl "hosts"
93 _wanted hosts expl hostname _hosts && return