86 lines
1.5 KiB
Bash
86 lines
1.5 KiB
Bash
# create/attach to named session.
|
|
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.
|
|
alias td="tmux detach-client"
|
|
|
|
# list.
|
|
alias tl="tmux list-sessions"
|
|
|
|
# Rename current session. Uses current dir name by default.
|
|
# Usage: trn [NAME]
|
|
trn()
|
|
{
|
|
local name="${1}"
|
|
|
|
[[ "${name}" = "" ]] && name="${PWD##*/}"
|
|
|
|
tmux rename-session "${name}"
|
|
}
|
|
|
|
# Assign name (to window). Uses current dir name by default.
|
|
# Usage: tn [NAME]
|
|
tn()
|
|
{
|
|
local name="${1}"
|
|
|
|
[[ "${name}" = "" ]] && name="${PWD##*/}"
|
|
|
|
tmux rename-window "${name}"
|
|
}
|
|
|
|
# kill specified session or default one.
|
|
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.
|
|
tka()
|
|
{
|
|
local sessions=$(tmux list-sessions | sed -e 's/:.*//')
|
|
|
|
for session in $sessions; do
|
|
tmux kill-session -t "$session"
|
|
done
|
|
}
|
|
|
|
# autocompletes.
|
|
_complete_tmux_session()
|
|
{
|
|
_autocomplete_first "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')"
|
|
}
|
|
|
|
_complete_tmux_sessions()
|
|
{
|
|
_autocomplete "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')"
|
|
}
|
|
|
|
_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
|