2023-12-07 04:02:47 +03:00
|
|
|
# Create/attach to named session.
|
2024-01-31 17:47:55 +03:00
|
|
|
# By default uses current dir name.
|
2023-12-07 04:02:47 +03:00
|
|
|
# Usage: ta [NAME]
|
2023-12-07 01:44:42 +03:00
|
|
|
function ta() {
|
2024-01-23 15:55:40 +03:00
|
|
|
local name="${1}"
|
2023-12-05 21:50:45 +03:00
|
|
|
|
2024-01-23 15:55:40 +03:00
|
|
|
# Set default name.
|
2024-01-31 17:47:55 +03:00
|
|
|
# [[ "${name}" = "" ]] && name="main"
|
2024-01-31 18:40:02 +03:00
|
|
|
[[ "${name}" = "" ]] && name=$(parse_alnum "${PWD##*/}")
|
2023-12-10 16:56:56 +03:00
|
|
|
|
2024-01-23 15:55:40 +03:00
|
|
|
# Create session.
|
|
|
|
tmux new-session -s "${name}" -d &> /dev/null
|
|
|
|
|
|
|
|
# Attach to session.
|
2024-01-23 15:57:39 +03:00
|
|
|
if _is_tmux; then
|
2024-01-23 15:55:40 +03:00
|
|
|
tmux switch-client -t "${name}"
|
|
|
|
else
|
|
|
|
tmux attach-session -t "${name}"
|
|
|
|
fi
|
2023-08-08 16:24:15 +03:00
|
|
|
}
|
|
|
|
|
2023-12-07 04:02:47 +03:00
|
|
|
# Detach from running session.
|
2023-12-07 01:44:42 +03:00
|
|
|
function td() {
|
2023-12-07 00:42:06 +03:00
|
|
|
tmux detach-client
|
|
|
|
}
|
2023-08-08 16:24:15 +03:00
|
|
|
|
2023-12-10 16:56:56 +03:00
|
|
|
# Detach all other tmux clients.
|
|
|
|
function tda() {
|
2023-12-29 19:35:52 +03:00
|
|
|
tmux detach-client -s $(tmux display-message -p '#S')
|
2023-12-10 16:56:56 +03:00
|
|
|
}
|
|
|
|
|
2023-12-07 04:02:47 +03:00
|
|
|
# List running sessions.
|
2023-12-07 01:44:42 +03:00
|
|
|
function tl() {
|
2023-12-07 00:42:06 +03:00
|
|
|
tmux list-sessions
|
|
|
|
}
|
2023-08-08 16:24:15 +03:00
|
|
|
|
2024-01-07 22:40:11 +03:00
|
|
|
# Assign name to session. Uses current dir name by default.
|
2024-01-06 02:17:46 +03:00
|
|
|
# Usage: tns [NAME]
|
|
|
|
function tns() {
|
2023-12-05 21:50:45 +03:00
|
|
|
local name="${1}"
|
2023-11-08 16:16:01 +03:00
|
|
|
|
2024-01-31 18:40:02 +03:00
|
|
|
[[ "${name}" = "" ]] && name=$(parse_alnum "${PWD##*/}")
|
2023-11-08 16:16:01 +03:00
|
|
|
|
2023-12-05 21:50:45 +03:00
|
|
|
tmux rename-session "${name}"
|
2023-11-08 16:16:01 +03:00
|
|
|
}
|
2023-08-08 16:24:15 +03:00
|
|
|
|
2023-12-07 04:02:47 +03:00
|
|
|
# Assign name to window. Uses current dir name by default.
|
2024-01-07 22:40:11 +03:00
|
|
|
# Usage: tnw [NAME]
|
|
|
|
function tnw() {
|
2023-12-05 21:50:45 +03:00
|
|
|
local name="${1}"
|
2023-11-08 16:16:01 +03:00
|
|
|
|
2024-01-31 18:40:02 +03:00
|
|
|
[[ "${name}" = "" ]] && name=$(parse_alnum "${PWD##*/}")
|
2023-11-08 16:16:01 +03:00
|
|
|
|
2023-12-05 21:50:45 +03:00
|
|
|
tmux rename-window "${name}"
|
2023-11-08 16:16:01 +03:00
|
|
|
}
|
2023-08-08 16:24:15 +03:00
|
|
|
|
2023-12-07 04:02:47 +03:00
|
|
|
# Kill specified session.
|
2024-01-31 18:25:30 +03:00
|
|
|
# By default uses current dir name.
|
2023-12-07 04:02:47 +03:00
|
|
|
# Usage: tk [NAME]
|
2023-12-07 01:44:42 +03:00
|
|
|
function tk() {
|
2024-01-31 18:25:30 +03:00
|
|
|
local name="${1}"
|
2023-12-10 16:56:56 +03:00
|
|
|
|
2024-01-31 18:40:02 +03:00
|
|
|
[[ "${name}" = "" ]] && name=$(parse_alnum "${PWD##*/}")
|
2024-01-31 18:25:30 +03:00
|
|
|
|
|
|
|
tmux kill-session -t "${name}"
|
2023-08-08 16:24:15 +03:00
|
|
|
}
|
|
|
|
|
2023-12-07 04:02:47 +03:00
|
|
|
# Kill all sessions.
|
2023-12-07 01:44:42 +03:00
|
|
|
function tka() {
|
2023-12-05 21:50:45 +03:00
|
|
|
local sessions=$(tmux list-sessions | sed -e 's/:.*//')
|
2023-08-08 16:24:15 +03:00
|
|
|
|
2023-12-05 21:50:45 +03:00
|
|
|
for session in $sessions; do
|
|
|
|
tmux kill-session -t "$session"
|
|
|
|
done
|
2023-08-08 16:24:15 +03:00
|
|
|
}
|
2023-10-23 00:24:36 +03:00
|
|
|
|
2023-12-07 04:02:47 +03:00
|
|
|
# Autocomplete with running sessions once.
|
2023-12-07 01:44:42 +03:00
|
|
|
function _complete_tmux_session() {
|
2023-12-05 21:50:45 +03:00
|
|
|
_autocomplete_first "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')"
|
2023-10-23 00:24:36 +03:00
|
|
|
}
|
|
|
|
|
2023-12-07 04:02:47 +03:00
|
|
|
# Autocomplete with running sessions.
|
2023-12-07 01:44:42 +03:00
|
|
|
function _complete_tmux_sessions() {
|
2023-12-05 21:50:45 +03:00
|
|
|
_autocomplete "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')"
|
2023-11-19 22:12:18 +03:00
|
|
|
}
|
|
|
|
|
2023-12-07 04:02:47 +03:00
|
|
|
# Autocomplete with current dir name and dirs inside this one.
|
2023-12-07 01:44:42 +03:00
|
|
|
function _complete_tmux_name() {
|
2023-12-05 21:50:45 +03:00
|
|
|
_autocomplete_first "${PWD##*/}"$'\n'$(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
|
2024-01-18 02:10:59 +03:00
|
|
|
complete -o nosort -F _complete_tmux_name tns tnw
|