Commit 2d1deeb5 authored by Stephen M. Coakley's avatar Stephen M. Coakley Committed by GitHub

Replace package database with independently installed package repositories (#427)

Replace package database with independently installed package repositories

- Add support for fetching and installing from package repositories containing package URLs and metadata
- Support multiple package repository sources
- Add new repo command
- Remove submit command
- Enhance describe and search commands
- Fix and improve help text for new and adjusted commands
- Fix bundle install exit status
- Refer to plugins as "plugins" instead of the general term "packages"
- Code clarity improvements
- Put plugin/theme distinction into package metadata
parent e2c3343e
......@@ -50,7 +50,7 @@ Oh My Fish includes a small utility `omf` to fetch and install new packages and
#### `omf update` _`[omf]`_ _`[<package>...]`_
Update the framework and installed packages.
Update Oh My Fish, all package repositories, and all installed packages.
- When called without arguments, update core and all installed packages.
- You can choose to update only the core, by running `omf update omf`.
......@@ -64,6 +64,10 @@ Install one _or more_ packages.
- You can install packages directly by URL via `omf install URL`
- When called without arguments, install missing packages from [bundle](#dotfiles).
#### `omf repositories` _`[list|add|remove]`_
Manage user-installed package repositories. Package repositories are where packages come from used by commands like `omf install`. By default the [official repository](https://github.com/oh-my-fish/packages-main) is always installed and available.
#### `omf list`
List installed packages.
......@@ -94,13 +98,6 @@ Scaffold out a new package or theme.
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/<name>`_ _`[<url>]`_
Add a new package. To add a theme, use `omf submit` _`themes/<name>`_ _`<url>`_.
Please note that the _`[<url>]`_ portion of the command should be the url to your repo on github. For example, with the `example` plugin, the command run should be `omf submit pkg/example https://github.com/oh-my-fish/example`.
Make sure to [send us a PR][omf-pulls-link] to update the registry.
#### `omf channel`
Gets or changes the update channel.
......
......@@ -489,7 +489,7 @@ end
# Assert that all tools we need are available.
function assert_cmds
set -l cmds basename cp cut date dirname fold head mkdir mv rm sed sort tar tr
set -l cmds awk basename cp cut date dirname fold head mkdir mv rm sed sort tar tr
for cmd in $cmds
type -f -q $cmd
......
https://github.com/oh-my-fish/plugin-android-sdk
https://github.com/pkg-gretel/pkg-ansible
https://github.com/oh-my-fish/plugin-apt
https://github.com/oh-my-fish/plugin-archlinux
https://github.com/oh-my-fish/plugin-argu
https://github.com/thecotne/omf-plugin-artisan
https://github.com/oh-my-fish/plugin-await
https://github.com/oh-my-fish/plugin-aws
https://github.com/oh-my-fish/plugin-bak
https://github.com/oh-my-fish/plugin-balias
https://github.com/oh-my-fish/plugin-bang-bang
https://github.com/oh-my-fish/plugin-basename-compat
https://github.com/oh-my-fish/plugin-battery
https://github.com/devert/plugin-blt
https://github.com/oh-my-fish/plugin-brew
https://github.com/oh-my-fish/plugin-bundler
https://github.com/oh-my-fish/plugin-cd
\ No newline at end of file
https://github.com/oh-my-fish/plugin-composer
https://github.com/oh-my-fish/plugin-config
https://github.com/oh-my-fish/plugin-direnv
https://github.com/oh-my-fish/plugin-docker-machine
https://github.com/oh-my-fish/plugin-dpaste
https://github.com/oh-my-fish/plugin-emacs
https://github.com/oh-my-fish/plugin-errno
https://github.com/oh-my-fish/plugin-exenv
https://github.com/oh-my-fish/plugin-expand
https://github.com/jcouyang/plugin-export
https://github.com/pkg-gretel/pkg-extract
https://github.com/oh-my-fish/plugin-fasd
https://github.com/HenrikWL/plugin-fish_logo.git
https://github.com/derekstavis/plugin-fonts
https://github.com/oh-my-fish/plugin-foreign-env
https://github.com/gretel/pkg-fzf
https://github.com/oh-my-fish/plugin-gem
https://github.com/oh-my-fish/plugin-getopts
https://github.com/oh-my-fish/plugin-gi
\ No newline at end of file
https://github.com/oh-my-fish/plugin-git-flow
https://github.com/oh-my-fish/plugin-gityaw
https://github.com/oh-my-fish/plugin-grc
https://github.com/oh-my-fish/plugin-hash
https://github.com/lfiolhais/plugin-homebrew-command-not-found
https://github.com/pkg-gretel/pkg-hub
https://github.com/belltoy/plugin-iex
https://github.com/oh-my-fish/plugin-jump
https://github.com/pkg-gretel/pkg-keychain
https://github.com/vincentjames501/fish-kill-on-port
https://github.com/oh-my-fish/plugin-license
https://github.com/oh-my-fish/plugin-linuxbrew
https://github.com/oh-my-fish/plugin-local-config
https://github.com/oh-my-fish/marlin
https://github.com/belltoy/plugin-mix
https://github.com/oh-my-fish/plugin-mou
https://github.com/benc/pkg-mvn
https://github.com/oh-my-fish/plugin-node-binpath
https://github.com/oh-my-fish/plugin-nodenv
https://github.com/derekstavis/plugin-nvm
https://github.com/oh-my-fish/plugin-osx
https://github.com/oh-my-fish/plugin-pbcopy
\ No newline at end of file
https://github.com/oh-my-fish/plugin-peco
https://github.com/rzyns/pkg-php-version
https://github.com/oh-my-fish/plugin-phpbrew
https://github.com/oh-my-fish/plugin-pj.git
https://github.com/iamruinous/plugin-powerline
https://github.com/oh-my-fish/plugin-proxy
https://github.com/oh-my-fish/plugin-pyenv
https://github.com/oh-my-fish/plugin-python
https://github.com/oh-my-fish/plugin-rails
https://github.com/oh-my-fish/plugin-rbenv
https://github.com/oh-my-fish/plugin-rustup.git
https://github.com/oh-my-fish/plugin-rvm
https://github.com/oh-my-fish/plugin-spark
https://github.com/oh-my-fish/plugin-ssh-config.d
https://github.com/wk/plugin-ssh-term-helper
https://github.com/oh-my-fish/plugin-sublime
https://github.com/oh-my-fish/plugin-sudope.git
https://github.com/oh-my-fish/plugin-tab
https://github.com/oh-my-fish/plugin-technicolor
https://github.com/sagebind/plugin-termux
https://github.com/oh-my-fish/plugin-thefuck
https://github.com/oh-my-fish/plugin-tiny
https://github.com/oh-my-fish/plugin-title
https://github.com/sagebind/tmux-zen
https://github.com/oh-my-fish/plugin-vcs
https://github.com/oh-my-fish/plugin-vi-mode
https://github.com/oh-my-fish/plugin-virtualfish.git
https://github.com/oh-my-fish/plugin-vundle
https://github.com/fischerling/plugin-wd
https://github.com/oh-my-fish/plugin-weather
https://github.com/oh-my-fish/plugin-wifi-password
https://github.com/oh-my-fish/plugin-wttr
https://github.com/oh-my-fish/plugin-z
https://github.com/oh-my-fish/theme-agnoster
https://github.com/oh-my-fish/theme-batman
https://github.com/oh-my-fish/theme-beloglazov
https://github.com/oh-my-fish/theme-bira
https://github.com/oh-my-fish/theme-bobthefish
https://github.com/oh-my-fish/theme-budspencer
https://github.com/oh-my-fish/theme-cbjohnson
https://github.com/oh-my-fish/theme-chain
https://github.com/oh-my-fish/theme-clearance
https://github.com/oh-my-fish/theme-cmorrell.com
https://github.com/oh-my-fish/theme-coffeeandcode
https://github.com/oh-my-fish/theme-cor
https://github.com/oh-my-fish/theme-qing
https://github.com/oh-my-fish/theme-dangerous
https://github.com/oh-my-fish/theme-default
https://github.com/oh-my-fish/theme-eclm
https://github.com/oh-my-fish/theme-edan
https://github.com/oh-my-fish/theme-eden
https://github.com/wyqydsyq/emoji-powerline
https://github.com/oh-my-fish/theme-es
\ No newline at end of file
https://github.com/oh-my-fish/theme-fishbone
https://github.com/oh-my-fish/theme-fishface
https://github.com/oh-my-fish/theme-fishy-drupal
https://github.com/oh-my-fish/theme-fisk
https://github.com/fishery/flash
https://github.com/oh-my-fish/theme-fox
https://github.com/ribugent/theme-gentoo
https://github.com/oh-my-fish/theme-gianu
https://github.com/oh-my-fish/theme-gitstatus
https://github.com/oh-my-fish/theme-gnuykeaj
https://github.com/oh-my-fish/theme-godfather
https://github.com/fishery/hulk
https://github.com/oh-my-fish/theme-idan
https://github.com/oh-my-fish/theme-integral
https://github.com/oh-my-fish/theme-jacaetevha
https://github.com/hastinbe/theme-kawasaki
https://github.com/oh-my-fish/theme-krisleech
https://github.com/oh-my-fish/theme-l
https://github.com/hasanozgan/theme-lambda
https://github.com/er0/lolfish
https://github.com/oh-my-fish/theme-mars
https://github.com/oh-my-fish/theme-mokou
https://github.com/oh-my-fish/theme-mtahmed
https://github.com/oh-my-fish/theme-nai
https://github.com/nelsonjchen/omf-theme-nelsonjchen
https://github.com/oh-my-fish/theme-numist
https://github.com/oh-my-fish/theme-ocean
https://github.com/chgu82837/theme-PastFish
https://github.com/oh-my-fish/theme-perryh
https://github.com/changyuheng/theme-plain
https://github.com/rafaelrinaldi/theme-pure
https://github.com/oh-my-fish/theme-red-snapper
https://github.com/oh-my-fish/theme-robbyrussell
https://github.com/oh-my-fish/theme-scorphish
https://github.com/simnalamburt/shellder
https://github.com/lfiolhais/theme-simple-ass-prompt
https://github.com/oh-my-fish/theme-simplevi
https://github.com/yangwao/omf-theme-slavic-cat
https://github.com/umayr/theme-sushi
\ No newline at end of file
https://github.com/oh-my-fish/theme-syl20bnr
https://github.com/oh-my-fish/theme-taktoa
https://github.com/oh-my-fish/theme-technopagan
https://github.com/oh-my-fish/theme-toaster
https://github.com/daveyarwood/tomita
https://github.com/oh-my-fish/theme-trout
https://github.com/oh-my-fish/theme-uggedal
https://github.com/oh-my-fish/theme-will
https://github.com/oh-my-fish/theme-yimmy
https://github.com/oh-my-fish/theme-zish
......@@ -116,25 +116,11 @@ Inside this hook, you can access two package-related variables:
Packages can use this hook to clean up custom resources, etc.
>Note: for backwards-compatibility, uninstall hooks will also be run if they are located at `uninstall.fish` in the package root.
> Note: for backwards-compatibility, uninstall hooks will also be run if they are located at `uninstall.fish` in the package root.
# Make it public
Oh My Fish keeps a registry of public packages under `$OMF_PATH/db/`.
To add your package to the registry you need to:
```fish
# For packages:
omf submit pkg/hello_world https://github.com/oh-my-fish/plugin-hello_world.git
# For themes
omf submit theme/my_theme https://github.com/oh-my-fish/theme-my_theme.git
```
This will add a new entry to your local copy of the registry. Now you just need to [send us a PR][omf-pulls-link] to update the global registry.
>When sending pull requests with package URL under Oh My Fish organization (https://github.com/oh-my-fish) we will allocate a repository inside the organization so you can push your work and join the community! :tada:
The official registry of public packages is managed in the [oh-my-fish/packages-main](https://github.com/oh-my-fish/packages-main) repository. See the README of that repository for instructions on how to add your package to the official package database.
[fish-bind]: http://fishshell.com/docs/current/commands.html#bind
......
......@@ -3,25 +3,31 @@
complete -c omf -f -d "Oh My Fish"
set -l installed_themes (omf.packages.list --installed --theme)
set -l installed_plugins (omf.packages.list --installed --plugin)
function __omf_assert_args_count -a count
set -l cmd (commandline -poc)
set -e cmd[1]
test (count $cmd) -eq $count
end
set -l installed_themes (omf.packages.list --theme)
set -l installed_plugins (omf.packages.list --plugin)
set -l installed $installed_themes $installed_plugins
for subcommand in "r rm remove" "c cd"
complete -c omf -f -n "__fish_seen_subcommand_from $subcommand" -a "$installed_themes" -d theme
complete -c omf -f -n "__fish_seen_subcommand_from $subcommand" -a "$installed_plugins" -d plugin
for subcommand in "r rm remove" "c cd" "u update"
complete -c omf -f -n "__fish_seen_subcommand_from $subcommand; and __omf_assert_args_count 1" -a "$installed_themes" -d theme
complete -c omf -f -n "__fish_seen_subcommand_from $subcommand; and __omf_assert_args_count 1" -a "$installed_plugins" -d plugin
end
set -l available_themes (omf.packages.list --available --theme)
set -l available_plugins (omf.packages.list --available --plugin)
for subcommand in "i install"
set -l available_themes (omf.index.query --type=theme)
set -l available_plugins (omf.index.query --type=plugin)
for subcommand in "i install" "d describe"
complete -c omf -f -n "__fish_seen_subcommand_from $subcommand" -a "$available_themes" -d theme
complete -c omf -f -n "__fish_seen_subcommand_from $subcommand" -a "$available_plugins" -d plugin
end
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 d desc describe" -a (printf "%s " (omf.index.query --type=plugin))
complete -c omf -f -n "__fish_seen_subcommand_from t theme" -a "$installed_themes"
complete -c omf -f -n "__fish_seen_subcommand_from channel" -a "stable dev"
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 -n "__fish_seen_subcommand_from help" -a "install theme remove update list describe cd new destroy doctor repositories"
complete -c omf -f -a list -n "__fish_use_subcommand" -d "List local packages"
complete -c omf -f -a describe -n "__fish_use_subcommand" -d "Get information about what packages do"
......@@ -29,10 +35,13 @@ complete -c omf -f -a install -n "__fish_use_subcommand" -d "Install one or mor
complete -c omf -f -a theme -n "__fish_use_subcommand" -d "List / Use themes"
complete -c omf -f -a remove -n "__fish_use_subcommand" -d "Remove a theme or package"
complete -c omf -f -a update -n "__fish_use_subcommand" -d "Update Oh My Fish"
complete -c omf -f -a repositories -n "__fish_use_subcommand" -d "Manage package repositories"
complete -c omf -f -n "__fish_seen_subcommand_from repo repositories; and __omf_assert_args_count 1" -a list -d "List installed repositories"
complete -c omf -f -n "__fish_seen_subcommand_from repo repositories; and __omf_assert_args_count 1" -a add -d "Add a package repository"
complete -c omf -f -n "__fish_seen_subcommand_from repo repositories; and __omf_assert_args_count 1" -a remove -d "Remove a package repository"
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"
complete -c omf -f -a doctor -n "__fish_use_subcommand" -d "Troubleshoot Oh My Fish"
......
......@@ -4,7 +4,7 @@ function omf.bundle.install
or set bundle $OMF_CONFIG/bundle
if test -f $bundle
set packages (omf.packages.list --installed)
set packages (omf.packages.list)
set bundle_contents (cat $bundle | sort -u)
for record in $bundle_contents
......@@ -20,12 +20,12 @@ function omf.bundle.install
if not contains $name $packages
omf.packages.install $name_or_url;
and set installed
or set error
end
end
sort -u $bundle -o $bundle
end
set -q installed
not set -q error
end
function omf.cli.describe -a name
omf.packages.describe $name
return 0
function omf.cli.describe -a package -d 'Show information about a package'
if set -l props (omf.index.stat $package description repository maintainer)
echo "Package: $package"
echo "Description: $props[1]"
echo "Repository: $props[2]"
echo "Maintainer: $props[3]"
return 0
end
echo "Unable to locate package '$package'." >&2
return 1
end
......@@ -38,11 +38,9 @@ determines what version "(omf::em)"omf update"(omf::off)" will upgrade to.
Get information about what packages do.
"(omf::dim)"Usage:"(omf::off)"
omf describe Get information from all available packages
omf describe "(omf::em)"<name>"(omf::off)" Get information from package by name
omf describe "(omf::em)"<name>"(omf::off)" Show information about a package
"(omf::dim)"Examples:"(omf::off)"
omf describe
omf describe brew
"
......@@ -98,6 +96,21 @@ Create a new package from a template.
omf new theme mytheme
"
case "repo" "repositories"
echo "\
Manage package repositories.
"(omf::dim)"Usage:"(omf::off)"
omf repositories [list|ls] List installed repositories
omf repositories add "(omf::em)"<url>"(omf::off)" ["(omf::em)"<branch>"(omf::off)"] Add a package repository
omf repositories rm|remove "(omf::em)"<url>"(omf::off)" ["(omf::em)"<branch>"(omf::off)"] Remove a package repository
"(omf::dim)"Examples:"(omf::off)"
omf repositories
omf repositories add https://github.com/vendor/fish-packages
omf repositories rm https://github.com/vendor/fish-packages master
"
case "r" "rm" "remove" "uninstall"
echo "\
Remove a theme or package.
......@@ -112,29 +125,17 @@ Remove a theme or package.
case "search"
echo "\
Search for a package or theme.
Search for a plugin or theme.
"(omf::dim)"Usage:"(omf::off)"
omf search ("(omf::dim)"-pkg/--package"(omf::off)" | "(omf::dim)"-t/--theme"(omf::off)") "(omf::em)"<name>"(omf::off)" Search for a package or theme
omf search ("(omf::dim)"-p/--plugin"(omf::off)" | "(omf::dim)"-t/--theme"(omf::off)") "(omf::em)"<name>"(omf::off)" Search for a plugin or theme
"(omf::dim)"Examples:"(omf::off)"
omf search -pkg nvm
omf search -p nvm
omf search -t bobthefish
omf search vi
"
case "s" "submit"
echo "\
Submit a package to the registry.
"(omf::dim)"Usage:"(omf::off)"
omf submit ("(omf::dim)"pkg"(omf::off)" | "(omf::dim)"theme"(omf::off)") "(omf::em)"<url>"(omf::off)" Submit a package or theme to the registry
"(omf::dim)"Examples:"(omf::off)"
omf submit pkg https://github.com/oh-my-fish/plugin-mypkg
omf submit theme https://github.com/oh-my-fish/plugin-mythemes
"
case "t" "theme"
echo "\
Install and list themes.
......@@ -169,23 +170,23 @@ Update Oh My Fish.
omf "(omf::em)"help"(omf::off)" [<command>]
"(omf::dim)"Commands:"(omf::off)"
"(omf::em)"l"(omf::off)"ist List local packages.
"(omf::em)"d"(omf::off)"escribe Get information about what packages do.
"(omf::em)"i"(omf::off)"nstall Install one or more packages.
"(omf::em)"t"(omf::off)"heme List / Use themes.
"(omf::em)"r"(omf::off)"emove Remove a theme or package.
"(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.
"(omf::em)"help"(omf::off)" Shows help about a specific action.
"(omf::em)"c"(omf::off)"d Change directory to plugin/theme directory.
"(omf::em)"d"(omf::off)"escribe Get information about what packages do.
"(omf::em)"destroy"(omf::off)" Uninstall Oh My Fish.
"(omf::em)"doctor"(omf::off)" Troubleshoot Oh My Fish.
"(omf::em)"help"(omf::off)" Shows help about a specific action.
"(omf::em)"i"(omf::off)"nstall Install one or more packages.
"(omf::em)"l"(omf::off)"ist List local packages.
"(omf::em)"n"(omf::off)"ew Create a new package from a template.
"(omf::em)"r"(omf::off)"emove Remove a theme or package.
"(omf::em)"repo"(omf::off)"sitories Manage package repositories.
"(omf::em)"s"(omf::off)"earch Search for a package or theme.
"(omf::em)"t"(omf::off)"heme List / Use themes.
"(omf::em)"u"(omf::off)"pdate Update Oh My Fish.
"(omf::dim)"Options:"(omf::off)"
"(omf::em)"--h"(omf::off)"elp Display this help.
"(omf::em)"--v"(omf::off)"ersion Display version.
"(omf::em)"--h"(omf::off)"elp Display this help.
"(omf::em)"--v"(omf::off)"ersion Display version.
For more information visit → "(omf::em)"git.io/oh-my-fish"(omf::off)\n
end
......
function omf.cli.install
set fail_count 0
omf.index.update
or return 1
switch (count $argv)
case 0
omf.bundle.install;
......@@ -11,8 +14,8 @@ function omf.cli.install
and require $package
# If package is a theme, set it to active.
if contains "$package" (omf.packages.list --installed --theme)
omf.theme.set "$package"
if contains -- $package (omf.packages.list --theme)
omf.theme.set $package
end
test $status != 0;
......
......@@ -2,10 +2,10 @@ function omf.cli.list
switch (count $argv)
case 0
echo (set_color -u)Plugins(set_color normal)
omf.packages.list --installed --plugin | column
omf.packages.list --plugin | column
echo
echo (set_color -u)Themes(set_color normal)
omf.packages.list --installed --theme | column
omf.packages.list --theme | column
case '*'
omf.packages.list $argv | column
end
......
function omf.cli.search -d "CLI parser for the search command"
function omf.cli.search -d 'Searches all available packages'
switch (count $argv);
case 1;
omf.search.pkg $argv[1]
omf.index.update --if-missing
echo (omf::under)"Plugins"(omf::off)
__omf.cli.search.output --type=plugin --text=$argv[1]
echo
omf.search.theme $argv[1]
echo (omf::under)"Themes"(omf::off)
__omf.cli.search.output --type=theme --text=$argv[1]
case 2;
omf.index.update --if-missing
switch "$argv[1]"
case "-pkg" "--package";
omf.search.pkg $argv[2]
case "-p" "--plugin";
__omf.cli.search.output --type=plugin --text=$argv[2]
case "-t" "--theme";
omf.search.theme $argv[2]
__omf.cli.search.output --type=theme --text=$argv[2]
case '*';
__omf.cli.search.usage
omf.cli.help search
return 1
end
case '*';
__omf.cli.search.usage
omf.cli.help search
return 1
end
end
function __omf.cli.search.usage -d "Print usage"
echo (omf::err)"Usage: omf search ([-t | --theme]) ([-pkg | --package]) item"(omf::off)
return 0
end
function __omf.cli.search.output
for package in (omf.index.query $argv)
set -l desc (omf.index.stat $package description)
echo "$package - $desc"
end
end
function omf.cli.submit
switch (count $argv)
case 2
omf.packages.submit $argv
case "*"
echo (omf::err)"Argument missing"(omf::off) >&2
echo "Usage: $_ "(omf::em)"submit"(omf::off)" "(omf::em)"pkg|themes"(omf::off)"/<name> <url>" >&2
return $OMF_MISSING_ARG
end
end
......@@ -4,8 +4,8 @@ function omf.cli.themes.list
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"
omf.packages.list --theme | column | sed -E "$highlight_current"
echo
echo (omf::under)"Available:"(omf::off)
omf.packages.list --available --theme | column
omf.index.query --type=theme | column
end
......@@ -8,7 +8,7 @@ function omf.cli.update
and set -e packages[$index]
or set -e update_core
else
set packages (omf.packages.list --installed)
set packages (omf.packages.list)
end
if set -q update_core
......@@ -27,6 +27,9 @@ function omf.cli.update
end
end
omf.index.update
or return 1
for package in $packages
omf.packages.update $package
end
......
function omf.index.path -d 'Get the path to the local package index'
set -q XDG_CACHE_HOME
and echo "$XDG_CACHE_HOME/omf"
or echo "$HOME/.cache/omf"
end
function omf.index.query -d 'Query packages in the index'
set -l q_type any
set -l q_name ''
set -l q_text ''
# Parse search terms.
for arg in $argv
switch "$arg"
case '--type=any'
set q_type any
case '--type=plugin'
set q_type plugin
case '--type=theme'
set q_type theme
case '--name=?*'
set -l IFS '='
echo "$arg" | read dummy q_name
case '--text=?*'
set -l IFS '='
echo "$arg" | read dummy q_text
case '*'
echo "Invalid search term: '$arg'" >&2
return 1
end
end
# Put all packages into a list.
set -l packages (omf.index.path)/*/packages/*
# If there are no packages, there is nothing to search.
if not set -q packages[1]
return 1
end
# Perform a text search if any filters were given.
if set -q argv[1]
set results (command awk -v "q_type=$q_type" -v "q_name=$q_name" -v "q_text=$q_text" '
function flush() {
if (package && type_matches && name_matches && text_matches) {
print package;
}
}
BEGIN {
FS = "[ \t]*=[ \t]*";
q_name = tolower(q_name);
q_text = tolower(q_text);
}
FNR == 1 {
flush();
if (q_type == "any") {
type_matches = 1;
} else {
type_matches = 0;
}
name_matches = 0;
text_matches = 0;
package = parts[split(FILENAME, parts, "/")];
if (match(package, q_name)) {
name_matches = 1;
}
if (match(package, q_text)) {
text_matches = 1;
}
}
!type_matches && !/^#/ && $1 == "type" && $2 == q_type {
type_matches = 1;
}
!text_matches && !/^#/ {
if (match(tolower($2), q_text)) {
text_matches = 1;
}
}
END {
flush();
}
' $packages)
else
# No filters, just list all package names.
set results (for package in $packages
command basename $package
end)
end
if not set -q results[1]
return 1
end
# Sort results alphabetically.
for result in $results
echo $result
end | command sort -d
end
function omf.index.repositories -d 'Manage package repositories'
# List repositories by default.
if not set -q argv[1]
set argv[1] list
end
switch $argv[1]
case help --help -h
omf help repositories
return
case list ls
for file in {$OMF_PATH,$OMF_CONFIG}/repositories
if test -f $file
command cat $file
end
end
case add
if set -q argv[2]
set repo_url $argv[2]
else
echo "URL not specified" >&2
return 1
end
if set -q argv[3]
set repo_branch $argv[3]
else
set repo_branch master
end
set -l repo "$repo_url $repo_branch"
# Check if we already have the repository.
if test -f $OMF_CONFIG/repositories
if command grep -q $repo $OMF_CONFIG/repositories
echo "The repository is already added." >&2
return 1
end
end
if command grep -q $repo $OMF_PATH/repositories
echo "The repository is already added." >&2
return 1
end
# Before we add, do a quick ls-remote to see if the URL is a valid repo.
if not command git ls-remote --exit-code $repo_url refs/heads/$repo_branch > /dev/null ^&1
echo "The remote repository could not be found." >&2
return 1
end
echo "$repo" >> $OMF_CONFIG/repositories
case rm remove
if set -q argv[2]
set repo_url $argv[2]
else
echo "URL not specified" >&2
return 1
end
if set -q argv[3]
set repo_branch $argv[3]
else
set repo_branch master
end
set -l repo "$repo_url $repo_branch"
# Check to see if user has repositories and if the given URL is listed.
if test -f $OMF_CONFIG/repositories
if command grep -q $repo $OMF_CONFIG/repositories
command grep -v $repo $OMF_CONFIG/repositories > $OMF_CONFIG/repositories.swp
command mv $OMF_CONFIG/repositories.swp $OMF_CONFIG/repositories
return
end
end
# The given URL is not listed, check if it is a built-in repository they can't remove.
if command grep -q $repo $OMF_PATH/repositories
echo "The repository '$repo' is built-in and cannot be removed." >&2
else
echo "Could not find user repository '$repo'" >&2
end
return 1
case '*'
echo "Unknown command '$argv[1]'" >&2
return 1
end
end
function omf.index.stat -a name -d 'Get package properties'
if test -z "$name"
return 1
end
set -e argv[1]
set -l properties $argv
set -l package_file
# Find the package definition file.
set -l package_files (omf.index.path)/*/packages/$name
if set -q package_files[1]
set package_file $package_files[1]
else
return 1
end
# If no properties are specified, output all properties with names.
if not set -q properties[1]
command cat $package_file
return
end
# Find only the values of the properties requested.
command awk '
BEGIN {
FS = "[ \t]*=[ \t]*";
# Set default values for certain properties.
defaults["type"] = "plugin";
# Get the list of properties to display.
for (i = 2; i < ARGC; i++) {
properties[i - 1] = ARGV[i];
delete ARGV[i];
count++;
}
}
!/^#/ {
# Store the property value.
values[$1] = $2;
}
END {
# Print out each requested property.
for (i = 1; i <= count; i++) {
property = properties[i];
if (property in values) {
# If the property was set, print it out.
print values[property];
} else if (property in defaults) {
# If the property was not set and has a default value, print it out.
print defaults[property];
} else {
# Print a blank line if the property was not found.
print "";
}
}
}
' - $properties < $package_file
end
function omf.index.update -d 'Update package indexes'
# Only update if the index is missing.
if contains -- --if-missing $argv
set -l paths (omf.index.path)/*
if set -q paths[1]
return 0
end
end
# Find repository lists.
for list in {$OMF_PATH,$OMF_CONFIG}/repositories
test -f $list
and set lists $lists $list
end
# Read the configured repositories from the lists.
if set -q lists[1]
set repositories (command awk '
{
dir = $1 "_" $2;
gsub(/[ \/:@]/, "_", dir);
if (!visited[dir]++) {
print $1 "\n" $2 "\n" dir;
}
}
' $lists)
end
# Update repositories.
while set -q repositories[1]
set -l url $repositories[1]
set -l branch $repositories[2]
set -l path (omf.index.path)/$repositories[3]
set valid_paths $valid_paths $path
echo -n "Updating $url $branch... "
if begin
if not test -d $path
command git clone --quiet --depth 1 --branch $branch $url $path
else
command git -C $path pull --quiet
end
end
echo "Done!"
else
echo "Error"
return 1
end
set -e repositories[1..3]
end
# Remove repositories not in the lists.
for path in (omf.index.path)/*
if not contains -- $path $valid_paths
command rm -rf $path
end
end
return 0
end
......@@ -55,19 +55,19 @@ function omf -d "Oh My Fish"
case "r" "rm" "remove" "uninstall"
omf.cli.remove $arguments
case "s" "submit"
omf.cli.submit $arguments
case "t" "theme"
omf.cli.theme $arguments
case "u" "update"
omf.cli.update $arguments
case "repo" "repositories"
omf.index.repositories $arguments
case "channel"
omf.cli.channel $arguments
case "search"
case "s" "search"
omf.cli.search $arguments
case "version"
......
function omf.packages.describe -a name
if test (count $argv) -eq 0
for package in (omf.packages.list --database)
echo $package - (omf.packages.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)
curl -s https://api.github.com/repos/$repo ^/dev/null | grep \"description\" | head -1 | cut -d':' -f2- | sed -e 's/["|,]//g;s/^[ \t]//g'
else
echo (omf::err)"$name is not a valid pkg."(omf::off) >&2
return $OMF_INVALID_ARG
end
end
end
......@@ -11,44 +11,59 @@ function __omf.packages.install.error.already
end
function omf.packages.install -a name_or_url
if test \( -e $OMF_PATH/db/themes/$name_or_url \) -o (echo $name_or_url | grep theme-)
set install_type "theme"
set parent_path "themes"
else
set install_type "package"
set parent_path "pkg"
end
if test -e $OMF_PATH/db/$parent_path/$name_or_url
if set -l props (omf.index.stat $name_or_url type repository)
set package_type $props[1]
set name $name_or_url
set url (cat $OMF_PATH/db/$parent_path/$name)
set url $props[2]
else
set name (omf.packages.name $name_or_url)
set url $name_or_url
end
if test -e $OMF_PATH/$parent_path/$name
__omf.packages.install.error.already "$install_type $name_or_url"
if contains -- $name (omf.packages.list)
__omf.packages.install.error.already "$name_or_url"
return $OMF_INVALID_ARG
end
echo (omf::dim)"Installing $install_type $name"(omf::off)
echo (omf::dim)"Installing package $name"(omf::off)
if omf.repo.clone $url $OMF_PATH/$parent_path/$name
omf.bundle.install $OMF_PATH/$parent_path/$name/bundle
omf.bundle.add $install_type $name_or_url
set -l install_dir $OMF_PATH/pkg/$name
# Run the install hook.
if not omf.packages.run_hook $OMF_PATH/$parent_path/$name install
__omf.packages.install.error "$install_type $name"
return $OMF_UNKNOWN_ERR
end
# Clone the package repository.
if not omf.repo.clone $url $install_dir
__omf.packages.install.error "$name"
return $OMF_UNKNOWN_ERR
end
# If we don't know the package type yet, check if the package is a theme.
if not set -q package_type
echo $url | grep -q theme-
and set package_type theme
or set package_type plugin
end
__omf.packages.install.success "$install_type $name"
# If the package is a theme, move it to the themes directory.
if test $package_type = theme
test -d $OMF_PATH/themes
or command mkdir -p $OMF_PATH/themes
command mv $install_dir $OMF_PATH/themes/$name
set install_dir $OMF_PATH/themes/$name
omf.bundle.add theme $name_or_url
else
__omf.packages.install.error "$install_type $name"
omf.bundle.add package $name_or_url
end
omf.bundle.install $install_dir/bundle
# Run the install hook.
if not omf.packages.run_hook $install_dir install
__omf.packages.install.error "$name"
return $OMF_UNKNOWN_ERR
end
__omf.packages.install.success "$name"
return 0
end
set -l builtin_package_path {$OMF_PATH,$OMF_CONFIG}/pkg*/{omf,fish-spec}
set -l builtin_packages {$OMF_PATH,$OMF_CONFIG}/pkg*/{omf,fish-spec}
function __omf.packages.basename
set -l IFS /
for path in $argv
echo $path | read -la components
echo $components[-1]
end
end
function __omf.packages.list.available -a type
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/*
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 theme in $database_themes
contains $path $installed_themes; or echo $theme
end
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/*
function omf.packages.list -d 'List installed packages'
set -l show_plugins
set -l show_themes
test "$type" = "--theme"; or for path in $database_package_path
set list $list $path
if begin; contains -- --plugin $argv; or contains -- -p $argv; end
set -e show_themes
end
test "$type" = "--plugin"; or for path in $database_theme_path
set list $list $path
if begin; contains -- --theme $argv; or contains -- -t $argv; end
set show_themes
set -e show_plugins
end
__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/*
set -l plugins_paths $OMF_PATH/pkg/*
set -l themes_paths $OMF_PATH/themes/*
test "$type" = "--theme"; or for path in $installed_package_path
contains $path $builtin_package_path; or set list $list $path
if set -q show_plugins
for path in $plugins_paths
contains $path $builtin_packages; or command basename $path
end
end
test "$type" = "--plugin"; or for path in $installed_theme_path
set list $list $path
end
__omf.packages.basename $list
end
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
case "-d" "--database"
__omf.packages.list.database $type
case "-i" "--installed"
__omf.packages.list.installed $type
case "*"
__omf.packages.list.installed $type
if set -q show_themes
for path in $themes_paths
command basename $path
end
end
end
function omf.packages.name -a name_or_url
basename $name_or_url | sed -E 's/^(omf-)?((plugin|pkg|theme)-)?//;s/.git$//'
command basename $name_or_url | sed -E 's/^(omf-)?((plugin|pkg|theme)-)?//;s/.git$//'
end
# SYNOPSIS
# Submit a package to the registry
#
# OPTIONS
# name Name of the package.
# [url] URL to the package repository.
function omf.packages.submit -a name url -d "Submit a package to the registry"
switch (dirname $name)
case pkg
case themes
case "*"
echo (omf::err)"Missing directory name: pkg/ or themes/"(omf::off) >&2
return $OMF_INVALID_ARG
end
set -l pkg (basename $name)
if not omf.packages.valid_name $pkg
echo (omf::err)"$pkg is not a valid package/theme name"(omf::off) >&2
return $OMF_INVALID_ARG
end
if test -z "$url"
echo (omf::em)"URL not specified, looking for a remote origin..."(omf::off) >&2
set url (git config --get remote.origin.url)
if test -z "$url"
echo (omf::em)"$pkg remote URL not found"(omf::off) >&2
echo "Try: git remote add <URL> or see Docs#Submitting" >&2
return $OMF_INVALID_ARG
end
else
if test -e "$OMF_PATH/db/$name"
echo (omf::err)"Error: $pkg already exists in the registry!"(omf::off) >&2
return $OMF_INVALID_ARG
else
echo "$url" > $OMF_PATH/db/$name
echo (omf::em)"$pkg added to the local "(dirname $name)" registry."(omf::off)
echo "Want to contribute? Send us a PR → github.com/oh-my-fish/oh-my-fish"
return 0
end
end
end
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
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
function omf.theme.set -a target_theme
if not contains "$target_theme" (omf.packages.list --installed --theme)
if not contains "$target_theme" (omf.packages.list --theme)
echo (omf::err)"Theme not installed!"(omf::off)
echo Install it using (omf::em)omf install $target_theme(omf::off)
return $OMF_INVALID_ARG
......
......@@ -23,4 +23,4 @@ function omf::off
set_color normal ^ /dev/null
end
autoload $path/functions/{compat,core,packages,themes,bundle,util,repo,cli,search}
autoload $path/functions/{compat,core,index,packages,themes,bundle,util,repo,cli,search}
https://github.com/oh-my-fish/packages-main master
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