From 3f70a3fba50e13ebc462d5f1e598534e19f6d891 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Thu, 12 Jan 2023 13:46:41 -0600 Subject: [PATCH] tmux is king scripting and configs abound --- lib/alias.zsh | 3 +++ tmux/labbook.sh | 34 ++++++++++++++++++++++++++++++++++ tmux/tmux-functions.sh | 9 +++++++++ 3 files changed, 46 insertions(+) create mode 100755 tmux/labbook.sh create mode 100644 tmux/tmux-functions.sh diff --git a/lib/alias.zsh b/lib/alias.zsh index e751094..211ffc4 100755 --- a/lib/alias.zsh +++ b/lib/alias.zsh @@ -74,3 +74,6 @@ alias g="git" is-executable gum && alias plz="gum input --prompt='🔒' --password | sudo -nS" alias dockdots='docker run --rm -it -u "$(id -u):$(id -g)" -v "$PWD:/home/$USER/data" dots' + + +alias tmux-labbook="$DOTFILES_DIR/tmux/labbook.sh" diff --git a/tmux/labbook.sh b/tmux/labbook.sh new file mode 100755 index 0000000..c2afcc0 --- /dev/null +++ b/tmux/labbook.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +CURDIR="$(dirname "$(readlink -f "$0")")" +source "$CURDIR/tmux-functions.sh" + +# Set Session Name +SESSION="labbook" +WORK_DIR="$HOME/$SESSION" + +if ! [[ -d "$WORK_DIR" ]]; then + echo "expected to find $WORK_DIR but didn't" + exit 1 +fi + +# Only create tmux session if it doesn't already exist +if ! tmux list-sessions | grep $SESSION; then + # Start New Session with our name + tmux new-session -d -s $SESSION -c "$HOME/labbook" + + # Name first Pane and start zsh + tmux rename-window -t $SESSION:0 'Main' + tmux send-keys -t 'Main' + + # Create and setup pane for sphinx + tnw -t $SESSION:1 -n 'sphinx' + tsk -t 'sphinx' 'source ./.venv/bin/activate' Enter + tsk -t 'sphinx' 'make live' Enter + + # setup writing window + tnw -t $SESSION:2 -n 'writing' + tsk -t 'writing' "nvim ./now.md" Enter +fi + +# Attach Session, on the Main window +tmux attach-session -t $SESSION:0 diff --git a/tmux/tmux-functions.sh b/tmux/tmux-functions.sh new file mode 100644 index 0000000..da91936 --- /dev/null +++ b/tmux/tmux-functions.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# Custom tmux new window to apply $WORK_DIR for all commands +tnw() { + tmux new-window -c "$WORK_DIR" "$@" +} + +tsk() { + tmux send-keys "$@" +}