Open a new session, named after the current working directory
$ tat -n
Attach to a named session, or create it if it does not exist
$ tat my-new-session
List existing session names
$ tat
Put the script in a directory in your $PATH
.
Add completion script if you want bash completion.
$ mkdir -p ~/.local/share/bash-completion/completions/
$ cat <<'EOF' > ~/.local/share/bash-completion/completions/tat
# stigok, feb 2019
_tat()
{
local cur opts arglen cwdname
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
arglen=${#COMP_WORDS[@]}
cwdname=$(basename $(pwd))
# All existing tmux session names
opts="$(tmux ls -F '#{session_name}' 2> /dev/null)"
# If no tmux session is active, complete with current dir name
if [[ $? -ne 0 && $arglen -eq 2 ]]; then
COMPREPLY=( $(compgen -W "$cwdname") )
>&2 echo -e "No sessions. Completing with current dir name"
return 0
fi
# The `tat` binary should only accept a single argument.
# Only trigger completion on the first arg (after the binary name itself)
if [ $arglen -eq 2 ]; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
complete -F _tat tat
EOF