Skip to content

ishbguy/bag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Version License

bag is a bash package and plugin manager which inspired by vim-plug.

Table of Contents

🎨 Features

  • Basic packges and plugins management: install, update or uninstall.
  • Customizable to support different downloader: local repos, git repos or cloud drive repos.

📏 Prerequisite

  • bash 4.2 or later
  • git

🚀 Installation

$ git clone https://github.com/ishbguy/bag /path/to/bag

or

$ curl -fLo /path/to/bag.sh --create-dirs \
         https://raw.githubusercontent.com/ishbguy/bag/master/bag.sh

📓 Usage

The only action you need to do is to add below instruction in your bash config file: ~/.bashrc or ~/.bash_profile:

[[ -f /path/to/bag.sh ]] && source /path/to/bag.sh

After login bash, you can use bag command to manage packges and plugins. bag help will print usage.

bag v1.1.0
bag <subcmd> [somthing]

subcmds:
    agent                      agent for other package or repo operation cmd
    base       [path]          change or list bags download directory
    edit                       edit bag list
    help                       show help message, like this output
    install    [dl:url]        install a bag
    link       <path> <dl:url> add an existed package or repo by symbolic link
    list                       list installed bags
    load                       load all plugins and update PATH
    plug       [dl:url]        add a bag plugin or list all plugins
    uninstall  <dl:url>        uninstall a bag
    unlink     <dl:url>        unlink a bag, just like uninstall
    update     [pat]           update one or more bags
    version                    show version number

<dl:url> like 'gh:ishbguy/bag' means that it will install or update bag
from https://github.com/ishbguy/bag by github downloader.

If <dl:url> prefix with '@' like '@gh:ishbguy/bag', that means it will run
all the autoload/*.sh scripts under the bag directory.

If <dl:url> suffix with '#!.*' like 'gh:ishbguy/bag#!echo hello', that means
it will run the post-install hook 'echo hello'.

downloaders:
    file                       alias for local downloader
    gh                         alias for github downloader
    git                        downloader for git repo
    github                     downloader for github repo
    link                       downloader for local file or directory as symbolic link
    local                      downloader for local file or directory

bag list usage:

bag list [options]

options:
                               list without option will list all bags <dl-url>
    -a|--all|all               list all bags include autoload notation(@)
                               and post install cmd(#!)
    -@|@|--autoload|autoload   list autoload bags without '@' or '#!' string
    -p|--post|post             list bags configured post install cmd but
                               without '#!' cmd string
    -h|--help|help             print this help message

bag agent usage:

bag agent <action> [args..]

actions:
    add <cmd>       add an agent cmd, need to be quoted
    del <cmd-pat>   delete an agent cmd, need to be quoted
    run [cmd-pat]   run all or a pattern matched agent cmd
    edit            edit the agent file
    list            list all added agent cmd
    help            print the bag agent help message like this

This program is released under the terms of MIT License.
Get more infomation from <https://github.com/ishbguy/bag>.

Examples

  1. Use bag like other package management tools:
bag install gh:ishbguy/bag
bag update gh:ihsbguy/bag
bag uninstall gh:ishbguy/bag
  1. Use bag as a plugin management tool, you need to add instructions to ~/.bashrc or ~/.bash_profile:
bag base $HOME/.bags
bag plug gh:ishbguy/bag
bag install
bag load
  1. Define your own bag_downloader_XXX
# Define your own github downloader
bag_downloader_github() {
    __bag_require git || return 1

    # get two args
    local bag_opt="$1"
    local bag_url="https://github.com/${2#*:}"

    local bag=$(__bag_get_bag_name "$bag_url")

    # implement the install and update operations
    case $bag_opt in
        install) git clone "$bag_url" "$BAG_BASE_DIR/$bag" ;;
        update) (cd "$BAG_BASE_DIR/$bag" && git pull) ;;
        *) __bag_error "No such option: $bag_opt" ;;
    esac
}

# Write the help message, then install it
BAG_DOWNLOADER_HELP[github]="downloader for github repo"
BAG_DOWNLOADER[github]="bag_downloader_github"

📝 Configuration

The default BAG_BASE_DIR is $HOME/.bags, you can change it by bag base <dir-path> or export BAG_BASE_DIR=$DIR_PATH.

🌺 Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

👦 Authors

📜 License

Released under the terms of MIT License.

Releases

No releases published

Packages

No packages published