work with .tmux files

This commit is contained in:
Oliver Davies 2023-12-14 08:58:05 +00:00
parent 74cf7c2a99
commit bb64b892aa
2 changed files with 63 additions and 14 deletions

29
.tmux Executable file
View file

@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
session_name="${1:-dotfiles}"
session_path="${2:-$(pwd)}"
if tmux has-session -t="${session_name}" 2> /dev/null; then
tmux attach -t "${session_name}"
exit
fi
tmux new-session -d -s "${session_name}" -n vim -c "${session_path}"
# 1. Main window: Vim
tmux split-pane -t "${session_name}:vim" -h -c "${session_path}"
tmux send-keys -t "${session_name}:vim.left" "nvim +GoToFile" Enter
tmux send-keys -t "${session_name}:vim.right" "git status" Enter
# 2. General shell use.
tmux new-window -t "${session_name}" -c "${session_path}"
if [[ -n "${TMUX:-}" ]]; then
tmux switch-client -t "${session_name}"
tmux select-window -t "${session_name}:vim.left"
else
tmux attach -t "${session_name}:vim.left"
fi

48
bin/t
View file

@ -1,31 +1,51 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -o nounset
set -o pipefail
if [[ $# -eq 1 ]]; then if [[ $# -eq 1 ]]; then
selected=$1 selected=$1
else else
selected=$(zoxide query -l | grep -v /tmp | grep -v "^${HOME}/\." | grep -v "^${HOME}/Code$" | grep -v "/main$" | fzf --reverse) selected=$(zoxide query -l | grep -v /tmp | grep -v "^${HOME}/\." | grep -v "^${HOME}/Code$" | grep -v "/main$" | fzf --reverse)
fi fi
if [[ -z $selected ]]; then if [[ -z "${selected}" ]]; then
exit 0 exit 0
fi fi
is_tmux_running=$(pgrep tmux) session_name=$(basename "${selected}" | sed 's/\./-/g')
selected_name=$(basename "$selected" | tr . -)
if [[ -z $TMUX ]] && [[ -z $is_tmux_running ]]; then if tmux has-session -t="${session_name}" 2> /dev/null; then
tmux new-session -s $selected_name -c $selected exec tmux attach -t "${session_name}"
exit 0
fi fi
# Create a new session if tmux does not already have a session matching the # If a .tmux file exists within the selected directory, run it with the
# selected session name. # generated session name.
if ! tmux has-session -t $selected_name 2> /dev/null; then if [[ -e "${selected}/main" ]] && [[ -e "${selected}/main/.tmux" ]]; then
tmux new-session -s $selected_name -c $selected -d "${selected}/main/.tmux" "${session_name}" "${selected}/main"
exit
elif [[ -e "${selected}/.tmux" ]]; then
"${selected}/.tmux" "${session_name}" "${selected}"
exit
fi fi
if [[ -z $TMUX ]]; then tmux_running=$(pgrep tmux)
tmux attach-session -t $selected_name
else # if [[ -z "${TMUX:-}" ]] && [[ -z "${tmux_running}" ]]; then
tmux switch-client -t $selected_name # 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
fi fi
exec tmux switch-client -t "${session_name}"