tmux-sessionizer: 2.0
This commit is contained in:
parent
7c2bf6601a
commit
9fee4f6f3d
2 changed files with 38 additions and 37 deletions
|
@ -1,12 +1,42 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) getExe getExe';
|
||||
inherit (lib) getExe;
|
||||
|
||||
cfg = config.snowhawk.tmux.sessionizer;
|
||||
tmuxCfg = config.snowhawk.tmux;
|
||||
|
||||
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)
|
||||
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
|
||||
{
|
||||
options.snowhawk.tmux.sessionizer = {
|
||||
|
@ -25,8 +55,9 @@ in
|
|||
];
|
||||
};
|
||||
|
||||
pkg = lib.mkOption {
|
||||
package = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
default = tmux-sessionizer;
|
||||
description = ''
|
||||
tmux-sessionizer binary package
|
||||
'';
|
||||
|
@ -34,37 +65,10 @@ in
|
|||
};
|
||||
|
||||
config = lib.mkIf enable {
|
||||
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
|
||||
home.packages = [ cfg.package ];
|
||||
|
||||
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"
|
||||
'';
|
||||
});
|
||||
|
||||
home.packages = [ cfg.pkg ];
|
||||
programs.tmux.extraConfig = ''
|
||||
bind-key -r f run-shell "tmux neww ${getExe cfg.package}"
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
{ lib, config, pkgs, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) getExe optionalString;
|
||||
inherit (lib) getExe;
|
||||
|
||||
cfg = config.snowhawk.tmux;
|
||||
sessionizer = cfg.sessionizer;
|
||||
macos = config.snowhawk.macos.enable;
|
||||
in
|
||||
{
|
||||
|
@ -41,8 +40,6 @@ in
|
|||
|
||||
bind '"' split-window -v -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}"
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue