Skip to content

Commit

Permalink
Merge pull request #1865 from NoahGorny/add-profile-subcommand
Browse files Browse the repository at this point in the history
add profile subcommand
  • Loading branch information
NoahGorny authored Jan 3, 2022
2 parents f0abc3f + cd38f32 commit c81c9dc
Show file tree
Hide file tree
Showing 11 changed files with 517 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ bats
enabled/*
/enabled
tmp/

# Do not save profiles
profiles/*
# apart from the default one
!profiles/default.bash_it
41 changes: 40 additions & 1 deletion completion/available/bash-it.completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ _bash-it-comp-list-available()
COMPREPLY=( $(compgen -W "${enabled_things}" -- ${cur}) )
}

_bash-it-comp-list-profiles()
{
local profiles

profiles=$(for f in `compgen -G "${BASH_IT}/profiles/*.bash_it" | sort -d`;
do
basename $f | sed -e 's/.bash_it//g'
done)

COMPREPLY=( $(compgen -W "${profiles}" -- ${cur}) )
}

_bash-it-comp()
{
local cur prev opts
Expand All @@ -65,7 +77,7 @@ _bash-it-comp()
prev="${COMP_WORDS[COMP_CWORD-1]}"
chose_opt="${COMP_WORDS[1]}"
file_type="${COMP_WORDS[2]}"
opts="disable enable help migrate reload restart doctor search show update version"
opts="disable enable help migrate reload restart profile doctor search show update version"
case "${chose_opt}" in
show)
local show_args="aliases completions plugins"
Expand All @@ -82,6 +94,33 @@ _bash-it-comp()
return 0
fi
;;
profile)
case "${file_type}" in
load)
if [[ "load" == "$prev" ]]; then
_bash-it-comp-list-profiles
fi
return 0
;;
rm)
if [[ "rm" == "$prev" ]]; then
_bash-it-comp-list-profiles
fi
return 0
;;
save)
return 0
;;
list)
return 0
;;
*)
local profile_args="load save list rm"
COMPREPLY=( $(compgen -W "${profile_args}" -- ${cur}) )
return 0
;;
esac
;;
doctor)
local doctor_args="errors warnings all"
COMPREPLY=( $(compgen -W "${doctor_args}" -- ${cur}) )
Expand Down
1 change: 1 addition & 0 deletions docs/commands/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ You should be familiar with them in order to fully utilize Bash-it.
search
reload
doctor
profile
31 changes: 31 additions & 0 deletions docs/commands/profile.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.. _profile:

Bash-it Profile
---------------

Have you ever wanted to port your *Bash-it* configuration into another machine?

If you did, then ``bash-it profile`` is for you!

This command can save and load custom *"profile"* files, that can be later
used to load and recreate your configuration, in any machine you would like |:smile:|

When porting your configuration into a new machine, you just need to save your current profile, copy the resulting *"profile"* file, and load it in the other machine.

Example
^^^^^^^

.. code-block:: bash
# Saves your current profile
bash-it profile save my_profile
# Load the default profile, which is the one used in the default installation.
bash-it profile load default
# Do whatever you want:
# Disable stuff
bash-it disable ...
# Enable stuff
bash-it enable ...
# If you want to get back into your original configuration, you can do it easily
bash-it profile load my_profile
9 changes: 3 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ export BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE=''
source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh
# shellcheck source=./lib/utilities.bash
source "$BASH_IT/lib/utilities.bash"
# shellcheck source=./lib/log.bash
source "${BASH_IT}/lib/log.bash"
cite _about _param _example _group _author _version
# shellcheck source=./lib/helpers.bash
source "$BASH_IT/lib/helpers.bash"
Expand All @@ -219,12 +221,7 @@ if [[ -n $interactive && -z "${silent}" ]]; then
done
else
echo ""
echo -e "\033[0;32mEnabling reasonable defaults\033[0m"
_enable-completion bash-it
_enable-completion system
_enable-plugin base
_enable-plugin alias-completion
_enable-alias general
_bash-it-profile-load "default"
fi

echo ""
Expand Down
Loading

0 comments on commit c81c9dc

Please sign in to comment.