diff --git a/.zshrc b/.zshrc index dbbb156..9e31d03 100644 --- a/.zshrc +++ b/.zshrc @@ -79,6 +79,7 @@ export FZF_DEFAULT_OPTS=" \ export GOPATH="$HOME/go" export PATH="$GOPATH/bin:$PATH" +export PATH="$HOME/scripts:$PATH" # pnpm export PNPM_HOME="/home/kyren/.local/share/pnpm" diff --git a/scripts/tms b/scripts/tms new file mode 100755 index 0000000..97407cb --- /dev/null +++ b/scripts/tms @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +if [[ $# -eq 1 ]]; then + selected=$1 +else + selected=$(find ~/projects ~/ ~/personal -mindepth 1 -maxdepth 1 -type d | fzf) +fi + +if [[ -z $selected ]]; then + exit 0 +fi + +selected_name=$(basename "$selected" | tr . _) +tmux_running=$(pgrep tmux) + +if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then + tmux new-session -s $selected_name -c $selected + tmux-session-setup $selected_name $selected + exit 0 +fi + +if ! tmux has-session -t=$selected_name 2> /dev/null; then + tmux new-session -ds $selected_name -c $selected + tmux-session-setup $selected_name $selected +fi + +tmux switch-client -t $selected_name diff --git a/scripts/tmux-session-setup b/scripts/tmux-session-setup new file mode 100755 index 0000000..835e2c5 --- /dev/null +++ b/scripts/tmux-session-setup @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +sess=$1 +dir=$2 + +if [ "$sess" = "eko" ]; then + tmux rename-window -t $sess:1 editor + tmux send-keys -t $sess:editor.1 "vim" C-m + + tmux new-window -t $sess -n app -c $dir + tmux split-window -t $sess:app.1 -v -c $dir + tmux send-keys -t $sess:app.2 "watchexec --exts=go './reload.sh'" C-m + tmux resize-pane -Z -t $sess:app.1 + + tmux new-window -t $sess -n logs -c $dir + tmux split-window -t $sess:logs.1 -h -c $dir + tmux split-window -t $sess:logs.2 -v -c $dir + tmux send-keys -t $sess:logs.1 "tail -f messages.log" C-m + tmux send-keys -t $sess:logs.2 "tail -f client.log" C-m + tmux send-keys -t $sess:logs.3 "go run ./cmd/server --stdout" C-m + + tmux select-window -t $sess:editor +elif [[ "$dir" == "$HOME/projects/"* ]]; then + tmux rename-window -t $sess:1 editor + tmux send-keys -t $sess:editor.1 "vim" C-m +fi