blob: a7609883f929898bf5740c13e7085749241034f5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
tmux_new_session() {
if [[ -n $TMUX ]]; then
tmux switch-client -t "$(TMUX= tmux -S "${TMUX%,*,*}" new-session -dP "$@")"
else
echo -n "Nombre de Sesión: "
read REPLY
if [[ -n $REPLY ]]; then
tmux -2 new-session -s "$REPLY"
else
tmux -2 new-session
fi
fi
}
tmux_sessions() {
# Select existing session or create session with fuzzy search tool
# get the IDs
if ! ID="$(tmux list-sessions 2>/dev/null)"; then
# tmux returned error, so try cleaning up /tmp
\rm -rf /tmp/tmux*
fi
create_new_session="Crear Sesión"
if [[ -n "$ID" ]]; then
ID="${create_new_session}:\n$ID"
else
ID="${create_new_session}:"
fi
ID="$(echo "$ID" | fzf | cut -d: -f1)"
if [[ "$ID" == "${create_new_session}" ]]; then
tmux_new_session
elif [[ -n "$ID" ]]; then
if [[ -n $TMUX ]]; then
tmux switch-client -t "$ID"
else
tmux attach-session -t "$ID"
fi
else
: # Start terminal normally
fi
}
tmux_base_session(){
# create base session, then prompt for others
client_cnt="$(tmux list-clients 2>/dev/null | wc -l)"
if [[ $client_cnt -eq 0 ]]; then
tmux -2 new-session -d -s z
tmux -2 attach-session -t z
else
tmux_sessions
fi
}
if [[ -z $TMUX ]]; then
tmux_base_session
fi
|