From 09da2bc403cf8fcdb41e523aa60f43edf6d4b6b2 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 26 Jan 2024 14:58:41 +0000 Subject: [PATCH] Create `.tmux` files If `experimental.createTmuxStartupFile` is set in `build.yaml`. --- src/Action/CreateListOfFilesToGenerate.php | 7 ++++++ src/Action/GenerateConfigurationFiles.php | 4 ++++ src/DataTransferObject/ConfigDto.php | 4 ++++ templates/common/.tmux.twig | 27 ++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100755 templates/common/.tmux.twig diff --git a/src/Action/CreateListOfFilesToGenerate.php b/src/Action/CreateListOfFilesToGenerate.php index 2b04dbc..b8a5d32 100644 --- a/src/Action/CreateListOfFilesToGenerate.php +++ b/src/Action/CreateListOfFilesToGenerate.php @@ -146,6 +146,13 @@ final class CreateListOfFilesToGenerate break; } + if (Arr::get($configurationData, 'experimental.createTmuxStartupFile') === true) { + $filesToGenerate[] = new TemplateFile( + data: 'common/.tmux', + name: '.tmux', + ); + } + $filesToGenerate[] = new TemplateFile( data: 'common/.githooks/prepare-commit-msg', name: 'prepare-commit-msg', diff --git a/src/Action/GenerateConfigurationFiles.php b/src/Action/GenerateConfigurationFiles.php index e73bcb1..a5e6c5f 100644 --- a/src/Action/GenerateConfigurationFiles.php +++ b/src/Action/GenerateConfigurationFiles.php @@ -59,6 +59,10 @@ final class GenerateConfigurationFiles $this->filesystem->chmod("{$this->outputDir}/.githooks/prepare-commit-msg", 0755); } + if ($this->filesystem->exists("{$this->outputDir}/.tmux")) { + $this->filesystem->chmod("{$this->outputDir}/.tmux", 0755); + } + if ($this->filesystem->exists("{$this->outputDir}/run")) { $this->filesystem->chmod("{$this->outputDir}/run", 0755); } diff --git a/src/DataTransferObject/ConfigDto.php b/src/DataTransferObject/ConfigDto.php index fe01b6e..b2d7d73 100644 --- a/src/DataTransferObject/ConfigDto.php +++ b/src/DataTransferObject/ConfigDto.php @@ -116,6 +116,10 @@ final class ConfigDto new Assert\Type('bool'), ]), + 'createTmuxStartupFile' => new Assert\Optional([ + new Assert\Type('bool'), + ]), + 'runGitHooksBeforePush' => new Assert\Optional([ new Assert\Type('bool'), ]), diff --git a/templates/common/.tmux.twig b/templates/common/.tmux.twig new file mode 100755 index 0000000..1ef5c1e --- /dev/null +++ b/templates/common/.tmux.twig @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset + +session_name="${1:-{{ name }}}" +session_path="${2:-$(pwd)}" + +if tmux has-session -t="${session_name}" 2> /dev/null; then + tmux attach -t "${session_name}" || + tmux switch-client -t "${session_name}" +fi + +tmux new-session -d -s "${session_name}" -n vim -c "${session_path}" + +# 1. Main window: Vim. +tmux send-keys -t "${session_name}:vim" "nvim" Enter +tmux split-pane -t "${session_name}:vim" -h -c "${session_path}" -p 40 +tmux send-keys -t "${session_name}:vim.right" "./run start" Enter + +# 2. General shell use. +tmux new-window -t "${session_name}" -c "${session_path}" + +tmux switch-client -t "${session_name}:vim.left" || + tmux attach -t "${session_name}:vim.left" + +# vim: ft=bash