diff --git a/README.md b/README.md index 93e99d2..258b8a1 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,10 @@ Scaffold out a new package or theme. > This creates a new directory under `$OMF_CONFIG/{pkg | themes}/` with a template. +#### `omf search` _`-t|--theme / -pkg|--package`_ _``_ + +Searches Oh My Fish's database for a given package, theme or both. It also supports fuzzy search, so if you are not sure of the name you can simply `omf search simple`. + #### `omf submit` _`pkg/`_ _`[]`_ Add a new package. To add a theme, use `omf submit` _`themes/`_ _``_. diff --git a/pkg/omf/completions/omf.fish b/pkg/omf/completions/omf.fish index 3b8045e..904073a 100644 --- a/pkg/omf/completions/omf.fish +++ b/pkg/omf/completions/omf.fish @@ -30,6 +30,7 @@ complete -c omf -f -a remove -n "__fish_use_subcommand" -d "Remove a theme or complete -c omf -f -a update -n "__fish_use_subcommand" -d "Update Oh My Fish" complete -c omf -f -a cd -n "__fish_use_subcommand" -d "Change directory to plugin/theme directory" complete -c omf -f -a new -n "__fish_use_subcommand" -d "Create a new package from a template" +complete -c omf -f -a search -n "__fish_use_subcommand" -d "Search the database for a theme, package or both" complete -c omf -f -a submit -n "__fish_use_subcommand" -d "Submit a package to the registry" complete -c omf -f -a help -n "__fish_use_subcommand" -d "Display this help" complete -c omf -f -a destroy -n "__fish_use_subcommand" -d "Remove Oh My Fish" diff --git a/pkg/omf/functions/cli/omf.cli.help.fish b/pkg/omf/functions/cli/omf.cli.help.fish index 1691f57..d21bb16 100644 --- a/pkg/omf/functions/cli/omf.cli.help.fish +++ b/pkg/omf/functions/cli/omf.cli.help.fish @@ -89,6 +89,19 @@ function omf.cli.help -a command omf remove l " + case "search" + echo \n"\ + Search for a package or theme. + + "(omf::dim)"Usage:"(omf::off)" + omf search ("(omf::dim)"-pkg/--package"(omf::off)" | "(omf::dim)"-t/--theme"(omf::off)") "(omf::em)""(omf::off)" Search for a package or theme + + "(omf::dim)"Examples:"(omf::off)" + omf search -pkg nvm + omf search -t bobthefish + omf search vi + " + case "s" "submit" echo \n"\ Submit a package to the registry. @@ -130,6 +143,7 @@ function omf.cli.help -a command omf "(omf::em)"install"(omf::off)" [|] omf "(omf::em)"theme"(omf::off)" [] omf "(omf::em)"remove"(omf::off)" [] + omf "(omf::em)"search"(omf::off)" [] omf "(omf::em)"update"(omf::off)" omf "(omf::em)"help"(omf::off)" [] @@ -142,6 +156,7 @@ function omf.cli.help -a command "(omf::em)"u"(omf::off)"pdate Update Oh My Fish. "(omf::em)"c"(omf::off)"d Change directory to plugin/theme directory. "(omf::em)"n"(omf::off)"ew Create a new package from a template. + "(omf::em)"search"(omf::off)" Search for a package or theme. "(omf::em)"s"(omf::off)"ubmit Submit a package to the registry. "(omf::em)"destroy"(omf::off)" Uninstall Oh My Fish. "(omf::em)"doctor"(omf::off)" Troubleshoot Oh My Fish. diff --git a/pkg/omf/functions/cli/omf.cli.search.fish b/pkg/omf/functions/cli/omf.cli.search.fish new file mode 100644 index 0000000..b7d04ec --- /dev/null +++ b/pkg/omf/functions/cli/omf.cli.search.fish @@ -0,0 +1,26 @@ +function omf.cli.search -d "CLI parser for the search command" + + switch (count $argv); + case 1; + omf.search.pkg $argv[1] + echo + omf.search.theme $argv[1] + case 2; + switch "$argv[1]" + case "-pkg" "--package"; + omf.search.pkg $argv[2] + case "-t" "--theme"; + omf.search.theme $argv[2] + case '*'; + __omf.cli.search.usage + end + case '*'; + __omf.cli.search.usage + end +end + +function __omf.cli.search.usage -d "Print usage" + + echo (omf::err)"Usage: omf search ([-t | --theme]) ([-pkg | --package]) item"(omf::off) + +end diff --git a/pkg/omf/functions/omf.fish b/pkg/omf/functions/omf.fish index 5ee4a52..15c9661 100644 --- a/pkg/omf/functions/omf.fish +++ b/pkg/omf/functions/omf.fish @@ -64,6 +64,9 @@ function omf -d "Oh My Fish" case "u" "update" omf.cli.update $arguments + case "search" + omf.cli.search $arguments + case "*" echo (omf::err)"$argv[1] option not recognized"(omf::off) 1^&2 return $OMF_UNKNOWN_OPT diff --git a/pkg/omf/functions/search/omf.search.pkg.fish b/pkg/omf/functions/search/omf.search.pkg.fish new file mode 100644 index 0000000..b814ffd --- /dev/null +++ b/pkg/omf/functions/search/omf.search.pkg.fish @@ -0,0 +1,10 @@ +function omf.search.pkg -a item -d "Search db/pkg for the specified item" + + set -l available_pkg (omf.packages.list --database --plugin) + echo (omf::under)"Packages"(omf::off) + + set -l regex "([A-Za-z0-9-]*)($item)([A-Za-z0-9-]*)" + + echo $available_pkg | egrep -io $regex | column + +end diff --git a/pkg/omf/functions/search/omf.search.theme.fish b/pkg/omf/functions/search/omf.search.theme.fish new file mode 100644 index 0000000..61a32a8 --- /dev/null +++ b/pkg/omf/functions/search/omf.search.theme.fish @@ -0,0 +1,10 @@ +function omf.search.theme -a item -d "Search db/theme for the specified item" + + set -l available_theme (omf.packages.list --database --theme) + echo (omf::under)"Themes"(omf::off) + + set -l regex "([A-Za-z0-9-]*)($item)([A-Za-z0-9-]*)" + + echo $available_theme | egrep -io $regex | column + +end diff --git a/pkg/omf/init.fish b/pkg/omf/init.fish index fc016d6..9db491e 100644 --- a/pkg/omf/init.fish +++ b/pkg/omf/init.fish @@ -24,5 +24,5 @@ function init -a path --on-event init_omf set_color normal end - autoload $path/functions/{compat,core,packages,themes,bundle,util,repo,cli} + autoload $path/functions/{compat,core,packages,themes,bundle,util,repo,cli,search} end