project-launcher changes
This commit is contained in:
@@ -7,23 +7,56 @@
|
||||
with lib; let
|
||||
cfg = config.cli.rofi-project-opener;
|
||||
|
||||
# Convert list of paths to colon-separated string
|
||||
projectDirsStr = concatStringsSep ":" cfg.projectDirs;
|
||||
# Project directory submodule type
|
||||
projectDirType = types.submodule {
|
||||
options = {
|
||||
path = mkOption {
|
||||
type = types.str;
|
||||
description = "Base directory path to scan for project subdirectories.";
|
||||
example = "~/dev";
|
||||
};
|
||||
args = mkOption {
|
||||
type = types.str;
|
||||
default = "";
|
||||
description = "Additional arguments to pass to opencode when launching projects from this directory.";
|
||||
example = "--agent Planner-Sisyphus";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# Convert projectDirs attrset to JSON for config file
|
||||
projectDirsJson = builtins.toJSON (
|
||||
mapAttrs (name: value: {
|
||||
path = value.path;
|
||||
args = value.args;
|
||||
}) cfg.projectDirs
|
||||
);
|
||||
in {
|
||||
options.cli.rofi-project-opener = {
|
||||
enable = mkEnableOption "Rofi-based project directory launcher";
|
||||
|
||||
projectDirs = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = ["~/dev" "~/projects"];
|
||||
type = types.attrsOf projectDirType;
|
||||
default = {
|
||||
dev = { path = "~/dev"; };
|
||||
projects = { path = "~/projects"; };
|
||||
};
|
||||
description = ''
|
||||
List of base directories to scan for project subdirectories.
|
||||
Attribute set of base directories to scan for project subdirectories.
|
||||
Each directory will be scanned for immediate subdirectories (non-hidden).
|
||||
Projects are displayed as "base_dir/project_name" in rofi.
|
||||
|
||||
Supports ~ for home directory expansion.
|
||||
Each entry can specify:
|
||||
- path: Base directory path (supports ~ for home directory)
|
||||
- args: Optional arguments to pass to opencode for projects in this directory
|
||||
'';
|
||||
example = literalExpression ''
|
||||
{
|
||||
nixpkgs = { path = "~/p/NIX/nixpkgs"; args = "--agent Planner-Sisyphus"; };
|
||||
dev = { path = "~/dev"; };
|
||||
work = { path = "~/work"; args = "--agent work-agent"; };
|
||||
}
|
||||
'';
|
||||
example = literalExpression ''["~/dev" "~/projects" "~/code"]'';
|
||||
};
|
||||
|
||||
terminal = mkOption {
|
||||
@@ -37,17 +70,21 @@ in {
|
||||
type = types.str;
|
||||
default = "";
|
||||
description = ''
|
||||
Custom command to pass to the terminal.
|
||||
Custom command to run in the terminal.
|
||||
|
||||
Use %s as a placeholder for the project path.
|
||||
If empty, defaults to opening a shell in the project directory and running opencode.
|
||||
Placeholders:
|
||||
- %s = project path
|
||||
- %a = project args (from projectDirs.<name>.args)
|
||||
|
||||
If empty, defaults to: cd to project, run "opencode %a"
|
||||
|
||||
Examples:
|
||||
- "" (empty) - Uses default: cd to project, run opencode
|
||||
- "-e zsh -c 'cd %s && opencode'" - Custom shell with explicit path
|
||||
- "--hold -e nvim" - Open editor directly (no %s = no cd)
|
||||
- "" (empty) - Uses default: cd to project, run opencode with args
|
||||
- "opencode %a" - Run opencode with project-specific args
|
||||
- "nvim" - Open editor (no args)
|
||||
- "myapp %s %a" - Custom app with path and args
|
||||
'';
|
||||
example = literalExpression ''"-e zsh -c 'cd %s && opencode'"'';
|
||||
example = literalExpression ''"opencode %a"'';
|
||||
};
|
||||
|
||||
rofiPrompt = mkOption {
|
||||
@@ -77,10 +114,12 @@ in {
|
||||
config = mkIf cfg.enable {
|
||||
home.packages = [pkgs.rofi-project-opener];
|
||||
|
||||
# Write config file (shell-independent)
|
||||
# Write JSON config file for project directories
|
||||
xdg.configFile."rofi-project-opener/projects.json".text = projectDirsJson;
|
||||
|
||||
# Write shell config file for other settings
|
||||
xdg.configFile."rofi-project-opener/config".text = ''
|
||||
# rofi-project-opener configuration
|
||||
PROJECT_DIRS="${projectDirsStr}"
|
||||
TERMINAL="${if isDerivation cfg.terminal then "${cfg.terminal}/bin/${cfg.terminal.pname or (builtins.baseNameOf (toString cfg.terminal))}" else cfg.terminal}"
|
||||
${optionalString (cfg.terminalCommand != "") ''TERMINAL_CMD="${cfg.terminalCommand}"''}
|
||||
ROFI_PROMPT="${cfg.rofiPrompt}"
|
||||
|
||||
Reference in New Issue
Block a user