1
0

dev-flakes.nix 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. { pkgs, ... }: {
  2. programs.fish = {
  3. functions = {
  4. flakeme = {
  5. body = ''
  6. set -l flake_dir "$HOME/nix-dots/dev-flakes"
  7. argparse 'l/list' -- $argv
  8. or return 1
  9. if set -q _flag_list
  10. if command -q tree
  11. tree --noreport -P '*.nix' --prune "$flake_dir"
  12. else
  13. for dir in "$flake_dir"/*/
  14. if test -d "$dir"
  15. echo (basename "$dir")"/"
  16. for file in "$dir"*.nix
  17. if test -f "$file"
  18. echo " └── "(basename "$file")
  19. end
  20. end
  21. end
  22. end
  23. end
  24. return 0
  25. end
  26. set -l tool $argv[1]
  27. set -l name $argv[2]
  28. if test -z "$tool"
  29. echo "Error: No tool specified."
  30. return 1
  31. end
  32. set -l target_dir "$flake_dir/$tool"
  33. if not test -d "$target_dir"
  34. echo "Error: Directory $target_dir does not exist."
  35. return 1
  36. end
  37. set -l target_file ""
  38. if test -n "$name"
  39. set target_file "$target_dir/$name.nix"
  40. else
  41. set target_file "$target_dir/default.nix"
  42. end
  43. if not test -f "$target_file"
  44. echo "Error: File $target_file does not exist."
  45. return 1
  46. end
  47. echo "Selected: $target_file"
  48. cp $target_file ./flake.nix
  49. '';
  50. };
  51. };
  52. completions = {
  53. flakeme = ''
  54. set -l flake_dir "$HOME/nix-dots/dev-flakes"
  55. complete -c flakeme -f
  56. complete -c flakeme -s l -l list -d "List available dev flakes"
  57. complete -c flakeme -n '__fish_is_nth_token 1' -a "(
  58. if test -d $flake_dir
  59. for dir in $flake_dir/*/
  60. basename \$dir
  61. end
  62. end
  63. )" -d "Tool directory"
  64. complete -c flakeme -n '__fish_is_nth_token 2' -a "(
  65. set -l cmd (commandline -opc)
  66. set -l tool \$cmd[2]
  67. if test -n \"\$tool\" -a -d $flake_dir/\$tool
  68. for file in $flake_dir/\$tool/*.nix
  69. if test -f \$file
  70. basename \$file .nix
  71. end
  72. end
  73. end
  74. )" -d "Flake template name"
  75. '';
  76. };
  77. };
  78. }