Commit 17de8c4b authored by Derek Willian Stavis's avatar Derek Willian Stavis

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

parent ce978438
...@@ -62,7 +62,9 @@ function omf.cli.help -a command ...@@ -62,7 +62,9 @@ function omf.cli.help -a command
List local packages. List local packages.
"(omf::dim)"Usage:"(omf::off)" "(omf::dim)"Usage:"(omf::off)"
omf list omf list [ --available | -a ]
omf list [ --installed | -i ]
omf list [ --database | -d ]
" "
case "n" "new" case "n" "new"
......
function omf.cli.list -a type function omf.cli.list
test -z "$type"; and set type '--installed' switch (count $argv)
case 0
if contains -- $type '--available' '-a' '--database' '-d' '--installed' '-i' echo (set_color -u)Plugins(set_color normal)
omf.packages.list $type | column omf.packages.list --installed --plugin | column
else echo
echo (omf::err)"Invalid arguments"(omf::off) echo (set_color -u)Themes(set_color normal)
echo 'Usage: omf list [ --available | -a ]' omf.packages.list --installed --theme | column
echo ' omf list [ --installed | -i ]' case '*'
echo ' omf list [ --database | -d ]' omf.packages.list $argv | column
return $OMF_INVALID_ARG
end end
end end
function __omf.packages.sort set -l builtin_package_path {$OMF_PATH,$OMF_CONFIG}/pkg*/{omf,fish-spec}
for package in (echo $argv | tr ' ' '\n' | sort); echo $package; end
end
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
end
test "$type" = "--plugin"; or for package in (basename -a {$OMF_CONFIG,$OMF_PATH/db}/themes/*) function __omf.packages.basename
set list $list $package set -l IFS /
for path in $argv
echo $path | read -la components
echo $components[-1]
end end
__omf.packages.sort $list
end end
function __omf.packages.list.available -a type 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/*
test "$type" = "--theme"; or for package in (basename -a $OMF_PATH/db/pkg/*) set -l installed_package_path {$OMF_CONFIG,$OMF_PATH}/pkg/*
contains $package (basename -a {$OMF_CONFIG,$OMF_PATH}/pkg/*); or set list $list $package set -l installed_theme_path {$OMF_CONFIG,$OMF_PATH}/themes/*
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 end
test "$type" = "--plugin"; or for package in (basename -a $OMF_PATH/db/themes/*) test "$type" = "--plugin"; or for theme in $database_themes
contains $package (basename -a {$OMF_CONFIG,$OMF_PATH}/themes/*); or set list $list $package contains $path $installed_themes; or echo $theme
end end
__omf.packages.sort $list
end end
function __omf.packages.list.database -a type function __omf.packages.list.database -a type
set -l list 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/*) test "$type" = "--theme"; or for path in $database_package_path
set list $list $package set list $list $path
end end
test "$type" = "--plugin"; or for package in (basename -a $OMF_PATH/db/themes/*) test "$type" = "--plugin"; or for path in $database_theme_path
set list $list $package set list $list $path
end end
__omf.packages.sort $list __omf.packages.basename $list
end end
function __omf.packages.list.installed -a type function __omf.packages.list.installed -a type
set -l list 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/*) test "$type" = "--theme"; or for path in $installed_package_path
contains $package (__omf.packages.builtin); or set list $list $package contains $path $builtin_package_path; or set list $list $path
end end
test "$type" = "--plugin"; or for package in (basename -a {$OMF_CONFIG,$OMF_PATH}/themes/* 2>/dev/null) test "$type" = "--plugin"; or for path in $installed_theme_path
set list $list $package set list $list $path
end end
__omf.packages.sort $list __omf.packages.basename $list
end 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" switch "$option"
case "-a" "--available" case "-a" "--available"
__omf.packages.list.available $type __omf.packages.list.available $type
...@@ -72,6 +88,6 @@ function omf.packages.list -a option type ...@@ -72,6 +88,6 @@ function omf.packages.list -a option type
case "-i" "--installed" case "-i" "--installed"
__omf.packages.list.installed $type __omf.packages.list.installed $type
case "*" case "*"
__omf.packages.list $type __omf.packages.list.installed $type
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment