Add basic tmux support

This commit is contained in:
GHOSCHT 2024-05-08 09:53:50 +02:00
parent af58abcf3c
commit d483cad685
Signed by: ghoscht
GPG key ID: 2C2C1C62A5388E82
8 changed files with 120 additions and 4 deletions

View file

@ -3,5 +3,6 @@
./nvim
./vscode.nix
./intellij.nix
./tmux.nix
];
}

View file

@ -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 = ''

View file

@ -1,3 +1,5 @@
vim.keymap.set("", "<Space>", "<Nop>")
vim.keymap.set("", "<C-Space>", "<Nop>")
vim.g.mapleader = " "
vim.g.maplocalleader = " "

View file

@ -0,0 +1,5 @@
-- Navigate vim panes better
vim.keymap.set("n", "<c-k>", ":wincmd k<CR>")
vim.keymap.set("n", "<c-j>", ":wincmd j<CR>")
vim.keymap.set("n", "<c-h>", ":wincmd h<CR>")
vim.keymap.set("n", "<c-l>", ":wincmd l<CR>")

View file

@ -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}"
'';
}
];
};
}

View file

@ -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 {};
}

View file

@ -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";
}

View file

@ -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