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-06-14 00:22:59 -07:00
logg info 'Installing powerline via install-software'
install-software 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"
if command -v powerline-daemon > /dev/null && [ -f " $ BASH_IT /bash_it.sh" ]; then
. " $ BASH_IT /bash_it.sh"
fi
2023-07-14 22:28:48 -07:00
### Ensure ble.sh installed
2023-08-02 12:03:05 -07:00
if [ -d " ${ XDG_DATA_HOME : - $ HOME / . local / share } /blesh/src" ] && [ ! ]; then
logg info " ${ XDG_DATA_HOME : - $ HOME / . local / share } /ble.sh/src present and ${ XDG_DATA_HOME : - $ HOME / . local / share } /blesh/src not present - installing ble.sh..."
make -C " ${ XDG_DATA_HOME : - $ HOME / . local / share } /ble.sh/src" install > /dev/null && logg success "Installed ble.sh"
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:
# logg info 'Running `source ~/.bashrc`'
# source ~/.bashrc
# 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
logg info 'Installing `bash-it` since it is not available yet as a command'
bash " $ BASH_IT /install.sh" --silent --no-modify-config
2023-07-14 22:28:48 -07:00
else
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
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 npm 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-07-14 22:28:48 -07:00
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"
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-07-14 22:28:48 -07:00
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"
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
2023-07-17 15:06:36 -07:00
exit 0
2023-01-12 11:13:58 -08:00
else
2023-01-12 15:59:23 -08:00
if ! command -v powerline > /dev/null; then
logg warn '`powerline` is not available'
else
logg warn '`~/.bashrc` is missing'
fi
2023-01-12 10:50:06 -08:00
fi
{{ end -}}