2021-03-31 09:14:51 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-03-31 10:47:59 +00:00
|
|
|
#
|
|
|
|
# Open a new tmux session named after the current directory with a basic
|
|
|
|
# development/editing environment.
|
2021-04-03 08:55:12 +00:00
|
|
|
#
|
|
|
|
# The session will be named after the current directory unless the desired name
|
|
|
|
# is passed as the only argument.
|
2021-03-31 09:14:51 +00:00
|
|
|
set -e
|
|
|
|
|
2021-04-03 08:55:12 +00:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
cwd=$(pwd)
|
|
|
|
sessionname=$(basename $cwd)
|
|
|
|
else
|
|
|
|
sessionname="$1"
|
|
|
|
fi
|
2023-10-01 14:19:24 +00:00
|
|
|
|
|
|
|
tmux_new_result=$(tmux new -d -s $sessionname 2>&1) || true
|
|
|
|
exitcode=$?
|
|
|
|
|
|
|
|
if echo "$tmux_new_result" | grep -q "duplicate session"; then
|
|
|
|
echo "Session $sessionname already exists. Attaching..."
|
|
|
|
tmux new -d -A -s $sessionname
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $exitcode -ne 0 ]; then
|
|
|
|
echo "$tmux_new_result"
|
|
|
|
exit $exitcode
|
|
|
|
fi
|
|
|
|
|
|
|
|
# TODO: fix sessionname containing full stop which are renamed by tmux
|
2021-03-31 09:14:51 +00:00
|
|
|
tmux rename-window -t $sessionname:1 cli
|
2023-09-17 06:27:37 +00:00
|
|
|
tmux new-window -t $sessionname -n vim zsh -ic nvim
|
2021-03-31 09:14:51 +00:00
|
|
|
tmux select-window -t $sessionname:1
|
2021-04-13 15:59:03 +00:00
|
|
|
# https://github.com/tmux/tmux/issues/2064
|
|
|
|
sleep 0.5
|
2021-03-31 09:14:51 +00:00
|
|
|
tmux attach -t $sessionname
|