@@ -75,19 +75,26 @@ function print_source_help () {
7575 echo " if 'source' is given as 'owner/repo', it will default to 'github:owner/repo'"
7676}
7777
78+ function show_tree_without_default () {
79+ # TODO: why doesn't `grep -v "(default.nix|profiles|modules)$"` work?
80+ exa ${3} -Th " $1 " | grep -v " default.nix" | grep -v " profiles" | grep -v " modules" | sed ' s/\.nix//g' | tail -n +1 || echo " $2 "
81+ }
82+
7883GIT_CACHE=" $HOME /.cache/bud/git"
7984
8085case " $1 " in
8186 " show" )
8287 shift 1
8388
8489 url=" $1 "
90+ ty=" $2 "
8591
8692 if [[ -z " $url " ]]; then
87- echo " Show profiles available in the specified source\n"
88- echo " Usage: show source\n"
93+ echo " Show profiles / modules / users / hosts available in the specified source\n"
94+ echo " Usage: show source (profiles|users|hosts|modules) \n"
8995 print_source_help
90- echo " if 'source' is '.', it will show your own profiles"
96+ echo " if 'source' is '.', it will show your own profiles / users / hosts / modules\n"
97+ echo " if none of 'profiles', 'users', 'hosts' or 'modules' are specified, it will default to 'profiles'"
9198 exit 1
9299 fi
93100
@@ -100,19 +107,37 @@ case "$1" in
100107 fetch_repo " $url " " $repo_path " || exit $?
101108 fi
102109
103- echo " nixos profiles:"
104- exa -Th " $repo_path /profiles" | grep -v " default.nix" | tail -n +2 || echo " no nixos profiles found"
105- echo " home-manager profiles:"
106- exa -Th " $repo_path /users/profiles" | grep -v " default.nix" | tail -n +2 || echo " no home-manager profiles found"
110+ case " $ty " in
111+ " users" )
112+ echo " users:"
113+ show_tree_without_default " $repo_path /users" " no users found" " --level=1"
114+ ;;
115+ " hosts" )
116+ echo " hosts:"
117+ show_tree_without_default " $repo_path /hosts" " no hosts found" " --level=1"
118+ ;;
119+ " modules" )
120+ echo " nixos modules:"
121+ show_tree_without_default " $repo_path /modules" " no nixos profiles found"
122+ echo " home-manager modules:"
123+ show_tree_without_default " $repo_path /users/modules" " no home-manager profiles found"
124+ ;;
125+ * )
126+ echo " nixos profiles:"
127+ show_tree_without_default " $repo_path /profiles" " no nixos profiles found"
128+ echo " home-manager profiles:"
129+ show_tree_without_default " $repo_path /users/profiles" " no home-manager profiles found"
130+ ;;
131+ esac
107132 ;;
108133 " remove" )
109134 shift 1
110135
111136 attr_origpath=$1
112137
113138 if [[ -z " $attr_origpath " ]]; then
114- echo " Remove a profile from your config\n"
115- echo " Usage: remove ( nixos|hm). profiles.[PROFILE ]"
139+ echo " Remove a profile / user / host / module from your config\n"
140+ echo " Usage: remove nixos.(profiles|users|hosts|modules).[NAME] / add source hm.( profiles|modules).[NAME ]"
116141 exit 1
117142 fi
118143
@@ -133,8 +158,8 @@ case "$1" in
133158 attr_origpath=$2
134159
135160 if [[ -z " $url " || -z " $attr_origpath " ]]; then
136- echo " Add a profile from the specified source\n"
137- echo " Usage: add source ( nixos|hm). profiles.[PROFILE ]\n"
161+ echo " Add a profile / user / host / module from the specified source\n"
162+ echo " Usage: add source nixos.(profiles|users|hosts|modules).[NAME] / add source hm.( profiles|modules).[NAME ]\n"
138163 print_source_help
139164 exit 1
140165 fi
@@ -157,9 +182,9 @@ case "$1" in
157182 ;;
158183 * )
159184 echo " Available subcommands are:"
160- echo " - 'add': Add a profile from the specified source"
161- echo " - 'show': Show profiles available in the specified source"
162- echo " - 'remove': Remove a profile from your config\n"
185+ echo " - 'add': Add a profile / user / host / module from the specified source"
186+ echo " - 'show': Show profiles / users / hosts / modules available in the specified source"
187+ echo " - 'remove': Remove a profile / user / host / module from your config\n"
163188 echo " run 'bud cfg command' for more info about a command"
164189 exit 1
165190 ;;
0 commit comments