2022-10-03 16:46:49 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-09-17 18:42:11 +00:00
|
|
|
|
2023-12-14 08:58:05 +00:00
|
|
|
set -o nounset
|
|
|
|
set -o pipefail
|
|
|
|
|
2021-09-17 18:42:11 +00:00
|
|
|
if [[ $# -eq 1 ]]; then
|
|
|
|
selected=$1
|
|
|
|
else
|
2023-12-08 07:18:00 +00:00
|
|
|
selected=$(zoxide query -l | grep -v /tmp | grep -v "^${HOME}/\." | grep -v "^${HOME}/Code$" | grep -v "/main$" | fzf --reverse)
|
2021-09-17 18:42:11 +00:00
|
|
|
fi
|
|
|
|
|
2023-12-14 08:58:05 +00:00
|
|
|
if [[ -z "${selected}" ]]; then
|
2021-09-17 18:42:11 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-12-14 08:58:05 +00:00
|
|
|
session_name=$(basename "${selected}" | sed 's/\./-/g')
|
2021-09-17 21:35:47 +00:00
|
|
|
|
2023-12-14 08:58:05 +00:00
|
|
|
if tmux has-session -t="${session_name}" 2> /dev/null; then
|
|
|
|
exec tmux attach -t "${session_name}"
|
2021-09-17 21:35:47 +00:00
|
|
|
fi
|
|
|
|
|
2023-12-14 08:58:05 +00:00
|
|
|
# If a .tmux file exists within the selected directory, run it with the
|
|
|
|
# generated session name.
|
|
|
|
if [[ -e "${selected}/main" ]] && [[ -e "${selected}/main/.tmux" ]]; then
|
|
|
|
"${selected}/main/.tmux" "${session_name}" "${selected}/main"
|
|
|
|
exit
|
|
|
|
elif [[ -e "${selected}/.tmux" ]]; then
|
|
|
|
"${selected}/.tmux" "${session_name}" "${selected}"
|
|
|
|
exit
|
2021-09-17 18:42:11 +00:00
|
|
|
fi
|
|
|
|
|
2023-12-14 08:58:05 +00:00
|
|
|
tmux_running=$(pgrep tmux)
|
|
|
|
|
|
|
|
# if [[ -z "${TMUX:-}" ]] && [[ -z "${tmux_running}" ]]; then
|
|
|
|
# if [[ -e "${selected}/main" ]]; then
|
|
|
|
# tmux new-session -d -s "${session_name}" -d -s "${session_name}" -c "${selected}/main"
|
|
|
|
# else
|
|
|
|
# tmux new-session -d -s "${session_name}" -d -s "${session_name}" -c "${selected}"
|
|
|
|
# fi
|
|
|
|
# exit 0
|
|
|
|
# fi
|
|
|
|
|
|
|
|
if ! tmux has-session -t="${session_name}" 2> /dev/null; then
|
|
|
|
if [[ -e "${selected}/main" ]]; then
|
|
|
|
tmux new-session -d -s "${session_name}" -d -s "${session_name}" -c "${selected}/main"
|
|
|
|
else
|
|
|
|
tmux new-session -d -s "${session_name}" -d -s "${session_name}" -c "${selected}"
|
|
|
|
fi
|
2021-09-17 21:35:47 +00:00
|
|
|
fi
|
2023-12-14 08:58:05 +00:00
|
|
|
|
|
|
|
exec tmux switch-client -t "${session_name}"
|