Getting Bash-it to use the vendored composure

Fixed tests
Fixed install.sh and bash_it.sh
Added gitattributes to the vendor folder
Changed documentation
pull/1820/head
buhl 2021-01-28 22:54:12 +01:00
parent a0b6c4993a
commit 49d7d2e8c4
27 changed files with 306 additions and 677 deletions

View File

@ -38,6 +38,7 @@ repos:
types: [file] types: [file]
- id: dot-bash - id: dot-bash
name: Check .bash files against bash-it requirements name: Check .bash files against bash-it requirements
exclude: "test/test_helper.bash"
entry: ./hooks/dot-bash.sh entry: ./hooks/dot-bash.sh
language: system language: system
files: "\\.bash$" files: "\\.bash$"

View File

@ -3,18 +3,18 @@
BASH_IT_LOG_PREFIX="core: main: " BASH_IT_LOG_PREFIX="core: main: "
# Only set $BASH_IT if it's not already set # Only set $BASH_IT if it's not already set
if [ -z "$BASH_IT" ]; if [ -z "$BASH_IT" ]; then
then # Setting $BASH to maintain backwards compatibility
# Setting $BASH to maintain backwards compatibility export BASH_IT=$BASH
export BASH_IT=$BASH BASH="$(bash -c 'echo $BASH')"
BASH="$(bash -c 'echo $BASH')" export BASH
export BASH BASH_IT_OLD_BASH_SETUP=true
BASH_IT_OLD_BASH_SETUP=true
fi fi
# Load composure first, so we support function metadata # Load composure first, so we support function metadata
# shellcheck source=./lib/composure.bash # shellcheck disable=SC1090
source "${BASH_IT}/lib/composure.bash" source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh
# We need to load logging module first as well in order to be able to log # We need to load logging module first as well in order to be able to log
# shellcheck source=./lib/log.bash # shellcheck source=./lib/log.bash
source "${BASH_IT}/lib/log.bash" source "${BASH_IT}/lib/log.bash"
@ -23,39 +23,37 @@ source "${BASH_IT}/lib/log.bash"
[ -z "$BASH_IT_OLD_BASH_SETUP" ] || _log_warning "BASH_IT variable not initialized, please upgrade your bash-it version and reinstall it!" [ -z "$BASH_IT_OLD_BASH_SETUP" ] || _log_warning "BASH_IT variable not initialized, please upgrade your bash-it version and reinstall it!"
# For backwards compatibility, look in old BASH_THEME location # For backwards compatibility, look in old BASH_THEME location
if [ -z "$BASH_IT_THEME" ]; if [ -z "$BASH_IT_THEME" ]; then
then _log_warning "BASH_IT_THEME variable not initialized, please upgrade your bash-it version and reinstall it!"
_log_warning "BASH_IT_THEME variable not initialized, please upgrade your bash-it version and reinstall it!" export BASH_IT_THEME="$BASH_THEME"
export BASH_IT_THEME="$BASH_THEME"; unset BASH_THEME
unset BASH_THEME;
fi fi
# support 'plumbing' metadata # support 'plumbing' metadata
cite _about _param _example _group _author _version cite _about _param _example _group _author _version
cite about-alias about-plugin about-completion
# libraries, but skip appearance (themes) for now # libraries, but skip appearance (themes) for now
_log_debug "Loading libraries(except appearance)..." _log_debug "Loading libraries(except appearance)..."
LIB="${BASH_IT}/lib/*.bash" LIB="${BASH_IT}/lib/*.bash"
APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash" APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash"
for _bash_it_config_file in $LIB for _bash_it_config_file in $LIB; do
do if [ "$_bash_it_config_file" != "$APPEARANCE_LIB" ]; then
if [ "$_bash_it_config_file" != "$APPEARANCE_LIB" ]; then filename=${_bash_it_config_file##*/}
filename=${_bash_it_config_file##*/} filename=${filename%.bash}
filename=${filename%.bash} BASH_IT_LOG_PREFIX="lib: ${filename}: "
BASH_IT_LOG_PREFIX="lib: ${filename}: " _log_debug "Loading library file..."
_log_debug "Loading library file..." # shellcheck disable=SC1090
# shellcheck disable=SC1090 source "$_bash_it_config_file"
source "$_bash_it_config_file" fi
fi
done done
# Load vendors # Load vendors
BASH_IT_LOG_PREFIX="vendor: " BASH_IT_LOG_PREFIX="vendor: "
for _bash_it_vendor_init in "${BASH_IT}"/vendor/init.d/*.bash for _bash_it_vendor_init in "${BASH_IT}"/vendor/init.d/*.bash; do
do _log_debug "Loading \"$(basename "${_bash_it_vendor_init}" .bash)\"..."
_log_debug "Loading \"$(basename "${_bash_it_vendor_init}" .bash)\"..." # shellcheck disable=SC1090
# shellcheck disable=SC1090 source "${_bash_it_vendor_init}"
source "${_bash_it_vendor_init}"
done done
unset _bash_it_vendor_init unset _bash_it_vendor_init
@ -66,100 +64,95 @@ BASH_IT_LOG_PREFIX="core: main: "
source "${BASH_IT}/scripts/reloader.bash" source "${BASH_IT}/scripts/reloader.bash"
# Load enabled aliases, completion, plugins # Load enabled aliases, completion, plugins
for file_type in "aliases" "plugins" "completion" for file_type in "aliases" "plugins" "completion"; do
do # shellcheck source=./scripts/reloader.bash
# shellcheck source=./scripts/reloader.bash source "${BASH_IT}/scripts/reloader.bash" "skip" "$file_type"
source "${BASH_IT}/scripts/reloader.bash" "skip" "$file_type"
done done
# Load theme, if a theme was set # Load theme, if a theme was set
if [[ -n "${BASH_IT_THEME}" ]]; then if [[ -n "${BASH_IT_THEME}" ]]; then
_log_debug "Loading \"${BASH_IT_THEME}\" theme..." _log_debug "Loading \"${BASH_IT_THEME}\" theme..."
# Load colors and helpers first so they can be used in base theme # Load colors and helpers first so they can be used in base theme
BASH_IT_LOG_PREFIX="themes: colors: " BASH_IT_LOG_PREFIX="themes: colors: "
# shellcheck source=./themes/colors.theme.bash # shellcheck source=./themes/colors.theme.bash
source "${BASH_IT}/themes/colors.theme.bash" source "${BASH_IT}/themes/colors.theme.bash"
BASH_IT_LOG_PREFIX="themes: githelpers: " BASH_IT_LOG_PREFIX="themes: githelpers: "
# shellcheck source=./themes/githelpers.theme.bash # shellcheck source=./themes/githelpers.theme.bash
source "${BASH_IT}/themes/githelpers.theme.bash" source "${BASH_IT}/themes/githelpers.theme.bash"
BASH_IT_LOG_PREFIX="themes: p4helpers: " BASH_IT_LOG_PREFIX="themes: p4helpers: "
# shellcheck source=./themes/p4helpers.theme.bash # shellcheck source=./themes/p4helpers.theme.bash
source "${BASH_IT}/themes/p4helpers.theme.bash" source "${BASH_IT}/themes/p4helpers.theme.bash"
BASH_IT_LOG_PREFIX="themes: command_duration: " BASH_IT_LOG_PREFIX="themes: command_duration: "
# shellcheck source=./themes/command_duration.theme.bash # shellcheck source=./themes/command_duration.theme.bash
source "${BASH_IT}/themes/command_duration.theme.bash" source "${BASH_IT}/themes/command_duration.theme.bash"
BASH_IT_LOG_PREFIX="themes: base: " BASH_IT_LOG_PREFIX="themes: base: "
# shellcheck source=./themes/base.theme.bash # shellcheck source=./themes/base.theme.bash
source "${BASH_IT}/themes/base.theme.bash" source "${BASH_IT}/themes/base.theme.bash"
BASH_IT_LOG_PREFIX="lib: appearance: " BASH_IT_LOG_PREFIX="lib: appearance: "
# appearance (themes) now, after all dependencies # appearance (themes) now, after all dependencies
# shellcheck source=./lib/appearance.bash # shellcheck source=./lib/appearance.bash
source "$APPEARANCE_LIB" source "$APPEARANCE_LIB"
fi fi
BASH_IT_LOG_PREFIX="core: main: " BASH_IT_LOG_PREFIX="core: main: "
_log_debug "Loading custom aliases, completion, plugins..." _log_debug "Loading custom aliases, completion, plugins..."
for file_type in "aliases" "completion" "plugins" for file_type in "aliases" "completion" "plugins"; do
do if [ -e "${BASH_IT}/${file_type}/custom.${file_type}.bash" ]; then
if [ -e "${BASH_IT}/${file_type}/custom.${file_type}.bash" ] BASH_IT_LOG_PREFIX="${file_type}: custom: "
then _log_debug "Loading component..."
BASH_IT_LOG_PREFIX="${file_type}: custom: " # shellcheck disable=SC1090
_log_debug "Loading component..." source "${BASH_IT}/${file_type}/custom.${file_type}.bash"
# shellcheck disable=SC1090 fi
source "${BASH_IT}/${file_type}/custom.${file_type}.bash"
fi
done done
# Custom # Custom
BASH_IT_LOG_PREFIX="core: main: " BASH_IT_LOG_PREFIX="core: main: "
_log_debug "Loading general custom files..." _log_debug "Loading general custom files..."
CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash" CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash"
for _bash_it_config_file in $CUSTOM for _bash_it_config_file in $CUSTOM; do
do if [ -e "${_bash_it_config_file}" ]; then
if [ -e "${_bash_it_config_file}" ]; then filename=$(basename "${_bash_it_config_file}")
filename=$(basename "${_bash_it_config_file}") filename=${filename%*.bash}
filename=${filename%*.bash} BASH_IT_LOG_PREFIX="custom: $filename: "
BASH_IT_LOG_PREFIX="custom: $filename: " _log_debug "Loading custom file..."
_log_debug "Loading custom file..." # shellcheck disable=SC1090
# shellcheck disable=SC1090 source "$_bash_it_config_file"
source "$_bash_it_config_file" fi
fi
done done
unset _bash_it_config_file unset _bash_it_config_file
if [[ $PROMPT ]]; then if [[ $PROMPT ]]; then
export PS1="\[""$PROMPT""\]" export PS1="\[""$PROMPT""\]"
fi fi
# Adding Support for other OSes # Adding Support for other OSes
PREVIEW="less" PREVIEW="less"
if [ -s /usr/bin/gloobus-preview ]; then if [ -s /usr/bin/gloobus-preview ]; then
PREVIEW="gloobus-preview" PREVIEW="gloobus-preview"
elif [ -s /Applications/Preview.app ]; then elif [ -s /Applications/Preview.app ]; then
# shellcheck disable=SC2034 # shellcheck disable=SC2034
PREVIEW="/Applications/Preview.app" PREVIEW="/Applications/Preview.app"
fi fi
# Load all the Jekyll stuff # Load all the Jekyll stuff
if [ -e "$HOME/.jekyllconfig" ] if [ -e "$HOME/.jekyllconfig" ]; then
then # shellcheck disable=SC1090
# shellcheck disable=SC1090 . "$HOME/.jekyllconfig"
. "$HOME/.jekyllconfig"
fi fi
# BASH_IT_RELOAD_LEGACY is set. # BASH_IT_RELOAD_LEGACY is set.
if ! command -v reload &>/dev/null && [ -n "$BASH_IT_RELOAD_LEGACY" ]; then if ! command -v reload &> /dev/null && [ -n "$BASH_IT_RELOAD_LEGACY" ]; then
case $OSTYPE in case $OSTYPE in
darwin*) darwin*)
alias reload='source ~/.bash_profile' alias reload='source ~/.bash_profile'
;; ;;
*) *)
alias reload='source ~/.bashrc' alias reload='source ~/.bashrc'
;; ;;
esac esac
fi fi
# Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040 # Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040

View File

@ -23,6 +23,8 @@ hooks
# #
.gitattributes .gitattributes
lint_clean_files.sh lint_clean_files.sh
install.sh
bash_it.sh
# plugins # plugins
# #
@ -92,5 +94,9 @@ aliases/available/dnf.aliases.bash
aliases/available/vim.aliases.bash aliases/available/vim.aliases.bash
aliases/available/git.aliases.bash aliases/available/git.aliases.bash
# tests
test/test_helper.bash
# vendor init files # vendor init files
vendor/.gitattributes
vendor/init.d vendor/init.d

View File

@ -37,9 +37,12 @@ General Load Order
The main ``bash_it.sh`` script loads the frameworks individual components in the following order: The main ``bash_it.sh`` script loads the frameworks individual components in the following order:
* ``lib/composure.bash``
* ``vendor/github.com/erichs/composure/composure.sh``
* ``lib/log.bash``
* ``vendor/init.d/*.bash`` * ``vendor/init.d/*.bash``
* Files in ``lib`` with the exception of ``appearance.bash`` - this means that ``composure.bash`` is loaded again here (possible improvement?) * Files in ``lib`` with the exception of ``appearance.bash`` - this means that ``log.bash`` is loaded again here (possible improvement?)
* Enabled ``aliases`` * Enabled ``aliases``
* Enabled ``plugins`` * Enabled ``plugins``
* Enabled ``completions`` * Enabled ``completions``

View File

@ -3,72 +3,70 @@
# Show how to use this installer # Show how to use this installer
function show_usage() { function show_usage() {
echo -e "\n$0 : Install bash-it" echo -e "\n$0 : Install bash-it"
echo -e "Usage:\n$0 [arguments] \n" echo -e "Usage:\n$0 [arguments] \n"
echo "Arguments:" echo "Arguments:"
echo "--help (-h): Display this help message" echo "--help (-h): Display this help message"
echo "--silent (-s): Install default settings without prompting for input"; echo "--silent (-s): Install default settings without prompting for input"
echo "--interactive (-i): Interactively choose plugins" echo "--interactive (-i): Interactively choose plugins"
echo "--no-modify-config (-n): Do not modify existing config file" echo "--no-modify-config (-n): Do not modify existing config file"
echo "--append-to-config (-a): Keep existing config file and append bash-it templates at the end" echo "--append-to-config (-a): Keep existing config file and append bash-it templates at the end"
exit 0; exit 0
} }
# enable a thing # enable a thing
function load_one() { function load_one() {
file_type=$1 file_type=$1
file_to_enable=$2 file_to_enable=$2
mkdir -p "$BASH_IT/${file_type}/enabled" mkdir -p "$BASH_IT/${file_type}/enabled"
dest="${BASH_IT}/${file_type}/enabled/${file_to_enable}" dest="${BASH_IT}/${file_type}/enabled/${file_to_enable}"
if [ ! -e "${dest}" ]; then if [ ! -e "${dest}" ]; then
ln -sf "../available/${file_to_enable}" "${dest}" ln -sf "../available/${file_to_enable}" "${dest}"
else else
echo "File ${dest} exists, skipping" echo "File ${dest} exists, skipping"
fi fi
} }
# Interactively enable several things # Interactively enable several things
function load_some() { function load_some() {
file_type=$1 file_type=$1
single_type=$(echo "$file_type" | sed -e "s/aliases$/alias/g" | sed -e "s/plugins$/plugin/g") single_type=$(echo "$file_type" | sed -e "s/aliases$/alias/g" | sed -e "s/plugins$/plugin/g")
enable_func="_enable-$single_type" enable_func="_enable-$single_type"
[ -d "$BASH_IT/$file_type/enabled" ] || mkdir "$BASH_IT/$file_type/enabled" [ -d "$BASH_IT/$file_type/enabled" ] || mkdir "$BASH_IT/$file_type/enabled"
for path in "$BASH_IT/${file_type}/available/"[^_]* for path in "$BASH_IT/${file_type}/available/"[^_]*; do
do file_name=$(basename "$path")
file_name=$(basename "$path") while true; do
while true just_the_name="${file_name%%.*}"
do read -r -e -n 1 -p "Would you like to enable the $just_the_name $file_type? [y/N] " RESP
just_the_name="${file_name%%.*}" case $RESP in
read -e -n 1 -p "Would you like to enable the $just_the_name $file_type? [y/N] " RESP [yY])
case $RESP in $enable_func "$just_the_name"
[yY]) break
$enable_func $just_the_name ;;
break [nN] | "")
;; break
[nN]|"") ;;
break *)
;; echo -e "\033[91mPlease choose y or n.\033[m"
*) ;;
echo -e "\033[91mPlease choose y or n.\033[m" esac
;; done
esac done
done
done
} }
# Back up existing profile # Back up existing profile
function backup() { function backup() {
test -w "$HOME/$CONFIG_FILE" && test -w "$HOME/$CONFIG_FILE" \
cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" && && cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" \
echo -e "\033[0;32mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak\033[0m" && echo -e "\033[0;32mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak\033[0m"
} }
# Back up existing profile and create new one for bash-it # Back up existing profile and create new one for bash-it
function backup_new() { function backup_new() {
backup backup
sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" > "$HOME/$CONFIG_FILE" sed "s|{{BASH_IT}}|$BASH_IT|" "$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" echo -e "\033[0;32mCopied the template $CONFIG_FILE into ~/$CONFIG_FILE, edit this file to customize bash-it\033[0m"
} }
# Back up existing profile and append bash-it templates at the end # Back up existing profile and append bash-it templates at the end
@ -79,125 +77,132 @@ function backup_append() {
} }
for param in "$@"; do for param in "$@"; do
shift shift
case "$param" in case "$param" in
"--help") set -- "$@" "-h" ;; "--help") set -- "$@" "-h" ;;
"--silent") set -- "$@" "-s" ;; "--silent") set -- "$@" "-s" ;;
"--interactive") set -- "$@" "-i" ;; "--interactive") set -- "$@" "-i" ;;
"--no-modify-config") set -- "$@" "-n" ;; "--no-modify-config") set -- "$@" "-n" ;;
"--append-to-config") set -- "$@" "-a" ;; "--append-to-config") set -- "$@" "-a" ;;
*) set -- "$@" "$param" *) set -- "$@" "$param" ;;
esac esac
done done
OPTIND=1 OPTIND=1
while getopts "hsina" opt while getopts "hsina" opt; do
do case "$opt" in
case "$opt" in "h")
"h") show_usage; exit 0 ;; show_usage
"s") silent=true ;; exit 0
"i") interactive=true ;; ;;
"n") no_modify_config=true ;; "s") silent=true ;;
"a") append_to_config=true ;; "i") interactive=true ;;
"?") show_usage >&2; exit 1 ;; "n") no_modify_config=true ;;
esac "a") append_to_config=true ;;
"?")
show_usage >&2
exit 1
;;
esac
done done
shift $(expr $OPTIND - 1) shift $(("$OPTIND" - 1))
if [[ $silent ]] && [[ $interactive ]]; then if [[ $silent ]] && [[ $interactive ]]; then
echo -e "\033[91mOptions --silent and --interactive are mutually exclusive. Please choose one or the other.\033[m" echo -e "\033[91mOptions --silent and --interactive are mutually exclusive. Please choose one or the other.\033[m"
exit 1; exit 1
fi fi
if [[ $no_modify_config ]] && [[ $append_to_config ]]; then if [[ $no_modify_config ]] && [[ $append_to_config ]]; then
echo -e "\033[91mOptions --no-modify-config and --append-to-config are mutually exclusive. Please choose one or the other.\033[m" echo -e "\033[91mOptions --no-modify-config and --append-to-config are mutually exclusive. Please choose one or the other.\033[m"
exit 1; exit 1
fi fi
BASH_IT="$(cd "$(dirname "$0")" && pwd)" BASH_IT="$(cd "$(dirname "$0")" && pwd)"
case $OSTYPE in case $OSTYPE in
darwin*) darwin*)
CONFIG_FILE=.bash_profile CONFIG_FILE=.bash_profile
;; ;;
*) *)
CONFIG_FILE=.bashrc CONFIG_FILE=.bashrc
;; ;;
esac esac
BACKUP_FILE=$CONFIG_FILE.bak BACKUP_FILE=$CONFIG_FILE.bak
echo "Installing bash-it" echo "Installing bash-it"
if ! [[ $silent ]] && ! [[ $no_modify_config ]]; then if ! [[ $silent ]] && ! [[ $no_modify_config ]]; then
if [ -e "$HOME/$BACKUP_FILE" ]; then if [ -e "$HOME/$BACKUP_FILE" ]; then
echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2 echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2
while ! [ $silent ]; do while ! [ $silent ]; do
read -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file ($HOME/$BACKUP_FILE) [y/N] " RESP read -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file ($HOME/$BACKUP_FILE) [y/N] " RESP
case $RESP in case $RESP in
[yY]) [yY])
break break
;; ;;
[nN]|"") [nN] | "")
echo -e "\033[91mInstallation aborted. Please come back soon!\033[m" echo -e "\033[91mInstallation aborted. Please come back soon!\033[m"
exit 1 exit 1
;; ;;
*) *)
echo -e "\033[91mPlease choose y or n.\033[m" echo -e "\033[91mPlease choose y or n.\033[m"
;; ;;
esac esac
done done
fi fi
while ! [ $append_to_config ]; do while ! [ $append_to_config ]; do
read -e -n 1 -r -p "Would you like to keep your $CONFIG_FILE and append bash-it templates at the end? [y/N] " choice read -e -n 1 -r -p "Would you like to keep your $CONFIG_FILE and append bash-it templates at the end? [y/N] " choice
case $choice in case $choice in
[yY]) [yY])
backup_append backup_append
break break
;; ;;
[nN]|"") [nN] | "")
backup_new backup_new
break break
;; ;;
*) *)
echo -e "\033[91mPlease choose y or n.\033[m" echo -e "\033[91mPlease choose y or n.\033[m"
;; ;;
esac esac
done done
elif [[ $append_to_config ]]; then elif [[ $append_to_config ]]; then
# backup/append # backup/append
backup_append backup_append
elif [[ $silent ]] && ! [[ $no_modify_config ]]; then elif [[ $silent ]] && ! [[ $no_modify_config ]]; then
# backup/new by default # backup/new by default
backup_new backup_new
fi fi
# Disable auto-reload in case its enabled # Disable auto-reload in case its enabled
export BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE='' export BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE=''
# Load dependencies for enabling components # Load dependencies for enabling components
source "$BASH_IT/lib/composure.bash" # shellcheck disable=SC1090
source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh
# shellcheck source=./lib/utilities.bash
source "$BASH_IT/lib/utilities.bash" source "$BASH_IT/lib/utilities.bash"
cite _about _param _example _group _author _version cite _about _param _example _group _author _version
# shellcheck source=./lib/helpers.bash
source "$BASH_IT/lib/helpers.bash" source "$BASH_IT/lib/helpers.bash"
if [[ $interactive ]] && ! [[ $silent ]] ; if [[ $interactive ]] && ! [[ $silent ]]; then
then for type in "aliases" "plugins" "completion"; do
for type in "aliases" "plugins" "completion" echo -e "\033[0;32mEnabling $type\033[0m"
do load_some $type
echo -e "\033[0;32mEnabling $type\033[0m" done
load_some $type
done
else else
echo "" echo ""
echo -e "\033[0;32mEnabling reasonable defaults\033[0m" echo -e "\033[0;32mEnabling reasonable defaults\033[0m"
_enable-completion bash-it _enable-completion bash-it
_enable-completion system _enable-completion system
_enable-plugin base _enable-plugin base
_enable-plugin alias-completion _enable-plugin alias-completion
_enable-alias general _enable-alias general
fi fi
echo "" echo ""
echo -e "\033[0;32mInstallation finished successfully! Enjoy bash-it!\033[0m" echo -e "\033[0;32mInstallation finished successfully! Enjoy bash-it!\033[0m"
# shellcheck disable=SC2086
echo -e "\033[0;32mTo start using it, open a new tab or 'source "$HOME/$CONFIG_FILE"'.\033[0m" echo -e "\033[0;32mTo start using it, open a new tab or 'source "$HOME/$CONFIG_FILE"'.\033[0m"
echo "" echo ""
echo "To show the available aliases/completions/plugins, type one of the following:" echo "To show the available aliases/completions/plugins, type one of the following:"

View File

@ -1,380 +0,0 @@
# composure - by erichs
# light-hearted functions for intuitive shell programming
# install: source this script in your ~/.profile or ~/.${SHELL}rc script
# latest source available at http://git.io/composure
# known to work on bash, zsh, and ksh93
# 'plumbing' functions
composure_keywords ()
{
echo "about author example group param version"
}
letterpress ()
{
typeset rightcol="$1" leftcol="${2:- }"
if [ -z "$rightcol" ]; then
return
fi
printf "%-20s%s\n" "$leftcol" "$rightcol"
}
transcribe ()
{
typeset func=$1
typeset file=$2
typeset operation="$3"
if git --version >/dev/null 2>&1; then
if [ -d ~/.composure ]; then
(
cd ~/.composure
if git rev-parse 2>/dev/null; then
if [ ! -f $file ]; then
printf "%s\n" "Oops! Couldn't find $file to version it for you..."
return
fi
cp $file ~/.composure/$func.inc
git add --all .
git commit -m "$operation $func"
fi
)
else
if [ "$USE_COMPOSURE_REPO" = "0" ]; then
return # if you say so...
fi
printf "%s\n" "I see you don't have a ~/.composure repo..."
typeset input
typeset valid=0
while [ $valid != 1 ]; do
printf "\n%s" 'would you like to create one? y/n: '
read input
case $input in
y|yes|Y|Yes|YES)
(
echo 'creating git repository for your functions...'
mkdir ~/.composure
cd ~/.composure
git init
echo "composure stores your function definitions here" > README.txt
git add README.txt
git commit -m 'initial commit'
)
# if at first you don't succeed...
transcribe "$func" "$file" "$operation"
valid=1
;;
n|no|N|No|NO)
printf "%s\n" "ok. add 'export USE_COMPOSURE_REPO=0' to your startup script to disable this message."
valid=1
;;
*)
printf "%s\n" "sorry, didn't get that..."
;;
esac
done
fi
fi
}
typeset_functions ()
{
# unfortunately, there does not seem to be a easy, portable way to list just the
# names of the defined shell functions...
# first, determine our shell:
typeset shell
if [ -n "$SHELL" ]; then
shell=$(basename $SHELL) # we assume this is set correctly!
else
# we'll have to try harder
# here's a hack I modified from a StackOverflow post:
# we loop over the ps listing for the current process ($$), and print the last column (CMD)
# stripping any leading hyphens bash sometimes throws in there
typeset x ans
typeset this=$(for x in $(ps -p $$); do ans=$x; done; printf "%s\n" $ans | sed 's/^-*//')
typeset shell=$(basename $this) # e.g. /bin/bash => bash
fi
case "$shell" in
bash)
typeset -F | awk '{print $3}'
;;
*)
# trim everything following '()' in ksh
typeset +f | sed 's/().*$//'
;;
esac
}
# bootstrap metadata keywords for porcelain functions
for f in $(composure_keywords)
do
eval "$f() { :; }"
done
unset f
# 'porcelain' functions
cite ()
{
about creates one or more meta keywords for use in your functions
param one or more keywords
example '$ cite url username'
example '$ url http://somewhere.com'
example '$ username alice'
group composure
# this is the storage half of the 'metadata' system:
# we create dynamic metadata keywords with function wrappers around
# the NOP command, ':'
# anything following a keyword will get parsed as a positional
# parameter, but stay resident in the ENV. As opposed to shell
# comments, '#', which do not get parsed and are not available
# at runtime.
# a BIG caveat--your metadata must be roughly parsable: do not use
# contractions, and consider single or double quoting if it contains
# non-alphanumeric characters
if [ -z "$1" ]; then
printf '%s\n' 'missing parameter(s)'
reference cite
return
fi
typeset keyword
for keyword in $*; do
eval "$keyword() { :; }"
done
}
draft ()
{
about wraps command from history into a new function, default is last command
param 1: name to give function
param 2: optional history line number
example '$ ls'
example '$ draft list'
example '$ draft newfunc 1120 # wraps command at history line 1120 in newfunc()'
group composure
typeset func=$1
typeset num=$2
typeset cmd
if [ -z "$func" ]; then
printf '%s\n' 'missing parameter(s)'
reference draft
return
fi
# aliases bind tighter than function names, disallow them
if [ -n "$(LANG=C type -t $func 2>/dev/null | grep 'alias')" ]; then
printf '%s\n' "sorry, $(type -a $func). please choose another name."
return
fi
if [ -z "$num" ]; then
# parse last command from fc output
# some versions of 'fix command, fc' need corrective lenses...
typeset myopic=$(fc -ln -1 | grep draft)
typeset lines=1
if [ -n "$myopic" ]; then
lines=2
fi
cmd=$(fc -ln -$lines | head -1 | sed 's/^[[:blank:]]*//')
else
# parse command from history line number
cmd=$(eval "history | grep '^[[:blank:]]*$num' | head -1" | sed 's/^[[:blank:][:digit:]]*//')
fi
eval "$func() { $cmd; }"
typeset file=$(mktemp -t draft.XXXX)
typeset -f $func > $file
transcribe $func $file draft
rm $file 2>/dev/null
}
glossary ()
{
about displays help summary for all functions, or summary for a group of functions
param 1: optional, group name
example '$ glossary'
example '$ glossary misc'
group composure
typeset targetgroup=${1:-}
for func in $(typeset_functions); do
if [ -n "$targetgroup" ]; then
typeset group="$(typeset -f $func | metafor group)"
if [ "$group" != "$targetgroup" ]; then
continue # skip non-matching groups, if specified
fi
fi
typeset about="$(typeset -f $func | metafor about)"
letterpress "$about" $func
done
}
metafor ()
{
about prints function metadata associated with keyword
param 1: meta keyword
example '$ typeset -f glossary | metafor example'
group composure
typeset keyword=$1
if [ -z "$keyword" ]; then
printf '%s\n' 'missing parameter(s)'
reference metafor
return
fi
# this sed-fu is the retrieval half of the 'metadata' system:
# 'grep' for the metadata keyword, and then parse/filter the matching line
# grep keyword # strip trailing '|"|; # ignore thru keyword and leading '|"
sed -n "/$keyword / s/['\";]*$//;s/^[ ]*$keyword ['\"]*\([^([].*\)*$/\1/p"
}
reference ()
{
about displays apidoc help for a specific function
param 1: function name
example '$ reference revise'
group composure
typeset func=$1
if [ -z "$func" ]; then
printf '%s\n' 'missing parameter(s)'
reference reference
return
fi
typeset line
typeset about="$(typeset -f $func | metafor about)"
letterpress "$about" $func
typeset author="$(typeset -f $func | metafor author)"
if [ -n "$author" ]; then
letterpress "$author" 'author:'
fi
typeset version="$(typeset -f $func | metafor version)"
if [ -n "$version" ]; then
letterpress "$version" 'version:'
fi
if [ -n "$(typeset -f $func | metafor param)" ]; then
printf "parameters:\n"
typeset -f $func | metafor param | while read line
do
letterpress "$line"
done
fi
if [ -n "$(typeset -f $func | metafor example)" ]; then
printf "examples:\n"
typeset -f $func | metafor example | while read line
do
letterpress "$line"
done
fi
}
revise ()
{
about loads function into editor for revision
param 1: name of function
example '$ revise myfunction'
group composure
typeset func=$1
typeset temp=$(mktemp -t revise.XXXX)
if [ -z "$func" ]; then
printf '%s\n' 'missing parameter(s)'
reference revise
return
fi
# populate tempfile...
if [ -f ~/.composure/$func.inc ]; then
# ...with contents of latest git revision...
cat ~/.composure/$func.inc >> $temp
else
# ...or from ENV if not previously versioned
typeset -f $func >> $temp
fi
if [ -z "$EDITOR" ]
then
typeset EDITOR=vi
fi
$EDITOR $temp
. $temp # source edited file
transcribe $func $temp revise
rm $temp
}
write ()
{
about writes one or more composed function definitions to stdout
param one or more function names
example '$ write finddown foo'
example '$ write finddown'
group composure
if [ -z "$1" ]; then
printf '%s\n' 'missing parameter(s)'
reference write
return
fi
# bootstrap metadata
cat <<END
for f in $(composure_keywords)
do
eval "\$f() { :; }"
done
unset f
END
# include cite() to enable custom keywords
typeset -f cite $*
}
: <<EOF
License: The MIT License
Copyright © 2012 Erich Smith
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
EOF

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../test_helper load ../test_helper
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
function local_setup { function local_setup {
setup_test_fixture setup_test_fixture

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../test_helper load ../test_helper
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../completion/available/bash-it.completion load ../../completion/available/bash-it.completion
function local_setup { function local_setup {

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../test_helper load ../test_helper
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
# Determine which config file to use based on OS. # Determine which config file to use based on OS.
case $OSTYPE in case $OSTYPE in

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../test_helper load ../test_helper
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
# Determine which config file to use based on OS. # Determine which config file to use based on OS.
case $OSTYPE in case $OSTYPE in

View File

@ -1,9 +1,9 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../test_helper load ../test_helper
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
@test "lib composure: composure_keywords()" { @test "lib composure: _composure_keywords()" {
run composure_keywords run _composure_keywords
assert_output "about author example group param version" assert_output "about author example group param version"
} }

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../test_helper load ../test_helper
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../lib/log load ../../lib/log
load ../../lib/utilities load ../../lib/utilities
load ../../lib/search load ../../lib/search

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../test_helper load ../test_helper
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../lib/appearance load ../../lib/appearance
load ../../plugins/available/base.plugin load ../../plugins/available/base.plugin

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../test_helper load ../test_helper
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../lib/log load ../../lib/log
load ../../lib/helpers load ../../lib/helpers
load ../../lib/utilities load ../../lib/utilities

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../test_helper load ../test_helper
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../lib/helpers load ../../lib/helpers
load ../../lib/utilities load ../../lib/utilities
load ../../lib/search load ../../lib/search

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../test_helper load ../test_helper
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../lib/log load ../../lib/log
load ../../lib/helpers load ../../lib/helpers

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../test_helper load ../test_helper
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../plugins/available/base.plugin load ../../plugins/available/base.plugin
@test 'plugins base: ips()' { @test 'plugins base: ips()' {

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../test_helper load ../test_helper
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
cite _about _param _example _group _author _version cite _about _param _example _group _author _version

View File

@ -2,7 +2,7 @@
load ../test_helper load ../test_helper
load ../../lib/helpers load ../../lib/helpers
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../plugins/available/cmd-returned-notify.plugin load ../../plugins/available/cmd-returned-notify.plugin

View File

@ -2,7 +2,7 @@
load ../test_helper load ../test_helper
load ../../lib/helpers load ../../lib/helpers
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
@test 'ensure _go_pathmunge_wrap is defined' { @test 'ensure _go_pathmunge_wrap is defined' {
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found' { [[ $CI ]] || _command_exists go; } || skip 'golang not found'

View File

@ -2,7 +2,7 @@
load ../test_helper load ../test_helper
load ../../lib/helpers load ../../lib/helpers
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../plugins/available/ruby.plugin load ../../plugins/available/ruby.plugin
function local_setup { function local_setup {

View File

@ -2,7 +2,7 @@
load ../test_helper load ../test_helper
load ../../lib/helpers load ../../lib/helpers
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../plugins/available/xterm.plugin load ../../plugins/available/xterm.plugin

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
unset BASH_IT_THEME unset BASH_IT_THEME
unset GIT_HOSTING unset GIT_HOSTING
@ -23,11 +23,11 @@ load "${TEST_DEPS_DIR}/bats-file/load.bash"
cite _about _param _example _group _author _version cite _about _param _example _group _author _version
local_setup() { local_setup() {
true true
} }
local_teardown() { local_teardown() {
true true
} }
# This function sets up a local test fixture, i.e. a completely # This function sets up a local test fixture, i.e. a completely
@ -35,71 +35,70 @@ local_teardown() {
# messing with your own Bash-it source directory. # messing with your own Bash-it source directory.
# If you need this, call it in your .bats file's `local_setup` function. # If you need this, call it in your .bats file's `local_setup` function.
setup_test_fixture() { setup_test_fixture() {
mkdir -p "$BASH_IT" mkdir -p "$BASH_IT"
lib_directory="$(cd "$(dirname "$0")" && pwd)" lib_directory="$(cd "$(dirname "$0")" && pwd)"
local src_topdir="$lib_directory/../../../.." local src_topdir="$lib_directory/../../../.."
if command -v rsync &> /dev/null if command -v rsync &> /dev/null; then
then # Use rsync to copy Bash-it to the temp folder
# Use rsync to copy Bash-it to the temp folder rsync -qavrKL -d --delete-excluded --exclude=.git --exclude=enabled "$src_topdir" "$BASH_IT"
rsync -qavrKL -d --delete-excluded --exclude=.git --exclude=enabled "$src_topdir" "$BASH_IT" else
else rm -rf "$BASH_IT"
rm -rf "$BASH_IT" mkdir -p "$BASH_IT"
mkdir -p "$BASH_IT"
find "$src_topdir" \ find "$src_topdir" \
-mindepth 1 -maxdepth 1 \ -mindepth 1 -maxdepth 1 \
-not -name .git \ -not -name .git \
-exec cp -r {} "$BASH_IT" \; -exec cp -r {} "$BASH_IT" \;
fi fi
rm -rf "$BASH_IT"/enabled rm -rf "$BASH_IT"/enabled
rm -rf "$BASH_IT"/aliases/enabled rm -rf "$BASH_IT"/aliases/enabled
rm -rf "$BASH_IT"/completion/enabled rm -rf "$BASH_IT"/completion/enabled
rm -rf "$BASH_IT"/plugins/enabled rm -rf "$BASH_IT"/plugins/enabled
mkdir -p "$BASH_IT"/enabled mkdir -p "$BASH_IT"/enabled
mkdir -p "$BASH_IT"/aliases/enabled mkdir -p "$BASH_IT"/aliases/enabled
mkdir -p "$BASH_IT"/completion/enabled mkdir -p "$BASH_IT"/completion/enabled
mkdir -p "$BASH_IT"/plugins/enabled mkdir -p "$BASH_IT"/plugins/enabled
# Some tests use the BASH_IT_TEST_HOME variable, e.g. install/uninstall # Some tests use the BASH_IT_TEST_HOME variable, e.g. install/uninstall
export BASH_IT_TEST_HOME="$TEST_TEMP_DIR" export BASH_IT_TEST_HOME="$TEST_TEMP_DIR"
} }
setup() { setup() {
# The `temp_make` function from "bats-file" requires the tralston/bats-file fork, # The `temp_make` function from "bats-file" requires the tralston/bats-file fork,
# since the original ztombol/bats-file's `temp_make` does not work on macOS. # since the original ztombol/bats-file's `temp_make` does not work on macOS.
TEST_TEMP_DIR="$(temp_make --prefix 'bash-it-test-')" TEST_TEMP_DIR="$(temp_make --prefix 'bash-it-test-')"
export TEST_TEMP_DIR export TEST_TEMP_DIR
export BASH_IT_TEST_DIR="${TEST_TEMP_DIR}/.bash_it" export BASH_IT_TEST_DIR="${TEST_TEMP_DIR}/.bash_it"
export BASH_IT_ROOT="${BASH_IT_TEST_DIR}/root" export BASH_IT_ROOT="${BASH_IT_TEST_DIR}/root"
export BASH_IT=$BASH_IT_TEST_DIR export BASH_IT=$BASH_IT_TEST_DIR
mkdir -p -- "${BASH_IT_ROOT}" mkdir -p -- "${BASH_IT_ROOT}"
# Some tools, e.g. `git` use configuration files from the $HOME directory, # Some tools, e.g. `git` use configuration files from the $HOME directory,
# which interferes with our tests. The only way to keep `git` from doing this # which interferes with our tests. The only way to keep `git` from doing this
# seems to set HOME explicitly to a separate location. # seems to set HOME explicitly to a separate location.
# Refer to https://git-scm.com/docs/git-config#FILES. # Refer to https://git-scm.com/docs/git-config#FILES.
unset XDG_CONFIG_HOME unset XDG_CONFIG_HOME
export HOME="${TEST_TEMP_DIR}" export HOME="${TEST_TEMP_DIR}"
mkdir -p "${HOME}" mkdir -p "${HOME}"
# For `git` tests to run well, user name and email need to be set. # For `git` tests to run well, user name and email need to be set.
# Refer to https://git-scm.com/docs/git-commit#_commit_information. # Refer to https://git-scm.com/docs/git-commit#_commit_information.
# This goes to the test-specific config, due to the $HOME overridden above. # This goes to the test-specific config, due to the $HOME overridden above.
git config --global user.name "John Doe" git config --global user.name "John Doe"
git config --global user.email "johndoe@example.com" git config --global user.email "johndoe@example.com"
local_setup local_setup
} }
teardown() { teardown() {
local_teardown local_teardown
rm -rf "${BASH_IT_TEST_DIR}" rm -rf "${BASH_IT_TEST_DIR}"
temp_del "${TEST_TEMP_DIR}" temp_del "${TEST_TEMP_DIR}"
} }

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../test_helper load ../test_helper
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../lib/log load ../../lib/log
cite _about _param _example _group _author _version cite _about _param _example _group _author _version

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../test_helper load ../test_helper
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../lib/log load ../../lib/log
cite _about _param _example _group _author _version cite _about _param _example _group _author _version

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load ../test_helper load ../test_helper
load ../../lib/composure load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../lib/log load ../../lib/log
cite _about _param _example _group _author _version cite _about _param _example _group _author _version

2
vendor/.gitattributes vendored 100644
View File

@ -0,0 +1,2 @@
* -whitespace
init.d/*.bash text eol=lf