dotfiles/.local/bin/tm
Marty Oehme df45a08c6c Move scripts to .local/bin
Moved all personal scripts to ~/.local/bin to be systemd file hierarchy
compliant, as well as XDG compliant. Since they are not configuration
options they don't have anything to do in .config directories.
Also, it's just easier to find than the previous .config/scripts/bin.
2019-05-23 11:20:11 +02:00

44 lines
772 B
Bash
Executable file

#!/bin/sh
#
# Attach to a tmux session, or create it if it doesnt exist
if [ -e $XDG_CONFIG_HOME/tmux/tmux.conf ]; then
start="tmux -f $XDG_CONFIG_HOME/tmux/tmux.conf"
else
start=tmux
fi
path_name="$(basename "$PWD" | tr . -)"
curr_dir=${1-$path_name}
session_name=${1:-$curr_dir}
_not_in_tmux() {
[ -z "$TMUX" ]
}
_session_exists() {
$start has-session -t "$session_name"
}
_create_detached_session() {
(TMUX='' $start new-session -Ad -s "$session_name")
}
_get_session_name() {
#${1:-$session_name}
return "blubb"
}
_attach_or_create() {
if _not_in_tmux; then
$start new-session -As "$session_name"
else
if ! _session_exists; then
_create_detached_session
fi
$start switch-client -t "$session_name"
fi
}
_attach_or_create