2023-08-08 16:24:15 +03:00
|
|
|
# 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"
|
|
|
|
|
2023-11-08 16:16:01 +03:00
|
|
|
# Rename current session. Uses current dir name by default.
|
2023-11-25 21:47:52 +03:00
|
|
|
# Usage: trn [NAME]
|
|
|
|
trn()
|
2023-11-08 16:16:01 +03:00
|
|
|
{
|
|
|
|
local name="${1}"
|
|
|
|
|
|
|
|
[[ "${name}" = "" ]] && name="${PWD##*/}"
|
|
|
|
|
|
|
|
tmux rename-session "${name}"
|
|
|
|
}
|
2023-08-08 16:24:15 +03:00
|
|
|
|
2023-11-08 16:16:01 +03:00
|
|
|
# Assign name (to window). Uses current dir name by default.
|
|
|
|
# Usage: tn [NAME]
|
|
|
|
tn()
|
|
|
|
{
|
|
|
|
local name="${1}"
|
|
|
|
|
|
|
|
[[ "${name}" = "" ]] && name="${PWD##*/}"
|
|
|
|
|
|
|
|
tmux rename-window "${name}"
|
|
|
|
}
|
2023-08-08 16:24:15 +03:00
|
|
|
|
|
|
|
# kill specified session or default one.
|
|
|
|
tk()
|
|
|
|
{
|
|
|
|
# set default name.
|
2023-11-19 22:12:18 +03:00
|
|
|
if [[ "${1}" = "" ]]; then
|
|
|
|
1="main"
|
2023-08-08 16:24:15 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# call tmux.
|
2023-11-19 22:12:18 +03:00
|
|
|
for name in "$@"; do
|
|
|
|
tmux kill-session -t "${name}"
|
|
|
|
done
|
2023-08-08 16:24:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# kill all sessions.
|
|
|
|
tka()
|
|
|
|
{
|
|
|
|
local sessions=$(tmux list-sessions | sed -e 's/:.*//')
|
|
|
|
|
|
|
|
for session in $sessions; do
|
|
|
|
tmux kill-session -t "$session"
|
|
|
|
done
|
|
|
|
}
|
2023-10-23 00:24:36 +03:00
|
|
|
|
|
|
|
# autocompletes.
|
2023-11-19 22:12:18 +03:00
|
|
|
_complete_tmux_session()
|
2023-10-23 00:24:36 +03:00
|
|
|
{
|
2023-10-23 04:27:32 +03:00
|
|
|
_autocomplete_first "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')"
|
2023-10-23 00:24:36 +03:00
|
|
|
}
|
|
|
|
|
2023-11-19 22:12:18 +03:00
|
|
|
_complete_tmux_sessions()
|
|
|
|
{
|
|
|
|
_autocomplete "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')"
|
|
|
|
}
|
|
|
|
|
|
|
|
_complete_tmux_name()
|
2023-11-08 20:05:19 +03:00
|
|
|
{
|
2023-11-11 18:39:07 +03:00
|
|
|
_autocomplete_first "${PWD##*/}" $(ls --classify | grep /$ | sed -e 's/\/$//')
|
2023-11-08 20:05:19 +03:00
|
|
|
}
|
|
|
|
|
2023-11-19 22:12:18 +03:00
|
|
|
complete -F _complete_tmux_session ta
|
|
|
|
complete -F _complete_tmux_sessions tk
|
|
|
|
complete -o nosort -F _complete_tmux_name tr tn
|