2023-01-12 10:50:06 -08:00
|
|
|
{{- if (ne .host.distro.family "windows") -}}
|
2023-07-17 13:40:40 -07:00
|
|
|
#!/usr/bin/env -S bash -i
|
2023-04-11 20:57:02 -07:00
|
|
|
# @file Bash It!
|
|
|
|
# @brief Ensures Bash is configured to use Bash It!
|
|
|
|
# @description
|
|
|
|
# This script ensures Bash is configured to use Bash It! It ensures dependencies are installed, installs completions,
|
|
|
|
# and enables Bash It! plugins. The completions and plugins are hardcoded in this script.
|
2023-01-12 10:50:06 -08:00
|
|
|
|
|
|
|
{{ includeTemplate "universal/profile" }}
|
|
|
|
{{ includeTemplate "universal/logg" }}
|
|
|
|
|
2023-01-12 11:13:58 -08:00
|
|
|
### Ensure Powerline is installed
|
|
|
|
if ! command -v powerline > /dev/null; then
|
2023-08-30 12:58:51 -07:00
|
|
|
logg info 'Installing powerline via install-program'
|
|
|
|
install-program powerline > /dev/null
|
2023-01-12 11:13:58 -08:00
|
|
|
fi
|
|
|
|
|
2023-07-17 10:41:49 -07:00
|
|
|
### Include Bash It
|
|
|
|
export BASH_IT="${XDG_DATA_HOME:-$HOME/.local/share}/bash_it"
|
|
|
|
export BASH_IT_THEME="powerline"
|
2023-08-07 21:06:52 -07:00
|
|
|
if command -v powerline-daemon > /dev/null && [ -f "$BASH_IT/bash_it.sh" ] && ! command -v bash-it; then
|
|
|
|
logg info "Sourcing the bash_it.sh script"
|
2023-07-17 10:41:49 -07:00
|
|
|
. "$BASH_IT/bash_it.sh"
|
|
|
|
fi
|
|
|
|
|
2023-07-14 22:28:48 -07:00
|
|
|
### Ensure ble.sh installed
|
2023-08-03 23:17:37 -07:00
|
|
|
if [ -d "${XDG_DATA_HOME:-$HOME/.local/share}/blesh/src" ]; then
|
2023-08-03 23:18:00 -07:00
|
|
|
logg info 'Make installing blesh'
|
2023-11-29 22:13:23 -08:00
|
|
|
make -C "${XDG_DATA_HOME:-$HOME/.local/share}/blesh/src" install > /dev/null && logg success "Installed ble.sh" || logg error "Error running make -C "${XDG_DATA_HOME:-$HOME/.local/share}/blesh/src" install"
|
2023-07-14 22:28:48 -07:00
|
|
|
fi
|
|
|
|
|
2023-01-12 10:50:06 -08:00
|
|
|
### Bash-it completions / plugins
|
2023-01-12 15:59:23 -08:00
|
|
|
if command -v powerline > /dev/null && [ -f "$HOME/.bashrc" ]; then
|
2023-07-10 23:18:04 -07:00
|
|
|
# These three lines are probably not needed:
|
2023-11-04 18:46:18 -07:00
|
|
|
# logg info 'Running source ~/.bashrc'
|
2023-07-10 23:18:04 -07:00
|
|
|
# source ~/.bashrc
|
2023-11-04 18:46:18 -07:00
|
|
|
# logg success 'Imported the ~/.bashrc profile'
|
2023-07-11 21:32:13 -07:00
|
|
|
if [ -d "$BASH_IT" ]; then
|
|
|
|
### Ensure bash-it is installed
|
|
|
|
if ! command -v bash-it > /dev/null; then
|
2023-11-04 18:46:18 -07:00
|
|
|
logg info 'Installing bash-it since it is not available yet as a command'
|
2023-07-11 21:32:13 -07:00
|
|
|
bash "$BASH_IT/install.sh" --silent --no-modify-config
|
2023-07-14 22:28:48 -07:00
|
|
|
else
|
2023-11-04 18:46:18 -07:00
|
|
|
logg info 'bash-it already available'
|
2023-01-12 11:13:58 -08:00
|
|
|
fi
|
2023-07-11 21:32:13 -07:00
|
|
|
|
|
|
|
### Ensure completions are enabled
|
2023-11-26 21:40:58 -08:00
|
|
|
if [ ! -d "$BASH_IT/enabled" ]; then
|
|
|
|
logg info "Creating the $BASH_IT/enabled directory" && mkdir -p "$BASH_IT/enabled"
|
2023-11-04 22:33:23 -07:00
|
|
|
fi
|
2023-11-26 21:40:58 -08:00
|
|
|
logg info "Changing directory to $BASH_IT/enabled" && cd "$BASH_IT/enabled"
|
2023-07-11 21:32:13 -07:00
|
|
|
logg info 'Enabling bash-it completions'
|
|
|
|
# TODO: Move these plugins to the .chezmoidata.yaml
|
2023-08-08 00:06:49 -07:00
|
|
|
for COMPLETION in defaults dirs docker docker-compose export git makefile ng ssh system vagrant; do
|
2023-07-14 22:28:48 -07:00
|
|
|
if ls "$BASH_IT/enabled" | grep "$COMPLETION" > /dev/null; then
|
|
|
|
rm -f "$BASH_IT/enabled/"*"$COMPLETION"* > /dev/null && logg info "Removed old $COMPLETION bash-it completion symlink" || logg error "Failed to remove $COMPLETION bash-it completion symlink"
|
2023-07-11 21:32:13 -07:00
|
|
|
fi
|
2023-08-08 22:46:26 -07:00
|
|
|
yes | bash-it enable completion "$COMPLETION" > /dev/null && logg info "Enabled the bash-it $COMPLETION completion plugin" || logg error "Failed to install the $COMPLETION bash-it completion plugin"
|
2023-07-11 21:32:13 -07:00
|
|
|
done
|
|
|
|
|
|
|
|
### Ensure plugins are enabled
|
|
|
|
logg info 'Enabling bash-it plugins'
|
|
|
|
# TODO: Move these plugins to the .chezmoidata.yaml
|
2023-07-17 15:06:36 -07:00
|
|
|
for PLUGIN in base blesh browser cht-sh dirs gitstatus powerline sudo xterm; do
|
2023-07-11 21:32:13 -07:00
|
|
|
if ls "$BASH_IT/enabled" | grep "$PLUGIN" > /dev/null; then
|
2023-07-14 22:28:48 -07:00
|
|
|
rm -f "$BASH_IT/enabled/"*"$PLUGIN"* > /dev/null && logg info "Removed old $PLUGIN bash-it plugin symlink" || logg error "Failed to remove $PLUGIN bash-it plugin symlink"
|
2023-07-11 21:32:13 -07:00
|
|
|
fi
|
2023-08-08 22:46:26 -07:00
|
|
|
yes | bash-it enable plugin "$PLUGIN" > /dev/null && logg info "Enabled the bash-it $PLUGIN plugin" || logg error "Failed to install the $PLUGIN bash-it plugin"
|
2023-07-11 21:32:13 -07:00
|
|
|
done
|
2023-01-12 11:13:58 -08:00
|
|
|
else
|
2023-07-11 21:32:13 -07:00
|
|
|
logg warn 'The path specified by BASH_IT does not exist yet'
|
2023-01-12 11:13:58 -08:00
|
|
|
fi
|
|
|
|
else
|
2023-01-12 15:59:23 -08:00
|
|
|
if ! command -v powerline > /dev/null; then
|
2023-11-04 18:46:18 -07:00
|
|
|
logg warn 'powerline is not available'
|
2023-01-12 15:59:23 -08:00
|
|
|
else
|
2023-11-04 18:46:18 -07:00
|
|
|
logg warn '~/.bashrc is missing'
|
2023-01-12 15:59:23 -08:00
|
|
|
fi
|
2023-01-12 10:50:06 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
{{ end -}}
|