feat(tmux): add tmux attach + fzf script

nixos
Moritz Böhme 2023-06-30 20:50:25 +02:00
parent 988947be5e
commit ba7cc10188
Signed by: moritz
GPG Key ID: 970C6E89EB0547A9
1 changed files with 44 additions and 10 deletions

View File

@ -4,13 +4,13 @@ with lib;
let let
cfg = config.my.programs.tmux; cfg = config.my.programs.tmux;
tmux-sessionizer = pkgs.writeShellApplication { fzf1 = pkgs.writeShellApplication {
name = "ts"; name = "fzf1";
runtimeInputs = with pkgs; [ tmux findutils coreutils procps fd ]; runtimeInputs = with pkgs; [ coreutils fzf ];
text = '' text = ''
#!/usr/bin/env bash #!/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 if [[ -z $options ]]; then
exit 1 exit 1
@ -24,17 +24,48 @@ let
exit 0 exit 0
fi 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 . _) selected_name=$(basename "$selected" | tr . _)
if ! tmux has-session -t="$selected_name" 2> /dev/null; then if ! tmux has-session -t="$selected_name" 2> /dev/null; then
tmux new-session -ds "$selected_name" -c "$selected" tmux new-session -ds "$selected_name" -c "$selected"
fi fi
if [[ -z ''${TMUX+x} ]]; then ${getExe tmux-switch} "$selected_name"
tmux attach -t "$selected_name" '';
else };
tmux switch-client -t "$selected_name"
fi 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 { config = mkIf cfg.enable {
my.shell.abbreviations.t = "tmux"; 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 = { home-manager.users.moritz.programs = {
tmux = { tmux = {
enable = true; enable = true;