From 988947be5eba4ad14f04fab8a45f6feb20e49b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Fri, 30 Jun 2023 20:49:14 +0200 Subject: [PATCH 1/3] feat(base): add fzf file open alias --- modules/profiles/base.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/profiles/base.nix b/modules/profiles/base.nix index 86a70be..518ae72 100644 --- a/modules/profiles/base.nix +++ b/modules/profiles/base.nix @@ -45,6 +45,8 @@ in mv = "mv -i"; cd = "z"; + f = "fzf --multi --bind \"enter:become($EDITOR {+})\""; + nixos-switch = nom-system-command "sudo nixos-rebuild switch --flake ~/.dotfiles"; nixos-boot = nom-system-command "sudo nixos-rebuild boot --flake ~/.dotfiles"; nixos-update = "pushd ~/.dotfiles && nix flake update && popd"; From ba7cc101882bf76efc4a63f26c3f13d62d4d6c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Fri, 30 Jun 2023 20:50:25 +0200 Subject: [PATCH 2/3] feat(tmux): add tmux attach + fzf script --- modules/programs/tmux.nix | 54 +++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/modules/programs/tmux.nix b/modules/programs/tmux.nix index 912f7ad..369aec5 100644 --- a/modules/programs/tmux.nix +++ b/modules/programs/tmux.nix @@ -4,13 +4,13 @@ with lib; let cfg = config.my.programs.tmux; - tmux-sessionizer = pkgs.writeShellApplication { - name = "ts"; - runtimeInputs = with pkgs; [ tmux findutils coreutils procps fd ]; + fzf1 = pkgs.writeShellApplication { + name = "fzf1"; + runtimeInputs = with pkgs; [ coreutils fzf ]; text = '' #!/usr/bin/env bash - options=$(fd -HIg '.git' ~/ --min-depth 1 --max-depth 5 --type d --prune --exec dirname {} | fzf --filter "''$*") + options=$(fzf --filter "''$*" < /dev/stdin) if [[ -z $options ]]; then exit 1 @@ -24,17 +24,48 @@ let exit 0 fi + echo "$selected" + ''; + }; + + tmux-switch = pkgs.writeShellApplication { + name = "tmux-switch"; + runtimeInputs = with pkgs; [ tmux ]; + text = '' + #!/usr/bin/env bash + if [[ -z ''${TMUX+x} ]]; then + tmux attach -t "$1" + else + tmux switch-client -t "$1" + fi + ''; + }; + + tmux-sessionizer = pkgs.writeShellApplication { + name = "ts"; + runtimeInputs = with pkgs; [ tmux findutils coreutils procps fd fzf ]; + text = '' + #!/usr/bin/env bash + + selected=$(fd -HIg '.git' ~/ --min-depth 1 --max-depth 5 --type d --prune --exec dirname {} | ${getExe fzf1} "$*") + selected_name=$(basename "$selected" | tr . _) if ! tmux has-session -t="$selected_name" 2> /dev/null; then tmux new-session -ds "$selected_name" -c "$selected" fi - if [[ -z ''${TMUX+x} ]]; then - tmux attach -t "$selected_name" - else - tmux switch-client -t "$selected_name" - fi + ${getExe tmux-switch} "$selected_name" + ''; + }; + + tmux-attach = pkgs.writeShellApplication { + name = "ta"; + runtimeInputs = with pkgs; [ tmux ]; + text = '' + #!/usr/bin/env bash + selected=$(tmux list-sessions -F '#{session_name}' | ${getExe fzf1} "$*") + ${getExe tmux-switch} "$selected" ''; }; @@ -64,7 +95,10 @@ in config = mkIf cfg.enable { my.shell.abbreviations.t = "tmux"; - home-manager.users.moritz.home.packages = [ tmux-sessionizer ]; + home-manager.users.moritz.home.packages = [ + tmux-sessionizer + tmux-attach + ]; home-manager.users.moritz.programs = { tmux = { enable = true; From 3e8ff2e064dfb8d6f17b51defb78a884492e000a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Fri, 30 Jun 2023 20:50:53 +0200 Subject: [PATCH 3/3] fix(tmux): accidentally creating extra sessions --- modules/programs/tmux.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/programs/tmux.nix b/modules/programs/tmux.nix index 369aec5..32836bd 100644 --- a/modules/programs/tmux.nix +++ b/modules/programs/tmux.nix @@ -106,7 +106,6 @@ in customPaneNavigationAndResize = true; keyMode = "vi"; mouse = true; - newSession = true; prefix = "C-Space"; sensibleOnTop = false; plugins = with pkgs.tmuxPlugins; [