This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
linux/.linux/bash/module/tmux.sh

80 lines
1.3 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: tr [NAME]
tr()
{
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()
{
local name="$1"
# set default name.
if [[ "$name" = "" ]]; then
name="main"
fi
# call tmux.
tmux kill-session -t "$name"
}
# kill all sessions.
tka()
{
local sessions=$(tmux list-sessions | sed -e 's/:.*//')
for session in $sessions; do
tmux kill-session -t "$session"
done
}
# autocompletes.
_tmux_sessions()
{
_autocomplete_first "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')"
}
_tmux_names()
{
_autocomplete_first "${PWD##*/}" $(ls --classify | grep /$ | sed -e 's/\/$//')
}
complete -F _tmux_sessions ta tk
complete -o nosort -F _tmux_names tr tn