Skip to content
Snippets Groups Projects
Commit 49dda5c2 authored by Derek Stavis's avatar Derek Stavis
Browse files

Reorganize `omf` plugin structure

This updates omf plugin to new architecture, moving
functions to `functions` directory. It also revamps the
separation of concerns between CLI and underlying
implementations, organizing them into directories,
whose are autoloaded in plugin startup.
parent 68f450b4
Branches
No related merge requests found
Showing
with 141 additions and 86 deletions
function omf.install_package
for search in $argv
omf.install $search
end
end
# Backwards-compatible wrapper function
# TODO: Remove it after 2015, December 13
function omf.list_installed_packages
omf.packages.list --installed --plugin
end
function omf.new_from_template -a path github user name
for file in $path/*
if test -d $file
mkdir (basename $file)
pushd (basename $file)
omf.new_from_template $file $github $user $name
else
set -l target (begin
if test (basename $file) = "{{NAME}}.fish"
echo "$name.fish"
else
echo (basename "$file")
end
end)
sed "s/{{USER_NAME}}/$user/;s/{{GITHUB_USER}}/$github/;s/{{NAME}}/$name/" \
$file > $target
echo (omf::em)" create "(omf::off)" "(begin
if test (basename $PWD) = $name
echo ""
else
echo (basename "$PWD")"/"
end
end)$target
end
end
popd >/dev/null ^&2
end
function omf.remove_package
set -l pkg $argv
set -l remove_status 1
if not omf.util_valid_package $pkg
if test $pkg = "omf" -o $pkg = "default"
echo (omf::err)"You can't remove `$pkg`"(omf::off) 1^&2
else
echo (omf::err)"$pkg is not a valid package/theme name"(omf::off) 1^&2
end
return $OMF_INVALID_ARG
end
for path in {$OMF_PATH,$OMF_CONFIG}/{pkg}/$pkg
not test -d $path; and continue
source $path/uninstall.fish ^/dev/null; and emit uninstall_$pkg
omf.bundle.remove "package" $pkg
rm -rf $path
set remove_status $status
end
for path in {$OMF_PATH,$OMF_CONFIG}/{themes}/$pkg
not test -d $path; and continue
if test $pkg = (cat $OMF_CONFIG/theme)
echo default > $OMF_CONFIG/theme
end
omf.bundle.remove "theme" $pkg
rm -rf $path
set remove_status $status
end
if test $remove_status -eq 0
echo (omf::em)"$pkg successfully removed."(omf::off)
else
echo (omf::err)"$pkg could not be found"(omf::off) 1^&2
end
return $remove_status
end
...@@ -16,10 +16,10 @@ function omf.bundle.install ...@@ -16,10 +16,10 @@ function omf.bundle.install
set name_or_url (echo $record | cut -s -d' ' -f2- | sed 's/ //g') set name_or_url (echo $record | cut -s -d' ' -f2- | sed 's/ //g')
test -n "$name_or_url"; or continue test -n "$name_or_url"; or continue
set name (omf.package_name $name_or_url) set name (omf.packages.name $name_or_url)
if not contains $name $packages if not contains $name $packages
omf.install $name_or_url; omf.packages.install $name_or_url;
and set installed and set installed
end end
end end
......
...@@ -11,7 +11,7 @@ function omf.bundle.remove ...@@ -11,7 +11,7 @@ function omf.bundle.remove
for record in $bundle_contents for record in $bundle_contents
set record_type (echo $record | cut -d' ' -f1) set record_type (echo $record | cut -d' ' -f1)
set record_name_or_url (echo $record | cut -d' ' -f2-) set record_name_or_url (echo $record | cut -d' ' -f2-)
set record_name (omf.package_name $record_name_or_url) set record_name (omf.packages.name $record_name_or_url)
if not test "$type" = "$record_type" -a "$name" = "$record_name" if not test "$type" = "$record_type" -a "$name" = "$record_name"
echo "$record_type $record_name_or_url" >> $bundle echo "$record_type $record_name_or_url" >> $bundle
......
function omf.cli.cd -a name
omf.packages.cd $name
end
function omf.cli.describe -a name
switch (count $argv)
case 1
omf.packages.describe $name
return 0
case '*'
echo (omf::err)"Invalid number of arguments"(omf::off)
return 1
end
end
function omf.cli.destroy
echo (omf::err)"This will destroy your Oh My Fish installation!"(omf::off)
read -l decision -p 'echo -n "Are you sure you want to continue? (y/N) "'
switch $decision
case 'y' 'Y'
omf.destroy
case '*'
echo (omf::err)"Aborted!"(omf::off)
end
end
function omf.cli.doctor
omf.doctor
end
function omf.help -a command function omf.cli.help -a command
switch $command switch "$command"
case "c" "cd" case "c" "cd"
echo \n"\ echo \n"\
Change directory to root or plugin/theme directory. Change directory to root or plugin/theme directory.
......
function omf.cli.install
set fail_count 0
switch (count $argv)
case 0
omf.bundle.install;
or set fail_count 1
case '*'
for package in $argv
omf.packages.install $package;
and require $package
test $status != 0;
and set fail_count (math $fail_count + 1)
end
end
return $fail_count
end
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
end
end
function omf.cli.new
if test (count $argv) -ne 2
echo (omf::err)"Package type or name missing"(omf::off) 1^&2
echo "Usage: omf new "(omf::em)"(pkg | theme)"(omf::off)" <name>" 1^&2
return $OMF_MISSING_ARG
end
omf.packages.new $argv
end
function omf.cli.remove -a name
switch (count $argv)
case 1
omf.packages.remove $name
set code $status
switch $code
case 0
echo (omf::em)"$name successfully removed."(omf::off)
case 1
echo (omf::err)"$name could not be removed."(omf::off) 1^&2
case 2
echo (omf::err)"$name could not be found."(omf::off) 1^&2
end
return $code
case '*'
echo (omf::err)"Invalid number of arguments"(omf::off) 1^&2
echo "Usage: omf remove "(omf::em)"<name>"(omf::off) 1^&2
return $OMF_INVALID_ARG
end
end
function omf.cli.submit
switch (count $argv)
case 2
omf.packages.submit $argv
case "*"
echo (omf::err)"Argument missing"(omf::off) 1^&2
echo "Usage: $_ "(omf::em)"submit"(omf::off)" "(omf::em)"pkg|themes"(omf::off)"/<name> <url>" 1^&2
return $OMF_MISSING_ARG
end
end
function omf.cli.theme -a name
switch (count $argv)
case 0
omf.cli.themes.list
case 1
omf.theme.set $name
case '*'
echo (omf::err)"Invalid number of arguments"(omf::off) 1^&2
echo "Usage: $_ "(omf::em)"$argv[1]"(omf::off)" [<theme name>]" 1^&2
return $OMF_INVALID_ARG
end
end
function omf.cli.themes.list
set -l theme (cat $OMF_CONFIG/theme)
set -l regex_current "(^|[[:space:]])($theme)([[:space:]]|\$)"
set -l highlight_current s/"$regex_current"/"\1"(omf::em)"\2"(omf::off)"\3"/g
echo (omf::under)"Installed:"(omf::off)
omf.packages.list --installed --theme | column | sed -E "$highlight_current"
echo
echo (omf::under)"Available:"(omf::off)
omf.packages.list --available --theme | column
end
function omf.cli.update
if omf.core.update
echo (omf::em)"Oh My Fish is up to date."(omf::off)
else
echo (omf::err)"Oh My Fish failed to update."(omf::off)
echo "Please open a new issue here → "(omf::em)"github.com/oh-my-fish/oh-my-fish/issues"(omf::off)
end
for package in (omf.packages.list --installed)
omf.packages.update $package
end
end
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