Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add profile subcommand #1865

Merged
merged 21 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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