Compare commits

..

No commits in common. "581d729b79327cdf19e061920dd5660b657bc395" and "7c2bf6601a66e9736a0e1513ce4bee58cd404688" have entirely different histories.

2 changed files with 37 additions and 39 deletions

View File

@ -1,43 +1,12 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
inherit (lib) getExe; inherit (lib) getExe getExe';
cfg = config.snowhawk.tmux.sessionizer; cfg = config.snowhawk.tmux.sessionizer;
tmuxCfg = config.snowhawk.tmux; tmuxCfg = config.snowhawk.tmux;
enable = cfg.enable && tmuxCfg.enable; enable = cfg.enable && tmuxCfg.enable;
tmux-sessionizer = pkgs.writeShellApplication {
name = "tmux-sessionizer";
runtimeInputs = with pkgs; [ tmux fzf findutils coreutils procps ];
text = ''
if [[ $# -eq 1 ]]; then
selected=$1
else
selected=$(find -L ${lib.concatStringsSep " " cfg.paths} -mindepth 1 -maxdepth 1 -type d \
| fzf --tmux center --preview="ls {} --color || true")
fi
if [[ -z $selected ]]; then
exit 0
fi
selected_name=$(basename "$selected" | tr . _)
tmux_running=$(pgrep tmux)
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
tmux new-session -s "$selected_name" -c "$selected"
exit 0
fi
if ! tmux has-session -t="$selected_name" 2>/dev/null; then
tmux new-session -ds "$selected_name" -c "$selected"
fi
tmux switch-client -t "$selected_name"
'';
};
in in
{ {
options.snowhawk.tmux.sessionizer = { options.snowhawk.tmux.sessionizer = {
@ -56,9 +25,8 @@ in
]; ];
}; };
package = lib.mkOption { pkg = lib.mkOption {
type = lib.types.package; type = lib.types.package;
default = tmux-sessionizer;
description = '' description = ''
tmux-sessionizer binary package tmux-sessionizer binary package
''; '';
@ -66,10 +34,37 @@ in
}; };
config = lib.mkIf enable { config = lib.mkIf enable {
home.packages = [ cfg.package ]; snowhawk.tmux.sessionizer.pkg =
lib.mkDefault (pkgs.writeShellApplication {
name = "tmux-sessionizer";
runtimeInputs = with pkgs; [ tmux fzf findutils coreutils procps ];
text = ''
if [[ $# -eq 1 ]]; then
selected=$1
else
selected=$(find -L ${lib.concatStringsSep " " cfg.paths} -mindepth 1 -maxdepth 1 -type d | fzf)
fi
programs.tmux.extraConfig = '' if [[ -z $selected ]]; then
bind-key -r f run-shell "tmux neww ${getExe cfg.package}" exit 0
''; fi
selected_name=$(basename "$selected" | tr . _)
tmux_running=$(pgrep tmux)
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
tmux new-session -s "$selected_name" -c "$selected"
exit 0
fi
if ! tmux has-session -t="$selected_name" 2>/dev/null; then
tmux new-session -ds "$selected_name" -c "$selected"
fi
tmux switch-client -t "$selected_name"
'';
});
home.packages = [ cfg.pkg ];
}; };
} }

View File

@ -1,9 +1,10 @@
{ lib, config, pkgs, ... }: { lib, config, pkgs, ... }:
let let
inherit (lib) getExe; inherit (lib) getExe optionalString;
cfg = config.snowhawk.tmux; cfg = config.snowhawk.tmux;
sessionizer = cfg.sessionizer;
macos = config.snowhawk.macos.enable; macos = config.snowhawk.macos.enable;
in in
{ {
@ -40,6 +41,8 @@ in
bind '"' split-window -v -c "#{pane_current_path}" bind '"' split-window -v -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}" bind % split-window -h -c "#{pane_current_path}"
'' + optionalString sessionizer.enable ''
bind-key -r f run-shell "tmux neww ${getExe sessionizer.pkg}"
''; '';
}; };