From d483cad68502171929311083b9a9a539e6e34f18 Mon Sep 17 00:00:00 2001 From: GHOSCHT <31184695+GHOSCHT@users.noreply.github.com> Date: Wed, 8 May 2024 09:53:50 +0200 Subject: [PATCH] Add basic tmux support --- home/features/coding/default.nix | 1 + home/features/coding/nvim/default.nix | 11 ++-- home/features/coding/nvim/options.lua | 2 + .../coding/nvim/plugin/vim-tmux-navigator.lua | 5 ++ home/features/coding/tmux.nix | 43 +++++++++++++++ pkgs/default.nix | 1 + pkgs/tmuxinator-fzf-start/default.nix | 6 ++ .../tmuxinator-fzf-start.sh | 55 +++++++++++++++++++ 8 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 home/features/coding/nvim/plugin/vim-tmux-navigator.lua create mode 100644 home/features/coding/tmux.nix create mode 100644 pkgs/tmuxinator-fzf-start/default.nix create mode 100755 pkgs/tmuxinator-fzf-start/tmuxinator-fzf-start.sh diff --git a/home/features/coding/default.nix b/home/features/coding/default.nix index 83835d9..006bbeb 100644 --- a/home/features/coding/default.nix +++ b/home/features/coding/default.nix @@ -3,5 +3,6 @@ ./nvim ./vscode.nix ./intellij.nix + ./tmux.nix ]; } diff --git a/home/features/coding/nvim/default.nix b/home/features/coding/nvim/default.nix index 44015a8..52049c8 100644 --- a/home/features/coding/nvim/default.nix +++ b/home/features/coding/nvim/default.nix @@ -188,10 +188,7 @@ in { type = "lua"; } - { - plugin = barbar-nvim; - config = builtins.readFile ./plugin/barbar.lua; - } + barbar-nvim { plugin = nvim-surround; @@ -204,6 +201,12 @@ in { rainbow-delimiters-nvim rustaceanvim + + { + plugin = vim-tmux-navigator; + config = builtins.readFile ./plugin/vim-tmux-navigator.lua; + type = "lua"; + } ]; extraLuaConfig = '' diff --git a/home/features/coding/nvim/options.lua b/home/features/coding/nvim/options.lua index b8a6d3b..bca394f 100644 --- a/home/features/coding/nvim/options.lua +++ b/home/features/coding/nvim/options.lua @@ -1,3 +1,5 @@ +vim.keymap.set("", "", "") +vim.keymap.set("", "", "") vim.g.mapleader = " " vim.g.maplocalleader = " " diff --git a/home/features/coding/nvim/plugin/vim-tmux-navigator.lua b/home/features/coding/nvim/plugin/vim-tmux-navigator.lua new file mode 100644 index 0000000..09d5bb1 --- /dev/null +++ b/home/features/coding/nvim/plugin/vim-tmux-navigator.lua @@ -0,0 +1,5 @@ +-- Navigate vim panes better +vim.keymap.set("n", "", ":wincmd k") +vim.keymap.set("n", "", ":wincmd j") +vim.keymap.set("n", "", ":wincmd h") +vim.keymap.set("n", "", ":wincmd l") diff --git a/home/features/coding/tmux.nix b/home/features/coding/tmux.nix new file mode 100644 index 0000000..2ae93a0 --- /dev/null +++ b/home/features/coding/tmux.nix @@ -0,0 +1,43 @@ +{pkgs, ...}: { + home.packages = [pkgs.tmuxinator-fzf-start]; + programs.tmux = { + enable = true; + keyMode = "vi"; + customPaneNavigationAndResize = true; + mouse = true; + tmuxinator.enable = true; + shortcut = "Space"; + extraConfig = '' + bind % split-window -h -c "#{pane_current_path}" + bind \'%\' split-window -v -c "#{pane_current_path}" + ''; + plugins = with pkgs; [ + tmuxPlugins.vim-tmux-navigator + { + plugin = tmuxPlugins.catppuccin; + extraConfig = '' + set -g status-position top + + set -g @catppuccin_window_left_separator "" + set -g @catppuccin_window_right_separator " " + set -g @catppuccin_window_middle_separator " █" + set -g @catppuccin_window_number_position "right" + + set -g @catppuccin_window_default_fill "number" + set -g @catppuccin_window_default_text "#W" + + set -g @catppuccin_window_current_fill "number" + set -g @catppuccin_window_current_text "#W" + + set -g @catppuccin_status_modules_right "directory session" + set -g @catppuccin_status_left_separator " " + set -g @catppuccin_status_right_separator "" + set -g @catppuccin_status_fill "icon" + set -g @catppuccin_status_connect_separator "no" + + set -g @catppuccin_directory_text "#{pane_current_path}" + ''; + } + ]; + }; +} diff --git a/pkgs/default.nix b/pkgs/default.nix index 0893b3a..0527a76 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -6,4 +6,5 @@ feishin-appimage = pkgs.callPackage ./feishin {}; protonup-rs = pkgs.callPackage ./protonup-rs {}; rofi-audio-switcher = pkgs.callPackage ./rofi-audio-switcher {}; + tmuxinator-fzf-start = pkgs.callPackage ./tmuxinator-fzf-start {}; } diff --git a/pkgs/tmuxinator-fzf-start/default.nix b/pkgs/tmuxinator-fzf-start/default.nix new file mode 100644 index 0000000..a3cf7ec --- /dev/null +++ b/pkgs/tmuxinator-fzf-start/default.nix @@ -0,0 +1,6 @@ +{pkgs, ...}: +pkgs.stdenv.mkDerivation rec { + name = "tmuxinator-fzf-start"; + dontUnpack = true; + installPhase = "install -Dm755 ${./tmuxinator-fzf-start.sh} $out/bin/tmuxinator-fzf-start"; +} diff --git a/pkgs/tmuxinator-fzf-start/tmuxinator-fzf-start.sh b/pkgs/tmuxinator-fzf-start/tmuxinator-fzf-start.sh new file mode 100755 index 0000000..dfe3b41 --- /dev/null +++ b/pkgs/tmuxinator-fzf-start/tmuxinator-fzf-start.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +############################################################### +# Tmuxinator FZF Start +############################################################### +# +# Uses fzf to provide a selection list for tmuxinator projects. +# +# Overview: +# +# tmuxinator-fzf-start.sh will open fzf with a multi select +# list of tmuxinator projects. Upon selecting project/s each +# project will have `tmuxinator start` run, and when complete +# tmux will be attached, or if tmux is already running, a +# session selection interface will be provided. +# +# If an initial query is provided, and only one match results, +# the project will be automatically opened without user input. +# +# Usage: +# +# tmuxinator-fzf-start.sh +# tmuxinator-fzf-start.sh "Query" +# +# Expectations: +# +# - tmuxinator is on $PATH +# - fzf is on $PATH +# - tmux is on $PATH + +# Allow the user to select projects via fzf +SELECTED_PROJECTS=$(tmuxinator list -n | + tail -n +2 | + fzf --prompt="Project: " -m -1 -q "$1") + +if [ -n "$SELECTED_PROJECTS" ]; then + # Set the IFS to \n to iterate over \n delimited projects + IFS=$'\n' + + # Start each project without attaching + for PROJECT in $SELECTED_PROJECTS; do + tmuxinator start "$PROJECT" --no-attach # force disable attaching + done + + # If inside tmux then select session to switch, otherwise just attach + if [ -n "$TMUX" ]; then + SESSION=$(tmux list-sessions -F "#S" | fzf --prompt="Session: ") + if [ -n "$SESSION" ]; then + tmux switch-client -t "$SESSION" + fi + else + tmux attach-session + fi +fi +