88 lines
1.8 KiB
Bash
88 lines
1.8 KiB
Bash
# Create/attach to named session.
|
|
# By default uses name "main".
|
|
# Usage: ta [NAME]
|
|
function ta() {
|
|
local name="$1"
|
|
|
|
# set default name.
|
|
if [[ "$name" = "" ]]; then
|
|
name="main"
|
|
fi
|
|
|
|
# call tmux.
|
|
tmux new -s "$name" 2> /dev/null || tmux attach-session -t "$name"
|
|
}
|
|
|
|
# Detach from running session.
|
|
function td() {
|
|
tmux detach-client
|
|
}
|
|
|
|
# List running sessions.
|
|
function tl() {
|
|
tmux list-sessions
|
|
}
|
|
|
|
# Rename current session. Uses current dir name by default.
|
|
# Usage: trn [NAME]
|
|
function trn() {
|
|
local name="${1}"
|
|
|
|
[[ "${name}" = "" ]] && name="${PWD##*/}"
|
|
|
|
tmux rename-session "${name}"
|
|
}
|
|
|
|
# Assign name to window. Uses current dir name by default.
|
|
# Usage: tn [NAME]
|
|
function tn() {
|
|
local name="${1}"
|
|
|
|
[[ "${name}" = "" ]] && name="${PWD##*/}"
|
|
|
|
tmux rename-window "${name}"
|
|
}
|
|
|
|
# Kill specified session.
|
|
# By default it kills "main" session.
|
|
# Usage: tk [NAME]
|
|
function tk() {
|
|
# set default name.
|
|
if [[ "${1}" = "" ]]; then
|
|
1="main"
|
|
fi
|
|
|
|
# call tmux.
|
|
for name in "$@"; do
|
|
tmux kill-session -t "${name}"
|
|
done
|
|
}
|
|
|
|
# Kill all sessions.
|
|
function tka() {
|
|
local sessions=$(tmux list-sessions | sed -e 's/:.*//')
|
|
|
|
for session in $sessions; do
|
|
tmux kill-session -t "$session"
|
|
done
|
|
}
|
|
|
|
# Autocomplete with running sessions once.
|
|
function _complete_tmux_session() {
|
|
_autocomplete_first "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')"
|
|
}
|
|
|
|
# Autocomplete with running sessions.
|
|
function _complete_tmux_sessions() {
|
|
_autocomplete "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')"
|
|
}
|
|
|
|
# Autocomplete with current dir name and dirs inside this one.
|
|
function _complete_tmux_name() {
|
|
_autocomplete_first "${PWD##*/}"$'\n'$(ls --classify | grep /$ | sed -e 's/\/$//')
|
|
}
|
|
|
|
complete -F _complete_tmux_session ta
|
|
complete -F _complete_tmux_sessions tk
|
|
complete -o nosort -F _complete_tmux_name trn tn
|