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

Config can now live outside the repository #10

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion aliases/available/docker.aliases.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ case $OSTYPE in
;;
esac

if [ ! -z "$(command ls "${BASH_IT}/enabled/"{[0-9][0-9][0-9]${BASH_IT_LOAD_PRIORITY_SEPARATOR}docker,docker}.plugin.bash 2>/dev/null | head -1)" ]; then
if [ ! -z "$(command ls "${BASH_IT_CONFIG}/enabled/"{[0-9][0-9][0-9]${BASH_IT_LOAD_PRIORITY_SEPARATOR}docker,docker}.plugin.bash 2>/dev/null | head -1)" ]; then
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [ ! -z "$(command ls "${BASH_IT_CONFIG}/enabled/"{[0-9][0-9][0-9]${BASH_IT_LOAD_PRIORITY_SEPARATOR}docker,docker}.plugin.bash 2>/dev/null | head -1)" ]; then
if _bash-it-component-item-is-enabled plugin docker; then

# Function aliases from docker plugin:
alias dkrmlc='docker-remove-most-recent-container' # Delete most recent (i.e., last) Docker container
alias dkrmall='docker-remove-stale-assets' # Delete all untagged images and exited containers
Expand Down
6 changes: 3 additions & 3 deletions bash_it.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ fi
BASH_IT_LOG_PREFIX="core: main: "
_log_debug "Loading custom aliases, completion, plugins..."
for file_type in "aliases" "completion" "plugins"; do
if [ -e "${BASH_IT}/${file_type}/custom.${file_type}.bash" ]; then
if [ -e "${BASH_IT_CONFIG}/${file_type}/custom.${file_type}.bash" ]; then
BASH_IT_LOG_PREFIX="${file_type}: custom: "
_log_debug "Loading component..."
# shellcheck disable=SC1090
source "${BASH_IT}/${file_type}/custom.${file_type}.bash"
source "${BASH_IT_CONFIG}/${file_type}/custom.${file_type}.bash"
fi
done

# Custom
BASH_IT_LOG_PREFIX="core: main: "
_log_debug "Loading general custom files..."
CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash"
CUSTOM="${BASH_IT_CONFIG}/custom}/*.bash ${BASH_IT_CONFIG}/custom}/**/*.bash"
for _bash_it_config_file in $CUSTOM; do
if [ -e "${_bash_it_config_file}" ]; then
filename=$(basename "${_bash_it_config_file}")
Expand Down
6 changes: 3 additions & 3 deletions completion/available/bash-it.completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ _bash-it-comp-list-available-not-enabled()
do
file_entity=$(basename $f)

