Added new "bash-it migrate" command that migrates components from the old syntax to the new one that uses the load priority

pull/974/head
Nils Winkler 2017-05-10 11:12:08 +02:00
parent b1481038d8
commit c2446c2692
3 changed files with 52 additions and 3 deletions

View File

@ -53,7 +53,7 @@ _bash-it-comp()
prev="${COMP_WORDS[COMP_CWORD-1]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
chose_opt="${COMP_WORDS[1]}" chose_opt="${COMP_WORDS[1]}"
file_type="${COMP_WORDS[2]}" file_type="${COMP_WORDS[2]}"
opts="help show enable disable update search" opts="help show enable disable update search migrate"
case "${chose_opt}" in case "${chose_opt}" in
show) show)
local show_args="plugins aliases completions" local show_args="plugins aliases completions"
@ -65,7 +65,7 @@ _bash-it-comp()
COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) )
return 0 return 0
;; ;;
update | search) update | search | migrate)
return 0 return 0
;; ;;
enable | disable) enable | disable)

View File

@ -36,13 +36,14 @@ function reload_plugins() {
bash-it () bash-it ()
{ {
about 'Bash-it help and maintenance' about 'Bash-it help and maintenance'
param '1: verb [one of: help | show | enable | disable | update | search ] ' param '1: verb [one of: help | show | enable | disable | migrate | update | search ] '
param '2: component type [one of: alias(es) | completion(s) | plugin(s) ] or search term(s)' param '2: component type [one of: alias(es) | completion(s) | plugin(s) ] or search term(s)'
param '3: specific component [optional]' param '3: specific component [optional]'
example '$ bash-it show plugins' example '$ bash-it show plugins'
example '$ bash-it help aliases' example '$ bash-it help aliases'
example '$ bash-it enable plugin git [tmux]...' example '$ bash-it enable plugin git [tmux]...'
example '$ bash-it disable alias hg [tmux]...' example '$ bash-it disable alias hg [tmux]...'
example '$ bash-it migrate'
example '$ bash-it update' example '$ bash-it update'
example '$ bash-it search ruby [[-]rake]... [--enable | --disable]' example '$ bash-it search ruby [[-]rake]... [--enable | --disable]'
typeset verb=${1:-} typeset verb=${1:-}
@ -64,6 +65,8 @@ bash-it ()
return;; return;;
update) update)
func=_bash-it_update;; func=_bash-it_update;;
migrate)
func=_bash-it-migrate;;
*) *)
reference bash-it reference bash-it
return;; return;;
@ -150,6 +153,32 @@ _bash-it_update() {
cd - &> /dev/null cd - &> /dev/null
} }
_bash-it-migrate() {
_about 'migrates Bash-it configuration from a previous format to the current one'
_group 'lib'
for file_type in "aliases" "plugins" "completion"
do
for f in $BASH_IT/$file_type/enabled/*.bash
do
typeset ff=$(basename $f)
# Only process the ones that don't use the new structure
if ! [[ $ff =~ ^[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR.*\.bash$ ]] ; then
# Get the type of component from the extension
typeset single_type=$(echo $ff | awk -F'.' '{print $2}' | sed 's/aliases/alias/g')
typeset component_name=$(echo $ff | cut -d'.' -f1)
disable_func="_disable-$single_type"
enable_func="_enable-$single_type"
$disable_func $component_name
$enable_func $component_name
fi
done
done
}
_bash-it-describe () _bash-it-describe ()
{ {
_about 'summarizes available bash_it components' _about 'summarizes available bash_it components'

View File

@ -94,6 +94,26 @@ function __setup_plugin_tests {
[ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
} }
@test "migrate enabled plugins that don't use the new priority-based configuration" {
__setup_plugin_tests
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
[ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash
[ -L "$BASH_IT/plugins/enabled/node.plugin.bash" ]
run _enable-plugin "ssh"
[ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ]
run _bash-it-migrate
[ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
[ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
[ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ]
[ ! -L "$BASH_IT/plugins/enabled/node.plugin.bash" ]
[ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
}
@test "enable all plugins" { @test "enable all plugins" {
__setup_plugin_tests __setup_plugin_tests