dgy
/
hexagons
Archived
1
0
Fork 0
This repository has been archived on 2021-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
hexagons/.config/zsh/tmux.zsh

46 lines
1.0 KiB
Bash

#!/bin/zsh
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 new-session -s "$REPLY"
else
tmux 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
}
if [[ -z $TMUX ]]; then
tmux_sessions
fi