list: refactor code, fix fish 2.3.0 globs (#325)

This commit is contained in:
Derek Willian Stavis 2016-05-31 18:16:02 -03:00
parent ce97843850
commit 17de8c4b6b
3 changed files with 67 additions and 51 deletions

View File

@ -62,7 +62,9 @@ function omf.cli.help -a command
List local packages.
"(omf::dim)"Usage:"(omf::off)"
omf list
omf list [ --available | -a ]
omf list [ --installed | -i ]
omf list [ --database | -d ]
"
case "n" "new"

View File

@ -1,14 +1,12 @@
function omf.cli.list -a type
test -z "$type"; and set type '--installed'
if contains -- $type '--available' '-a' '--database' '-d' '--installed' '-i'
omf.packages.list $type | column
else
echo (omf::err)"Invalid arguments"(omf::off)
echo 'Usage: omf list [ --available | -a ]'
echo ' omf list [ --installed | -i ]'
echo ' omf list [ --database | -d ]'
return $OMF_INVALID_ARG
function omf.cli.list
switch (count $argv)
case 0
echo (set_color -u)Plugins(set_color normal)
omf.packages.list --installed --plugin | column
echo
echo (set_color -u)Themes(set_color normal)
omf.packages.list --installed --theme | column
case '*'
omf.packages.list $argv | column
end
end

View File

@ -1,69 +1,85 @@
function __omf.packages.sort
for package in (echo $argv | tr ' ' '\n' | sort); echo $package; end
end
set -l builtin_package_path {$OMF_PATH,$OMF_CONFIG}/pkg*/{omf,fish-spec}
function __omf.packages.builtin
echo "omf"
echo "fish-spec"
end
function __omf.packages.list -a type
set -l list
test "$type" = "--theme"; or for package in (basename -a {$OMF_CONFIG,$OMF_PATH/db}/pkg/*)
contains $package (__omf.packages.builtin); or set list $list $package
function __omf.packages.basename
set -l IFS /
for path in $argv
echo $path | read -la components
echo $components[-1]
end
test "$type" = "--plugin"; or for package in (basename -a {$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
set -l database_package_path $OMF_PATH/db/pkg/*
set -l database_theme_path $OMF_PATH/db/themes/*
set -l installed_package_path {$OMF_CONFIG,$OMF_PATH}/pkg/*
set -l installed_theme_path {$OMF_CONFIG,$OMF_PATH}/themes/*
test "$type" = "--theme"; or for package in (basename -a $OMF_PATH/db/pkg/*)
contains $package (basename -a {$OMF_CONFIG,$OMF_PATH}/pkg/*); or set list $list $package
set -l database_packages (__omf.packages.basename $database_package_path)
set -l database_themes (__omf.packages.basename $database_theme_path)
set -l installed_packages (__omf.packages.basename $installed_package_path)
set -l installed_themes (__omf.packages.basename $installed_theme_path)
test "$type" = "--theme"; or for package in $database_packages
contains $package $installed_packages; or echo $package
end
test "$type" = "--plugin"; or for package in (basename -a $OMF_PATH/db/themes/*)
contains $package (basename -a {$OMF_CONFIG,$OMF_PATH}/themes/*); or set list $list $package
test "$type" = "--plugin"; or for theme in $database_themes
contains $path $installed_themes; or echo $theme
end
__omf.packages.sort $list
end
function __omf.packages.list.database -a type
set -l list
set -l database_package_path $OMF_PATH/db/pkg/*
set -l database_theme_path $OMF_PATH/db/themes/*
test "$type" = "--theme"; or for package in (basename -a $OMF_PATH/db/pkg/*)
set list $list $package
test "$type" = "--theme"; or for path in $database_package_path
set list $list $path
end
test "$type" = "--plugin"; or for package in (basename -a $OMF_PATH/db/themes/*)
set list $list $package
test "$type" = "--plugin"; or for path in $database_theme_path
set list $list $path
end
__omf.packages.sort $list
__omf.packages.basename $list
end
function __omf.packages.list.installed -a type
set -l list
set -l installed_package_path $OMF_PATH/pkg/*
set -l installed_theme_path $OMF_PATH/themes/*
test "$type" = "--theme"; or for package in (basename -a {$OMF_CONFIG,$OMF_PATH}/pkg/*)
contains $package (__omf.packages.builtin); or set list $list $package
test "$type" = "--theme"; or for path in $installed_package_path
contains $path $builtin_package_path; or set list $list $path
end
test "$type" = "--plugin"; or for package in (basename -a {$OMF_CONFIG,$OMF_PATH}/themes/* 2>/dev/null)
set list $list $package
test "$type" = "--plugin"; or for path in $installed_theme_path
set list $list $path
end
__omf.packages.sort $list
__omf.packages.basename $list
end
function omf.packages.list -a option type
function omf.packages.list
set -l type_index (begin
contains -i -- --theme $argv
contains -i -- -t $argv
contains -i -- --plugin $argv
contains -i -- -p $argv
end)
set -l option_index (begin
contains -i -- --available $argv
contains -i -- -a $argv
contains -i -- --installed $argv
contains -i -- -i $argv
contains -i -- --database $argv
contains -i -- -d $argv
end)
set -l option $argv[$option_index]
set -l type $argv[$type_index]
switch "$option"
case "-a" "--available"
__omf.packages.list.available $type
@ -72,6 +88,6 @@ function omf.packages.list -a option type
case "-i" "--installed"
__omf.packages.list.installed $type
case "*"
__omf.packages.list $type
__omf.packages.list.installed $type
end
end