From 335a6afd5f47b58861dfa788f37369b64583efe7 Mon Sep 17 00:00:00 2001 From: outremonde Date: Fri, 13 Jun 2025 22:05:16 -0400 Subject: finished projinit and qr commands Former-commit-id: 2c9217e7b6e27de846a109d7834654032fc11f52 --- features/user/cli/shells/nushell/default.nix | 31 ++++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'features/user/cli/shells/nushell') diff --git a/features/user/cli/shells/nushell/default.nix b/features/user/cli/shells/nushell/default.nix index c0c8b40..b8abba5 100644 --- a/features/user/cli/shells/nushell/default.nix +++ b/features/user/cli/shells/nushell/default.nix @@ -59,33 +59,42 @@ in { } # define a function to initialize a direnv project - def projinit [path?: string] { + def projinit [path?: string] { # this code sucks but I'm tired of working on it mut path = $path if ($path == null) { $path = "./" } let path = $path | path expand - cp -r ${./direnv-project-template}/* $path - chmod +w $"($path)/" - direnv allow + let template_path = "${./direnv-project-template}" | path expand + let template_files = ls -a $template_path | get name + $template_files | each {|item| cp $item $path} + ls -a $path | get name | filter {|name| $template_files | str contains ($name | path basename) | any {}} | each {|name| chmod +w $name} + if (try {git rev-parse --is-inside-work-tree e> /dev/null}) != null { + direnv allow + } else { + git init + direnv allow + } + git add $"($path)/." + git commit -m "initialized" } # Quickly create a nix shell. - def qs [...pkgs] { - if $pkgs == [] { + def qs [...packages] { + if $packages == [] { print "Please use a package name." return } - let pkgs_string = $pkgs - | each {|pkg| return $"nixpkgs#($pkg) "} + let packages_string = $packages + | each {|package| return $"nixpkgs#($package) "} | str join | str trim - nu -c $"nix shell ($pkgs_string)" + nu -c $"nix shell ($packages_string)" } # Quickly run a nix package. - def qr [pkg: string] { - nix run $"nixpkgs#($pkg)" + def qr --wrapped [package: string ...arguments] { + nix run $"nixpkgs#($package)" -- ($arguments | str join " ") } ''; }; -- cgit v1.2.3