From: Erich Smith Date: Sun, 13 May 2012 12:37:31 +0000 (-0400) Subject: update plugin management X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=08e439c4f06ed3818d68961afd40e695a0d5fae9;p=common%2Fbash_it.git update plugin management --- diff --git a/lib/helpers.bash b/lib/helpers.bash index 53756e6..26690b6 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -29,10 +29,10 @@ function reload_plugins() { _load_bash_it_files "plugins" } -show_plugins () +bash-it-plugins () { - about summarizes available bash_it plugins - group lib + about 'summarizes available bash_it plugins' + group 'lib' typeset f typeset enabled @@ -47,57 +47,88 @@ show_plugins () printf "%-20s%-10s%s\n" "$(basename $f | cut -d'.' -f1)" " [$enabled]" "$(cat $f | metafor about-plugin)" done printf '\n%s\n' 'to enable a plugin, do:' - printf '%s\n' '$ enable_plugin ' + printf '%s\n' '$ enable-plugin -or- $ enable-plugin all' printf '\n%s\n' 'to disable a plugin, do:' - printf '%s\n' '$ disable_plugin ' + printf '%s\n' '$ disable-plugin -or- $ disable-plugin all' } -enable_plugin () +disable-plugin () { - about enables bash_it plugin - param 1: plugin name - example '$ enable_plugin rvm' - group lib + about 'disables bash_it plugin' + param '1: plugin name' + example '$ disable_plugin rvm' + group 'lib' - typeset plugin=$(ls $BASH_IT/plugins/available/$1.*bash 2>/dev/null | head -1) - if [ -z "$plugin" ]; then - printf '%s\n' 'sorry, that does not appear to be an available plugin.' + if [ -z "$1" ]; then + reference disable_plugin return fi - plugin=$(basename $plugin) - if [ -h $BASH_IT/plugins/enabled/$plugin ]; then - printf '%s\n' "$1 is already enabled." - return + if [ "$1" = "all" ]; then + typeset f plugin + for f in $BASH_IT/plugins/available/*.bash + do + plugin=$(basename $f) + if [ -h $BASH_IT/plugins/enabled/$plugin ]; then + rm $BASH_IT/plugins/enabled/$(basename $plugin) + fi + done + else + typeset plugin=$(ls $BASH_IT/plugins/enabled/$1.*bash 2>/dev/null | head -1) + if [ ! -h $plugin ]; then + printf '%s\n' 'sorry, that does not appear to be an enabled plugin.' + return + fi + rm $BASH_IT/plugins/enabled/$(basename $plugin) fi - ln -s $BASH_IT/plugins/available/$plugin $BASH_IT/plugins/enabled/$plugin - printf '%s\n' "$1 is enabled." - - reload_plugins - printf '%s\n' 'plugins reloaded.' + printf '%s\n' "$1 disabled." } -disable_plugin () +enable-plugin () { - about disables bash_it plugin - param 1: plugin name - example '$ disable_plugin rvm' - group lib + about 'enables bash_it plugin' + param '1: plugin name' + example '$ enable_plugin rvm' + group 'lib' - typeset plugin=$(ls $BASH_IT/plugins/enabled/$1.*bash 2>/dev/null | head -1) - if [ -z "$plugin" ]; then - printf '%s\n' 'sorry, that does not appear to be an enabled plugin.' + if [ -z "$1" ]; then + reference enable_plugin return fi - rm $BASH_IT/plugins/enabled/$(basename $plugin) - printf '%s\n' "$1 is disabled, and will be unavailable when you open a new terminal." + + if [ "$1" = "all" ]; then + typeset f plugin + for f in $BASH_IT/plugins/available/*.bash + do + plugin=$(basename $f) + if [ ! -h $BASH_IT/plugins/enabled/$plugin ]; then + ln -s $BASH_IT/plugins/available/$plugin $BASH_IT/plugins/enabled/$plugin + fi + done + else + typeset plugin=$(ls $BASH_IT/plugins/available/$1.*bash 2>/dev/null | head -1) + if [ -z "$plugin" ]; then + printf '%s\n' 'sorry, that does not appear to be an available plugin.' + return + fi + + plugin=$(basename $plugin) + if [ -h $BASH_IT/plugins/enabled/$plugin ]; then + printf '%s\n' "$1 is already enabled." + return + fi + + ln -s $BASH_IT/plugins/available/$plugin $BASH_IT/plugins/enabled/$plugin + fi + + printf '%s\n' "$1 enabled." } plugins-help () { - about list all plugins and functions defined by bash-it - group lib + about 'list all plugins and functions defined by bash-it' + group 'lib' printf '%s\n' "bash-it plugins help" printf '\n' @@ -112,8 +143,8 @@ plugins-help () all_groups () { - about displays all unique metadata groups - group lib + about 'displays all unique metadata groups' + group 'lib' typeset func typeset file=$(mktemp /tmp/composure.XXXX) diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index 8c5f24f..98d1fb4 100644 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -1,26 +1,26 @@ cite about-plugin -about-plugin miscellaneous tools +about-plugin 'miscellaneous tools' ips () { - about display all ip addresses for this host - group base + about 'display all ip addresses for this host' + group 'base' ifconfig | grep "inet " | awk '{ print $2 }' } down4me () { - about checks whether a website is down for you, or everybody - param 1: website url + about 'checks whether a website is down for you, or everybody' + param '1: website url' example '$ down4me http://www.google.com' - group base + group 'base' curl -s "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g' } myip () { - about displays your ip address, as seen by the Internet - group base + about 'displays your ip address, as seen by the Internet' + group 'base' res=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+') echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}" } @@ -28,10 +28,10 @@ myip () pickfrom () { - about picks random line from file - param 1: filename + about 'picks random line from file' + param '1: filename' example '$ pickfrom /usr/share/dict/words' - group base + group 'base' local file=$1 [ -z "$file" ] && reference $FUNCNAME && return length=$(cat $file | wc -l) @@ -41,12 +41,12 @@ pickfrom () pass () { - about generates random password from dictionary words - param optional integer length - param if unset, defaults to 4 + about 'generates random password from dictionary words' + param 'optional integer length' + param 'if unset, defaults to 4' example '$ pass' example '$ pass 6' - group base + group 'base' local i pass length=${1:-4} pass=$(echo $(for i in $(eval echo "{1..$length}"); do pickfrom /usr/share/dict/words; done)) echo "With spaces (easier to memorize): $pass" @@ -55,10 +55,10 @@ pass () pmdown () { - about preview markdown file in a browser - param 1: markdown file + about 'preview markdown file in a browser' + param '1: markdown file' example '$ pmdown README.md' - group base + group 'base' if command -v markdown &>/dev/null then markdown $1 | browser @@ -69,62 +69,62 @@ pmdown () mkcd () { - about make a directory and cd into it - param path to create + about 'make a directory and cd into it' + param 'path to create' example '$ mkcd foo' example '$ mkcd /tmp/img/photos/large' - group base + group 'base' mkdir -p "$*" cd "$*" } lsgrep () { - about search through directory contents with grep - group base + about 'search through directory contents with grep' + group 'base' ls | grep "$*" } pman () { - about view man documentation in Preview - param 1: man page to view + about 'view man documentation in Preview' + param '1: man page to view' example '$ pman bash' - group base + group 'base' man -t "${1}" | open -f -a $PREVIEW } pcurl () { - about download file and Preview it - param 1: download URL + about 'download file and Preview it' + param '1: download URL' example '$ pcurl http://www.irs.gov/pub/irs-pdf/fw4.pdf' - group base + group 'base' curl "${1}" | open -f -a $PREVIEW } pri () { - about display information about Ruby classes, modules, or methods, in Preview - param 1: Ruby method, module, or class + about 'display information about Ruby classes, modules, or methods, in Preview' + param '1: Ruby method, module, or class' example '$ pri Array' - group base + group 'base' ri -T "${1}" | open -f -a $PREVIEW } quiet () { about 'what *does* this do?' - group base + group 'base' $* &> /dev/null & } banish-cookies () { - about redirect .adobe and .macromedia files to /dev/null - group base + about 'redirect .adobe and .macromedia files to /dev/null' + group 'base' rm -r ~/.macromedia ~/.adobe ln -s /dev/null ~/.adobe ln -s /dev/null ~/.macromedia @@ -132,9 +132,9 @@ banish-cookies () usage () { - about disk usage per directory, in Mac OS X and Linux - param 1: directory name - group base + about 'disk usage per directory, in Mac OS X and Linux' + param '1: directory name' + group 'base' if [ $(uname) = "Darwin" ]; then if [ -n $1 ]; then du -hd $1 @@ -153,10 +153,10 @@ usage () t () { - about one thing todo - param if not set, display todo item - param 1: todo text - group base + about 'one thing todo' + param 'if not set, display todo item' + param '1: todo text' + group 'base' if [[ "$*" == "" ]] ; then cat ~/.t else @@ -166,19 +166,19 @@ t () command_exists () { - about checks for existence of a command - param 1: command to check + about 'checks for existence of a command' + param '1: command to check' example '$ command_exists ls && echo exists' - group base + group 'base' type "$1" &> /dev/null ; } # useful for administrators and configs buf () { - about back up file with timestamp - param filename - group base + about 'back up file with timestamp' + param 'filename' + group 'base' local filename=$1 local filetime=$(date +%Y%m%d_%H%M%S) cp ${filename} ${filename}_${filetime} diff --git a/plugins/available/battery.plugin.bash b/plugins/available/battery.plugin.bash index 1bfba2c..002d42f 100644 --- a/plugins/available/battery.plugin.bash +++ b/plugins/available/battery.plugin.bash @@ -1,9 +1,9 @@ cite about-plugin -about-plugin display info about your battery charge level +about-plugin 'display info about your battery charge level' battery_percentage(){ about 'displays battery charge as a percentage of full (100%)' - group battery + group 'battery' if command_exists acpi; then @@ -69,8 +69,8 @@ battery_percentage(){ } battery_charge(){ - about graphical display of your battery charge - group battery + about 'graphical display of your battery charge' + group 'battery' # Full char local F_C='▸' diff --git a/plugins/available/browser.plugin.bash b/plugins/available/browser.plugin.bash index 7ad2f4b..f7d820a 100644 --- a/plugins/available/browser.plugin.bash +++ b/plugins/available/browser.plugin.bash @@ -4,10 +4,10 @@ cite about-plugin about-plugin 'render commandline output in your browser' function browser() { - about pipe html to a browser + about 'pipe html to a browser' example '$ echo "

hi mom!

" | browser' example '$ ron -5 man/rip.5.ron | browser' - group browser + group 'browser' if [ -t 0 ]; then if [ -n "$1" ]; then @@ -27,7 +27,7 @@ function browser() { function wmate() { about 'pipe hot spicy interwebs into textmate and cleanup!' example '$ wmate google.com' - group browser + group 'browser' if [ -t 0 ]; then if [ -n "$1" ]; then @@ -64,7 +64,7 @@ EOT` function raw() { about 'write wget into a temp file and pump it into your browser' example '$ raw google.com' - group browser + group 'browser' if [ -t 0 ]; then if [ -n "$1" ]; then diff --git a/plugins/available/dirs.plugin.bash b/plugins/available/dirs.plugin.bash index d80b354..bb1fb02 100644 --- a/plugins/available/dirs.plugin.bash +++ b/plugins/available/dirs.plugin.bash @@ -6,7 +6,7 @@ # Jump to location by number. cite about-plugin -about-plugin directory stack navigation +about-plugin 'directory stack navigation' # Show directory stack alias d="dirs -v -l" @@ -32,8 +32,8 @@ alias pu="pushd" alias po="popd" function dirs-help() { - about directory navigation alias usage - group dirs + about 'directory navigation alias usage' + group 'dirs' echo "Directory Navigation Alias Usage" echo @@ -68,17 +68,17 @@ fi alias L='cat ~/.dirs' G () { # goes to distination dir otherwise , stay in the dir - about goes to destination dir - param 1: directory + about 'goes to destination dir' + param '1: directory' example '$ G ..' - group dirs + group 'dirs' cd ${1:-$(pwd)} ; } S () { # SAVE a BOOKMARK - about save a bookmark - group dirs + about 'save a bookmark' + group 'dirs' sed "/$@/d" ~/.dirs > ~/.dirs1; \mv ~/.dirs1 ~/.dirs; @@ -87,8 +87,8 @@ S () { # SAVE a BOOKMARK } R () { # remove a BOOKMARK - about remove a bookmark - group dirs + about 'remove a bookmark' + group 'dirs' sed "/$@/d" ~/.dirs > ~/.dirs1; \mv ~/.dirs1 ~/.dirs; diff --git a/plugins/available/extract.plugin.bash b/plugins/available/extract.plugin.bash index fbd969c..bb52045 100644 --- a/plugins/available/extract.plugin.bash +++ b/plugins/available/extract.plugin.bash @@ -1,5 +1,5 @@ cite about-plugin -about-plugin one command to extract them all... +about-plugin 'one command to extract them all...' extract () { if [ $# -ne 1 ] then diff --git a/plugins/available/fasd.plugin.bash b/plugins/available/fasd.plugin.bash index 220460c..ee810e2 100755 --- a/plugins/available/fasd.plugin.bash +++ b/plugins/available/fasd.plugin.bash @@ -585,7 +585,7 @@ fasd --init env case $- in *i*) cite about-plugin - about-plugin navigate 'frecently' used files and directories + about-plugin 'navigate "frecently" used files and directories' eval "$(fasd --init auto)" ;; *) # assume being executed as an executable diff --git a/plugins/available/git.plugin.bash b/plugins/available/git.plugin.bash index 15876de..0b77111 100644 --- a/plugins/available/git.plugin.bash +++ b/plugins/available/git.plugin.bash @@ -1,17 +1,17 @@ cite about-plugin -about-plugin git helper functions +about-plugin 'git helper functions' function git_remote { about 'adds remote $GIT_HOSTING:$1 to current repo' - group git + group 'git' echo "Running: git remote add origin ${GIT_HOSTING}:$1.git" git remote add origin $GIT_HOSTING:$1.git } function git_first_push { - about push into origin refs/heads/master - group git + about 'push into origin refs/heads/master' + group 'git' echo "Running: git push origin master:refs/heads/master" git push origin master:refs/heads/master @@ -19,23 +19,23 @@ function git_first_push { function git_remove_missing_files() { about "git rm's missing files" - group git + group 'git' git ls-files -d -z | xargs -0 git update-index --remove } # Adds files to git's exclude file (same as .gitignore) function local-ignore() { - about adds file or path to git exclude file - param 1: file or path fragment to ignore - group git + about 'adds file or path to git exclude file' + param '1: file or path fragment to ignore' + group 'git' echo "$1" >> .git/info/exclude } # get a quick overview for your git repo function git_info() { - about overview for your git repo - group git + about 'overview for your git repo' + group 'git' if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then # print informations @@ -71,8 +71,8 @@ function git_info() { } function git_stats { - about display stats per author - group git + about 'display stats per author' + group 'git' # awesome work from https://github.com/esc/git-stats # including some modifications diff --git a/plugins/available/hg.plugin.bash b/plugins/available/hg.plugin.bash index 97182fb..020b920 100644 --- a/plugins/available/hg.plugin.bash +++ b/plugins/available/hg.plugin.bash @@ -1,9 +1,9 @@ cite about-plugin -about-plugin hg helper functions +about-plugin 'hg helper functions' hg_dirty() { - about displays dirty status of hg repository - group hg + about 'displays dirty status of hg repository' + group 'hg' hg status --no-color 2> /dev/null \ | awk '$1 == "?" { print "?" } $1 != "?" { print "!" }' \ @@ -12,14 +12,14 @@ hg_dirty() { hg_in_repo() { about 'determine if pwd is an hg repo' - group hg + group 'hg' [[ `hg branch 2> /dev/null` ]] && echo 'on ' } hg_branch() { - about display current hg branch - group hg + about 'display current hg branch' + group 'hg' hg branch 2> /dev/null } diff --git a/plugins/available/javascript.plugin.bash b/plugins/available/javascript.plugin.bash index 40ee20e..40b647e 100644 --- a/plugins/available/javascript.plugin.bash +++ b/plugins/available/javascript.plugin.bash @@ -1,21 +1,21 @@ # The install directory is hard-coded. TODO: allow the directory to be specified on the command line. cite about-plugin -about-plugin download jquery files into current project +about-plugin 'download jquery files into current project' [[ -z "$JQUERY_VERSION_NUMBER" ]] && JQUERY_VERSION_NUMBER="1.6.1" [[ -z "$JQUERY_UI_VERSION_NUMBER" ]] && JQUERY_UI_VERSION_NUMBER="1.8.13" function rails_jquery { about 'download rails.js into public/javascripts' - group javascript + group 'javascript' curl -o public/javascripts/rails.js http://github.com/rails/jquery-ujs/raw/master/src/rails.js } function jquery_install { about 'download jquery.js into public/javascripts' - group javascripts + group 'javascripts' if [ -z "$1" ] then @@ -28,7 +28,7 @@ function jquery_install { function jquery_ui_install { about 'download jquery_us.js into public/javascripts' - group javascripts + group 'javascripts' if [ -z "$1" ] then diff --git a/plugins/available/jekyll.plugin.bash b/plugins/available/jekyll.plugin.bash index 2edd79e..6254a87 100644 --- a/plugins/available/jekyll.plugin.bash +++ b/plugins/available/jekyll.plugin.bash @@ -1,10 +1,10 @@ cite about-plugin -about-plugin manage your jekyll site +about-plugin 'manage your jekyll site' editpost() { - about edit a post - param 1: site directory - group jekyll + about 'edit a post' + param '1: site directory' + group 'jekyll' unset SITE if [ -z "$1" ] @@ -55,9 +55,9 @@ editpost() { } newpost() { - about create a new post - param 1: site directory - group jekyll + about 'create a new post' + param '1: site directory' + group 'jekyll' unset SITE if [ -z "$1" ] @@ -266,9 +266,9 @@ newpost() { } function testsite() { - about launches local jekyll server - param 1: site directory - group jekyll + about 'launches local jekyll server' + param '1: site directory' + group 'jekyll' unset SITE if [ -z "$1" ] @@ -298,9 +298,9 @@ function testsite() { } function buildsite() { - about builds site - param 1: site directory - group jekyll + about 'builds site' + param '1: site directory' + group 'jekyll' unset SITE if [ -z "$1" ] @@ -332,8 +332,8 @@ function buildsite() { function deploysite() { about 'rsyncs site to remote host' - param 1: site directory - group jekyll + param '1: site directory' + group 'jekyll' unset SITE if [ -z "$1" ] diff --git a/plugins/available/latex.plugin.bash b/plugins/available/latex.plugin.bash index ff9316a..eefec59 100644 --- a/plugins/available/latex.plugin.bash +++ b/plugins/available/latex.plugin.bash @@ -1,5 +1,5 @@ cite about-plugin -about-plugin use mactex +about-plugin 'use mactex' # add mactex to the path if its present MACTEX_PATH=/usr/local/texlive/2009/bin/universal-darwin diff --git a/plugins/available/nginx.plugin.bash b/plugins/available/nginx.plugin.bash index bdee127..660b503 100644 --- a/plugins/available/nginx.plugin.bash +++ b/plugins/available/nginx.plugin.bash @@ -1,9 +1,9 @@ cite about-plugin -about-plugin manage your nginx service +about-plugin 'manage your nginx service' function nginx_reload() { - about reload your nginx config - group nginx + about 'reload your nginx config' + group 'nginx' FILE="${NGINX_PATH}/logs/nginx.pid" if [ -e $FILE ]; then @@ -17,8 +17,8 @@ function nginx_reload() { } function nginx_stop() { - about stop nginx - group nginx + about 'stop nginx' + group 'nginx' FILE="${NGINX_PATH}/logs/nginx.pid" if [ -e $FILE ]; then @@ -32,8 +32,8 @@ function nginx_stop() { } function nginx_start() { - about start nginx - group nginx + about 'start nginx' + group 'nginx' FILE="${NGINX_PATH}/sbin/nginx" if [ -e $FILE ]; then @@ -45,8 +45,8 @@ function nginx_start() { } function nginx_restart() { - about restart nginx - group nginx + about 'restart nginx' + group 'nginx' FILE="${NGINX_PATH}/logs/nginx.pid" if [ -e $FILE ]; then diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index 0e51e0a..2e607d6 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -80,7 +80,7 @@ nvm() { about 'Node Version Manager' param '1: command, see nvm help' - group nvm + group 'nvm' if [ $# -lt 1 ]; then nvm help diff --git a/plugins/available/osx.plugin.bash b/plugins/available/osx.plugin.bash index ade109a..fde9c83 100644 --- a/plugins/available/osx.plugin.bash +++ b/plugins/available/osx.plugin.bash @@ -3,7 +3,7 @@ about-plugin 'osx-specific functions' function tab() { about 'opens a new terminal tab' - group osx + group 'osx' osascript 2>/dev/null <