install.fairie/home/.chezmoiscripts/universal/run_onchange_after_94-bash-it.sh.tmpl
2023-08-08 03:06:49 -04:00

78 lines
3.5 KiB
Cheetah

{{- if (ne .host.distro.family "windows") -}}
#!/usr/bin/env -S bash -i
# @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.
{{ includeTemplate "universal/profile" }}
{{ includeTemplate "universal/logg" }}
### Ensure Powerline is installed
if ! command -v powerline > /dev/null; then
logg info 'Installing powerline via install-software'
install-software powerline > /dev/null
fi
### Include Bash It
export BASH_IT="${XDG_DATA_HOME:-$HOME/.local/share}/bash_it"
export BASH_IT_THEME="powerline"
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"
. "$BASH_IT/bash_it.sh"
fi
### Ensure ble.sh installed
if [ -d "${XDG_DATA_HOME:-$HOME/.local/share}/blesh/src" ]; then
logg info 'Make installing blesh'
make -C "${XDG_DATA_HOME:-$HOME/.local/share}/blesh/src" install > /dev/null && logg success "Installed ble.sh"
fi
### Bash-it completions / plugins
if command -v powerline > /dev/null && [ -f "$HOME/.bashrc" ]; then
# These three lines are probably not needed:
# logg info 'Running `source ~/.bashrc`'
# source ~/.bashrc
# logg success 'Imported the `~/.bashrc` profile'
if [ -d "$BASH_IT" ]; then
### Ensure bash-it is installed
if ! command -v bash-it > /dev/null; then
logg info 'Installing `bash-it` since it is not available yet as a command'
bash "$BASH_IT/install.sh" --silent --no-modify-config
else
logg info '`bash-it` already available'
fi
### Ensure completions are enabled
cd "$BASH_IT/enabled"
logg info 'Enabling bash-it completions'
# TODO: Move these plugins to the .chezmoidata.yaml
for COMPLETION in defaults dirs docker docker-compose export git makefile ng ssh system vagrant; do
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"
fi
echo y | 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"
done
### Ensure plugins are enabled
logg info 'Enabling bash-it plugins'
# TODO: Move these plugins to the .chezmoidata.yaml
for PLUGIN in base blesh browser cht-sh dirs gitstatus powerline sudo xterm; do
if ls "$BASH_IT/enabled" | grep "$PLUGIN" > /dev/null; then
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"
fi
echo y | 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"
done
else
logg warn 'The path specified by BASH_IT does not exist yet'
fi
else
if ! command -v powerline > /dev/null; then
logg warn '`powerline` is not available'
else
logg warn '`~/.bashrc` is missing'
fi
fi
{{ end -}}