typeset enabled_component=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity,$file_entity} 2>/dev/null | head -1)
typeset enabled_component_global=$(command ls "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity 2>/dev/null | head -1)
typeset enabled_component=$(command ls "${BASH_IT_CONFIG}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity,$file_entity} 2>/dev/null | head -1)
typeset enabled_component_global=$(command ls "${BASH_IT_CONFIG}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity 2>/dev/null | head -1)

if [ -z "$enabled_component" ] && [ -z "$enabled_component_global" ]
then
Expand All @@ -35,7 +35,7 @@ _bash-it-comp-list-enabled()

suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g')

enabled_things=$(for f in `sort -d <(compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash") <(compgen -G "${BASH_IT}/enabled/*.${suffix}.bash")`;
enabled_things=$(for f in `sort -d <(compgen -G "${BASH_IT_CONFIG}/$subdirectory/enabled/*.${suffix}.bash") <(compgen -G "${BASH_IT_CONFIG}/enabled/*.${suffix}.bash")`;
do
basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g' | sed -e "s/^[0-9]*---//g"
done)
Expand Down
67 changes: 62 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ function _bash-it_show_usage() {
function _bash-it_load_one() {
file_type=$1
file_to_enable=$2
mkdir -p "$BASH_IT/${file_type}/enabled"
mkdir -p "$BASH_IT_CONFIG/${file_type}/enabled"

dest="${BASH_IT}/${file_type}/enabled/${file_to_enable}"
dest="${BASH_IT_CONFIG}/${file_type}/enabled/${file_to_enable}"
if [ ! -e "${dest}" ]; then
ln -sf "../available/${file_to_enable}" "${dest}"
ln -sf "${BASH_IT}/available/${file_to_enable}" "${dest}"
else
echo "File ${dest} exists, skipping"
fi
Expand All @@ -34,7 +34,7 @@ function _bash-it_load_some() {
file_type=$1
single_type=$(echo "$file_type" | sed -e "s/aliases$/alias/g" | sed -e "s/plugins$/plugin/g")
enable_func="_enable-$single_type"
[ -d "$BASH_IT/$file_type/enabled" ] || mkdir "$BASH_IT/$file_type/enabled"
[ -d "$BASH_IT_CONFIG/$file_type/enabled" ] || mkdir "$BASH_IT_CONFIG/$file_type/enabled"
for path in "$BASH_IT/${file_type}/available/"[^_]*; do
file_name=$(basename "$path")
while true; do
Expand Down Expand Up @@ -66,7 +66,7 @@ function _bash-it_backup() {
# Back up existing profile and create new one for bash-it
function _bash-it_backup_new() {
_bash-it_backup
sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" > "$HOME/$CONFIG_FILE"
sed -e "s|{{BASH_IT}}|$BASH_IT|" -e "s|{{BASH_IT_CONFIG}}|$BASH_IT_CONFIG_TEMPLATE|" "$BASH_IT/template/bash_profile.template.bash" > "$HOME/$CONFIG_FILE"
echo -e "\033[0;32mCopied the template $CONFIG_FILE into ~/$CONFIG_FILE, edit this file to customize bash-it\033[0m"
}

Expand Down Expand Up @@ -111,6 +111,62 @@ function _bash-it_check_for_backup() {
fi
}

function _bash-it_choose_bash_it_config_dir() {
if [[ -z "${silent}" ]]; then
echo Please select where to store your bash-it configuration
select config_dir in '${XDG_CONFIG_HOME:-${HOME}/.config}/bash-it' "${BASH_IT}" "Write one" "Quit"; do
case "$config_dir" in
'${XDG_CONFIG_HOME:-${HOME}/.config}/bash-it')
read -e -n 1 -r -p "Right now this results in '${XDG_CONFIG_HOME:-${HOME}/.config}/bash-it' does that look ok? [y/N] " choice
case $choice in
[yY])
export BASH_IT_CONFIG_TEMPLATE='${XDG_CONFIG_HOME:-${HOME}/.config}/bash-it'
export BASH_IT_CONFIG=${XDG_CONFIG_HOME:-${HOME}/.config}/bash-it
break 3
;;
[nN] | "")
continue
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
;;
esac

;;
"${BASH_IT}")
export BASH_IT_CONFIG_TEMPLATE='${BASH_IT}'
export BASH_IT_CONFIG="${BASH_IT}"
break 2
;;
"Write one")
while read -e -r -i "${BASH_IT_CONFIG}" -p "Enter BASH_IT_CONFIG dir> " folder; do
[ -z "$folder" ] && break
[ -d "$folder" ] || mkdir -p $folder || continue
if [ \! -w "$folder" ]; then
echo "${folder} not writable";
continue
fi
export BASH_IT_CONFIG_TEMPLATE="${folder}"
export BASH_IT_CONFIG="${folder}"
break 2
done
;;
"Quit")
echo -e "\033[91mInstallation aborted. Please come back soon!\033[m"
exit 0
;;
*)
echo "Try again"
continue
;;
esac
done
else
export BASH_IT_CONFIG_TEMPLATE='${XDG_CONFIG_HOME:-${HOME}/.config}/bash-it'
export BASH_IT_CONFIG=${XDG_CONFIG_HOME:-${HOME}/.config}/bash-it
fi
}

function _bash-it_modify_config_files() {
_bash-it_check_for_backup

Expand Down Expand Up @@ -185,6 +241,7 @@ if [[ -n "${no_modify_config}" && -n "${append_to_config}" ]]; then
fi

BASH_IT="$(cd "${BASH_SOURCE%/*}" && pwd)"
_bash-it_choose_bash_it_config_dir

case $OSTYPE in
darwin*)
Expand Down
2 changes: 1 addition & 1 deletion lib/appearance.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
export LSCOLORS='Gxfxcxdxdxegedabagacad'

if [[ -z "$CUSTOM_THEME_DIR" ]]; then
CUSTOM_THEME_DIR="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/themes"
CUSTOM_THEME_DIR="${BASH_IT_CONFIG}/custom/themes"
fi

# Load the theme
Expand Down
27 changes: 14 additions & 13 deletions lib/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ _bash-it-migrate() {

for file_type in "aliases" "plugins" "completion"
do
for f in `sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")`
for f in `sort <(compgen -G "${BASH_IT_CONFIG}/$file_type/enabled/*.bash")`
do
typeset ff="${f##*/}"

Expand Down Expand Up @@ -514,7 +514,7 @@ _bash-it-describe ()
# Check for both the old format without the load priority, and the extended format with the priority
declare enabled_files enabled_file
enabled_file="${f##*/}"
enabled_files=$(sort <(compgen -G "${BASH_IT}/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") | wc -l)
enabled_files=$(sort <(compgen -G "${BASH_IT_CONFIG}/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") <(compgen -G "${BASH_IT_CONFIG}/$subdirectory/enabled/${enabled_file}") <(compgen -G "${BASH_IT_CONFIG}/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") | wc -l)

if [ $enabled_files -gt 0 ]; then
enabled='x'
Expand Down Expand Up @@ -593,31 +593,31 @@ _disable-thing ()

if [ "$file_entity" = "all" ]; then
# Disable everything that's using the old structure
for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash"`
for f in `compgen -G "${BASH_IT_CONFIG}/$subdirectory/enabled/*.${suffix}.bash"`
do
rm "$f"
done

# Disable everything in the global "enabled" directory
for f in `compgen -G "${BASH_IT}/enabled/*.${suffix}.bash"`
for f in `compgen -G "${BASH_IT_CONFIG}/enabled/*.${suffix}.bash"`
do
rm "$f"
done
else
typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash 2>/dev/null | head -1)
typeset plugin_global=$(command ls $ "${BASH_IT_CONFIG}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash 2>/dev/null | head -1)
if [ -z "$plugin_global" ]; then
# Use a glob to search for both possible patterns
# 250---node.plugin.bash
# node.plugin.bash
# Either one will be matched by this glob
typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash,$file_entity.$suffix.bash} 2>/dev/null | head -1)
typeset plugin=$(command ls $ "${BASH_IT_CONFIG}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash,$file_entity.$suffix.bash} 2>/dev/null | head -1)
if [ -z "$plugin" ]; then
printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type."
return
fi
rm "${BASH_IT}/$subdirectory/enabled/${plugin##*/}"
rm "${BASH_IT_CONFIG}/$subdirectory/enabled/${plugin##*/}"
else
rm "${BASH_IT}/enabled/${plugin_global##*/}"
rm "${BASH_IT_CONFIG}/enabled/${plugin_global##*/}"
fi
fi

Expand Down Expand Up @@ -695,26 +695,26 @@ _enable-thing ()

to_enable="${to_enable##*/}"
# Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it.
typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1)
typeset enabled_plugin=$(command ls "${BASH_IT_CONFIG}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1)
if [ ! -z "$enabled_plugin" ] ; then
printf '%s\n' "$file_entity is already enabled."
return
fi

typeset enabled_plugin_global=$(command compgen -G "${BASH_IT}/enabled/[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable" 2>/dev/null | head -1)
typeset enabled_plugin_global=$(command compgen -G "${BASH_IT_CONFIG}/enabled/[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable" 2>/dev/null | head -1)
if [ ! -z "$enabled_plugin_global" ] ; then
printf '%s\n' "$file_entity is already enabled."
return
fi

mkdir -p "${BASH_IT}/enabled"
mkdir -p "${BASH_IT_CONFIG}/enabled"

# Load the priority from the file if it present there
declare local_file_priority use_load_priority
local_file_priority="$(_bash-it-egrep "^# BASH_IT_LOAD_PRIORITY:" "${BASH_IT}/$subdirectory/available/$to_enable" | awk -F': ' '{ print $2 }')"
use_load_priority="${local_file_priority:-$load_priority}"

ln -s ../$subdirectory/available/$to_enable "${BASH_IT}/enabled/${use_load_priority}${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}"
ln -s ${BASH_IT}/$subdirectory/available/$to_enable "${BASH_IT_CONFIG}/enabled/${use_load_priority}${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}"
fi

_bash-it-clean-component-cache "${file_type}"
Expand Down Expand Up @@ -750,11 +750,12 @@ _help-aliases()
else
typeset f

for f in `sort <(compgen -G "${BASH_IT}/aliases/enabled/*") <(compgen -G "${BASH_IT}/enabled/*.aliases.bash")`
for f in `sort <(compgen -G "${BASH_IT_CONFIG}/aliases/enabled/*") <(compgen -G "${BASH_IT_CONFIG}/enabled/*.aliases.bash")`
do
_help-list-aliases $f
done

#TODO: Shouldn't this be in ${BASH_IT_CONFIG/custom?
if [ -e "${BASH_IT}/aliases/custom.aliases.bash" ]; then
_help-list-aliases "${BASH_IT}/aliases/custom.aliases.bash"
fi
Expand Down
1 change: 1 addition & 0 deletions lib/preview.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ then

"

#TODO: add custom themes dir?
THEMES="$BASH_IT/themes/*/*.theme.bash"
for theme in $THEMES
do
Expand Down
2 changes: 1 addition & 1 deletion lib/utilities.bash
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function _bash-it-component-help() {
function _bash-it-component-cache-file() {
local component file
component="$(_bash-it-pluralize-component "${1?${FUNCNAME[0]}: component name required}")"
file="${XDG_CACHE_HOME:-${BASH_IT?}/tmp/cache}${XDG_CACHE_HOME:+/bash_it}/${component}"
file="${XDG_CACHE_HOME:-${BASH_IT_CONFIG?}/tmp/cache}${XDG_CACHE_HOME:+/bash_it}/${component}"
[[ -f "${file}" ]] || mkdir -p "${file%/*}"
printf '%s' "${file}"
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/available/base.plugin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ function usage() {
}

# shellcheck disable=SC2144 # the glob matches only one file
if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" &&
! -e "${BASH_IT?}/plugins/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR-}todo.plugin.bash" ]]; then
if [[ ! -e "${BASH_IT_CONFIG?}/plugins/enabled/todo.plugin.bash" &&
! -e "${BASH_IT_CONFIG?}/plugins/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR-}todo.plugin.bash" ]]; then
# if user has installed todo plugin, skip this...
function t() {
about 'one thing todo'
Expand Down
8 changes: 4 additions & 4 deletions scripts/reloader.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function _set-prefix-based-on-path()
BASH_IT_LOG_PREFIX="$extension: $filename: "
}

if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then
if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT_CONFIG/enabled" ]]; then
_bash_it_config_type=""

case $1 in
Expand All @@ -20,7 +20,7 @@ if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then
_log_debug "Loading all enabled components..." ;;
esac

for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT/enabled/*${_bash_it_config_type}.bash")); do
for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT_CONFIG/enabled/*${_bash_it_config_type}.bash")); do
if [ -e "${_bash_it_config_file}" ]; then
_set-prefix-based-on-path "${_bash_it_config_file}"
_log_debug "Loading component..."
Expand All @@ -32,11 +32,11 @@ if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then
done
fi

if [[ -n "${2}" ]] && [[ -d "$BASH_IT/${2}/enabled" ]]; then
if [[ -n "${2}" ]] && [[ -d "$BASH_IT_CONFIG/${2}/enabled" ]]; then
case $2 in
aliases|completion|plugins)
_log_warning "Using legacy enabling for $2, please update your bash-it version and migrate"
for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT/${2}/enabled/*.bash")); do
for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT_CONFIG/${2}/enabled/*.bash")); do
if [[ -e "$_bash_it_config_file" ]]; then
_set-prefix-based-on-path "${_bash_it_config_file}"
_log_debug "Loading component..."
Expand Down
2 changes: 2 additions & 0 deletions template/bash_profile.template.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ esac

# Path to the bash it configuration
export BASH_IT="{{BASH_IT}}"
# Path to the user configuration
export BASH_IT_CONFIG="${BASH_IT_CONFIG:={{BASH_IT_CONFIG}}}"

# Lock and Load a custom theme file.
# Leave empty to disable theming.
Expand Down