From 870efd0ddadb9f4826c72b10ed2aeb84b15e258c Mon Sep 17 00:00:00 2001 From: Bruno Pinto Date: Tue, 6 Oct 2015 21:31:44 +0100 Subject: [PATCH] Merge all omf list functions --- pkg/omf/cli/omf.bundle.install.fish | 4 +- pkg/omf/cli/omf.describe.fish | 3 +- pkg/omf/cli/omf.list_db_packages.fish | 11 --- pkg/omf/cli/omf.list_installed_packages.fish | 6 -- pkg/omf/cli/omf.list_installed_themes.fish | 3 - pkg/omf/cli/omf.list_local_packages.fish | 6 -- pkg/omf/cli/omf.list_themes.fish | 8 --- pkg/omf/cli/omf.packages.list.fish | 72 ++++++++++++++++++++ pkg/omf/completions/omf.fish | 10 +-- pkg/omf/omf.fish | 8 +-- 10 files changed, 85 insertions(+), 46 deletions(-) delete mode 100644 pkg/omf/cli/omf.list_db_packages.fish delete mode 100644 pkg/omf/cli/omf.list_installed_packages.fish delete mode 100644 pkg/omf/cli/omf.list_installed_themes.fish delete mode 100644 pkg/omf/cli/omf.list_local_packages.fish delete mode 100644 pkg/omf/cli/omf.list_themes.fish create mode 100644 pkg/omf/cli/omf.packages.list.fish diff --git a/pkg/omf/cli/omf.bundle.install.fish b/pkg/omf/cli/omf.bundle.install.fish index 5ef6a1a..ccd9456 100644 --- a/pkg/omf/cli/omf.bundle.install.fish +++ b/pkg/omf/cli/omf.bundle.install.fish @@ -2,8 +2,8 @@ function omf.bundle.install set bundle $OMF_CONFIG/bundle if test -f $bundle - set packages (omf.list_local_packages) - set themes (omf.list_installed_themes) + set packages (omf.packages.list --installed --plugin) + set themes (omf.packages.list --installed --theme) set bundle_contents (cat $bundle | sort -u) for record in $bundle_contents diff --git a/pkg/omf/cli/omf.describe.fish b/pkg/omf/cli/omf.describe.fish index 7ec9871..e3862e4 100644 --- a/pkg/omf/cli/omf.describe.fish +++ b/pkg/omf/cli/omf.describe.fish @@ -1,10 +1,11 @@ function omf.describe -a name if test (count $argv) -eq 0 - for package in (omf.list_db_packages) + for package in (omf.packages.list --database) echo $package - (omf.describe $package) end else set package_path $OMF_PATH/db/pkg/$name + if test -e $package_path set url (cat $package_path) set repo (basename (dirname $url))/(basename $url) diff --git a/pkg/omf/cli/omf.list_db_packages.fish b/pkg/omf/cli/omf.list_db_packages.fish deleted file mode 100644 index e17a225..0000000 --- a/pkg/omf/cli/omf.list_db_packages.fish +++ /dev/null @@ -1,11 +0,0 @@ -# List all packages available to install from the registry. -function omf.list_db_packages -a skip_installed - for item in (basename $OMF_PATH/db/pkg/*) - if begin - test -z $skip_installed - or not contains $item (basename {$OMF_PATH,$OMF_CONFIG}/pkg/*) - end - echo $item - end - end -end diff --git a/pkg/omf/cli/omf.list_installed_packages.fish b/pkg/omf/cli/omf.list_installed_packages.fish deleted file mode 100644 index 05649cb..0000000 --- a/pkg/omf/cli/omf.list_installed_packages.fish +++ /dev/null @@ -1,6 +0,0 @@ -# List all packages installed from the registry. -function omf.list_installed_packages - for item in (basename $OMF_PATH/pkg/*) - test $item = omf; or echo $item - end -end diff --git a/pkg/omf/cli/omf.list_installed_themes.fish b/pkg/omf/cli/omf.list_installed_themes.fish deleted file mode 100644 index 1886382..0000000 --- a/pkg/omf/cli/omf.list_installed_themes.fish +++ /dev/null @@ -1,3 +0,0 @@ -function omf.list_installed_themes - basename $OMF_PATH/themes/* -end diff --git a/pkg/omf/cli/omf.list_local_packages.fish b/pkg/omf/cli/omf.list_local_packages.fish deleted file mode 100644 index b79ec54..0000000 --- a/pkg/omf/cli/omf.list_local_packages.fish +++ /dev/null @@ -1,6 +0,0 @@ -# List all custom packages and packages installed from the registry. -function omf.list_local_packages - for item in (basename {$OMF_PATH,$OMF_CONFIG}/pkg/*) - test $item = omf; or echo $item - end -end diff --git a/pkg/omf/cli/omf.list_themes.fish b/pkg/omf/cli/omf.list_themes.fish deleted file mode 100644 index 26c0413..0000000 --- a/pkg/omf/cli/omf.list_themes.fish +++ /dev/null @@ -1,8 +0,0 @@ -function omf.list_themes - set -l seen "" - for theme in (basename $OMF_PATH/db/themes/*) \ - (basename {$OMF_PATH,$OMF_CONFIG}/themes/*) - contains $theme $seen; or echo $theme - set seen $seen $theme - end -end diff --git a/pkg/omf/cli/omf.packages.list.fish b/pkg/omf/cli/omf.packages.list.fish new file mode 100644 index 0000000..55f8517 --- /dev/null +++ b/pkg/omf/cli/omf.packages.list.fish @@ -0,0 +1,72 @@ +function __omf.packages.sort + for package in (echo $argv | tr ' ' '\n' | sort); echo $package; end +end + +function __omf.packages.list -a type + set -l list + + test "$type" = "--theme"; or for package in (basename {$OMF_CONFIG,$OMF_PATH/db}/pkg/*) + set list $list $package + end + + test "$type" = "--plugin"; or for package in (basename {$OMF_CONFIG,$OMF_PATH/db}/themes/*) + set list $list $package + end + + __omf.packages.sort $list +end + +function __omf.packages.list.available -a type + set -l list + + test "$type" = "--theme"; or for package in (basename $OMF_PATH/db/pkg/*) + contains $package (basename {$OMF_CONFIG,$OMF_PATH}/pkg/*); or set list $list $package + end + + test "$type" = "--plugin"; or for package in (basename $OMF_PATH/db/themes/*) + contains $package (basename {$OMF_CONFIG,$OMF_PATH}/themes/*); or set list $list $package + end + + __omf.packages.sort $list +end + +function __omf.packages.list.database -a type + set -l list + + test "$type" = "--theme"; or for package in (basename $OMF_PATH/db/pkg/*) + set list $list $package + end + + test "$type" = "--plugin"; or for package in (basename $OMF_PATH/db/themes/*) + set list $list $package + end + + __omf.packages.sort $list +end + +function __omf.packages.list.installed -a type + set -l list + + test "$type" = "--theme"; or for package in (basename {$OMF_CONFIG,$OMF_PATH}/pkg/*) + set list $list $package + end + + test "$type" = "--plugin"; or for package in (basename {$OMF_CONFIG,$OMF_PATH}/themes/*) + set list $list $package + end + + __omf.packages.sort $list +end + +function omf.packages.list -a option type + switch "$option" + case "--available" + __omf.packages.list.available $type + case "--database" + __omf.packages.list.database $type + case "--installed" + __omf.packages.list.installed $type + case "*" + __omf.packages.list $type + end +end diff --git a/pkg/omf/completions/omf.fish b/pkg/omf/completions/omf.fish index cd3b5d9..56aede2 100644 --- a/pkg/omf/completions/omf.fish +++ b/pkg/omf/completions/omf.fish @@ -3,11 +3,11 @@ complete -c omf -f -d "Oh My Fish" -complete -c omf -f -n "__fish_seen_subcommand_from r rm remove" -a (printf "%s " (omf.list_local_packages) (omf.list_installed_themes)) -complete -c omf -f -n "__fish_seen_subcommand_from d desc describe" -a (printf "%s " (omf.list_db_packages)) -complete -c omf -f -n "__fish_seen_subcommand_from c cd" -a (printf "%s " (omf.list_db_packages)) -complete -c omf -f -n "__fish_seen_subcommand_from i install" -a (printf "%s " (omf.list_db_packages "skip installed packages")) -complete -c omf -f -n "__fish_seen_subcommand_from t theme" -a (printf "%s " (omf.list_themes)) +complete -c omf -f -n "__fish_seen_subcommand_from r rm remove" -a (printf "%s " (omf.packages.list --installed)) +complete -c omf -f -n "__fish_seen_subcommand_from d desc describe" -a (printf "%s " (omf.packages.list --database --plugin)) +complete -c omf -f -n "__fish_seen_subcommand_from c cd" -a (printf "%s " (omf.packages.list --installed)) +complete -c omf -f -n "__fish_seen_subcommand_from i install" -a (printf "%s " (omf.packages.list --available --plugin)) +complete -c omf -f -n "__fish_seen_subcommand_from t theme" -a (printf "%s " (omf.packages.list --database --theme)) complete -c omf -f -n "__fish_seen_subcommand_from help" -a "install theme remove update list describe cd new submit destroy doctor" complete -c omf -f -a list -n "__fish_use_subcommand" -d "List local packages" diff --git a/pkg/omf/omf.fish b/pkg/omf/omf.fish index 5c3bd98..3dc86de 100644 --- a/pkg/omf/omf.fish +++ b/pkg/omf/omf.fish @@ -83,7 +83,7 @@ function omf -d "Oh My Fish" end case "l" "ls" "list" - omf.list_local_packages | column + omf.packages.list --installed | column case "n" "new" if test (count $argv) -ne 3 @@ -118,10 +118,10 @@ function omf -d "Oh My Fish" set -l regex "[[:<:]]($theme)[[:>:]]" test "$ostype" != "Darwin"; and set regex "\b($theme)\b" - omf.list_themes | column | sed -E "s/$regex/"(omf::em)"\1"(omf::off)"/" + omf.packages.list --database --theme | column | sed -E "s/$regex/"(omf::em)"\1"(omf::off)"/" omf::off else if test (count $argv) -eq 2 - if not contains -- $argv[2] (omf.list_installed_themes) + if not contains -- $argv[2] (omf.packages.list --installed) omf.install --theme $argv[2]; or return 1 end omf.theme $argv[2] @@ -140,7 +140,7 @@ function omf -d "Oh My Fish" echo "Please open a new issue here → "(omf::em)"github.com/oh-my-fish/oh-my-fish/issues"(omf::off) end omf.theme (cat $OMF_CONFIG/theme) - omf.install_package (omf.list_installed_packages) + omf.install_package (omf.packages.list --installed --plugin) refresh case "*"