Skip to content
Merged
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
3 changes: 3 additions & 0 deletions system_files/bluefin/usr/share/ublue-os/bling/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh
export BLING_MESSAGE_ENABLE="Enable the bluefin-cli enhanced terminal experience?"
export BLING_MESSAGE_DISABLE="Disable the bluefin-cli enhanced terminal experience?"
2 changes: 1 addition & 1 deletion system_files/bluefin/usr/share/ublue-os/just/system.just
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Configure Bluefin-CLI Terminal Experience with Brew
[group('System')]
bluefin-cli:
@/usr/bin/ublue-bling
@ublue-bling

# alias for toggle-devmode
devmode:
Expand Down
261 changes: 42 additions & 219 deletions system_files/shared/usr/bin/ublue-bling
Original file line number Diff line number Diff line change
Expand Up @@ -2,234 +2,57 @@

set -eou pipefail

# coloring / ugum chooser
source /usr/lib/ujust/ujust.sh

get_config() {
MOTD_CONFIG_FILE="${MOTD_CONFIG_FILE:-/etc/ublue-os/bling.json}"
QUERY="$1"
FALLBACK="$2"
shift
shift
OUTPUT="$(jq -r "$QUERY" "$MOTD_CONFIG_FILE" 2>/dev/null || echo "$FALLBACK")"
if [ "$OUTPUT" == "null" ] ; then
echo "$FALLBACK"
return
fi
echo "$OUTPUT"
}


# Exit Handling
function Exiting() {
printf "%s%sExiting...%s\n" "${red}" "${bold}" "${normal}"
printf "Rerun script with %s%sujust $BLING_CLI_NAME%s\n" "${blue}" "${bold}" "${normal}"
exit 0
}

# Trap function
function ctrl_c() {
printf "\n%s\n" "Signal SIGINT caught"
Exiting
}

# Brew Bundle Install
function brew-bundle() {
echo 'Installing bling from Homebrew 🍻🍻🍻'
brew bundle --file "$BLING_BREW_BUNDLE_PATH"
}

# Pixi Install Global
function pixi-install-global() {
echo 'Installing bling with pixi (global install) 🐍🐍🐍'

if [ ! -f "$BLING_PIXI_PACKAGES_FILE" ]; then
echo "Error: Pixi packages file not found at $BLING_PIXI_PACKAGES_FILE"
BLING_CLI_DIRECTORY="/usr/share/ublue-os/bling"

BLING_SCRIPT_SOURCE=""
TARGET_CONFIG_FILE=""
shell="$(basename "${SHELL}")"
case "${shell}" in
"fish")
BLING_SCRIPT_SOURCE="bling.fish"
TARGET_CONFIG_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/fish/config.fish"
;;
"zsh")
BLING_SCRIPT_SOURCE="bling.sh"
TARGET_CONFIG_FILE="${ZDOTDIR:-$HOME}/.zshrc"
;;
"bash")
BLING_SCRIPT_SOURCE="bling.sh"
TARGET_CONFIG_FILE="${HOME}/.bashrc"
;;
*)
echo 'Unknown shell. You are on your own.'
exit 1
fi

packages="$(cat "$BLING_PIXI_PACKAGES_FILE" | grep -v '^#' | grep -v '^$' | tr '\n' ' ')"

if [ -z "$packages" ]; then
echo "Error: No packages found in $BLING_PIXI_PACKAGES_FILE"
exit 1
fi

pixi global install $packages
}
;;
esac

# Check if bling is already sourced
# 0 for yes
# 1 for no
function is-bling-installed() {
shell="$1"
shift

line=""
BLING_SCRIPT_SOURCE="bling.sh"
TARGET_CONFIG_FILE="${HOME}/.bashrc"
case "${shell}" in
"fish")
BLING_SCRIPT_SOURCE="bling.fish"
TARGET_CONFIG_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/fish/config.fish"
;;
"zsh")
BLING_SCRIPT_SOURCE="bling.sh"
TARGET_CONFIG_FILE="${ZDOTDIR:-$HOME}/.zshrc"
;;
"bash")
BLING_SCRIPT_SOURCE="bling.sh"
TARGET_CONFIG_FILE="${HOME}/.bashrc"
;;
*)
echo 'Unknown shell. You are on your own.'
exit 1
;;
esac
# Prevents grep erroring out when theres no config file for the shell
touch "$TARGET_CONFIG_FILE"
line="$(grep -n "source $BLING_CLI_DIRECTORY/$BLING_SCRIPT_SOURCE" "$TARGET_CONFIG_FILE")"
line="$(grep -Eo '^[^:]+' <<< "$line")"
[ -f "$TARGET_CONFIG_FILE" ] || return 1

if [[ -n "${line}" ]]; then
if [ -n "$(grep -n "source $BLING_CLI_DIRECTORY/$BLING_SCRIPT_SOURCE" "$TARGET_CONFIG_FILE" | grep -Eo '^[^:]+')" ]; then
return 0
fi
return 1
}

# Add Bling
function add-bling() {
shell="$1"
shift

if [[ "${BLING_USE_PIXI}" == "1" ]]; then
pixi-install-global || Exiting
else
brew-bundle || Exiting
fi

echo 'Setting up your Shell 🐚🐚🐚'
case "${shell}" in
"fish")
echo 'Adding bling to your config.fish 🐟🐟🐟'
cat<<EOF >> "${XDG_CONFIG_HOME:-$HOME/.config}/fish/config.fish"
### bling.fish source start
test -f $BLING_CLI_DIRECTORY/bling.fish && source $BLING_CLI_DIRECTORY/bling.fish
### bling.fish source end
EOF
;;
"zsh")
echo 'Adding bling to your .zshrc 💤💤💤'
cat<<EOF >> "${ZDOTDIR:-$HOME}/.zshrc"
### bling.sh source start
test -f $BLING_CLI_DIRECTORY/bling.sh && source $BLING_CLI_DIRECTORY/bling.sh
### bling.sh source end
EOF
;;
"bash")
echo 'Adding bling to your .bashrc 💥💥💥'
cat<<EOF >> "${HOME}/.bashrc"
### bling.sh source start
test -f $BLING_CLI_DIRECTORY/bling.sh && source $BLING_CLI_DIRECTORY/bling.sh
### bling.sh source end
EOF
;;
*)
echo 'Unknown shell. You are on your own.'
exit 1
;;
esac
}
[ -f "${BLING_ENV_SCRIPT:-/usr/share/ublue-os/bling/env.sh}" ] && . "${BLING_ENV_SCRIPT:-/usr/share/ublue-os/bling/env.sh}"

# Remove bling, handle if old method
function remove-bling() {
shell="$1"
shift
BLING_MESSAGE_ENABLE="${BLING_MESSAGE_ENABLE:-Enable bling for ${shell}?}"
BLING_MESSAGE_DISABLE="${BLING_MESSAGE_DISABLE:-Disable bling for ${shell}?}"

case "${shell}" in
"fish")
sed -i '/### bling.fish source start/,/### bling.fish source end/d' \
"${XDG_CONFIG_HOME:-$HOME/.config}/fish/config.fish" \
|| \
line=$(grep -n "source $BLING_CLI_DIRECTORY/bling.fish" \
"${XDG_CONFIG_HOME:-$HOME/.config}/fish/config.fish" \
| grep -Eo '^[^:]+') \
&& \
sed -i "${line}"d "${XDG_CONFIG_HOME:-$HOME/.config}/fish/config.fish"
;;
"zsh")
sed -i '/### bling.sh source start/,/### bling.sh source end/d' \
"${ZDOTDIR:-$HOME}/.zshrc" \
|| \
line=$(grep -n "source $BLING_CLI_DIRECTORY/bling.sh" \
"${ZDOTDIR:-$HOME}/.zshrc" \
| grep -Eo '^[^:]+') && sed -i "${line}"d \
"${ZDOTDIR:-$HOME}/.zshrc"
;;
"bash")
sed -i '/### bling.sh source start/,/### bling.sh source end/d' \
"${HOME}/.bashrc" \
|| \
line=$(grep -n "source $BLING_CLI_DIRECTORY/bling.sh" \
"${HOME}/.bashrc" \
| grep -Eo '^[^:]+') && sed -i "${line}"d \
"${HOME}/.bashrc"
;;
esac
}

function main() {
# Get Shell
shell=$(basename "$SHELL")
reentry="$1"
clear
if [[ -n "${reentry:-}" ]]; then
printf "%s%s%s\n\n" "${bold}" "$reentry" "$normal"
if is-bling-installed "${shell}" ; then
gum confirm "${BLING_MESSAGE_DISABLE}"
if ! sed -i "/### ${BLING_SCRIPT_SOURCE} source start/,/### ${BLING_SCRIPT_SOURCE} source end/d" "${TARGET_CONFIG_FILE}" ; then
sed -i "$(grep -n "source ${BLING_SCRIPT_SOURCE}" "${TARGET_CONFIG_FILE}" | grep -Eo '^[^:]+')"d "${HOME}/.bashrc"
fi

# Check if bling is enabled and display
printf "Shell:\t%s%s%s%s\n" "${green}" "${bold}" "${shell}" "${normal}"
if is-bling-installed "${shell}"; then
printf "Bling:\t%s%sEnabled%s\n" "${green}" "${bold}" "${normal}"
else
printf "Bling:\t%s%sDisabled%s\n" "${red}" "${bold}" "${normal}"
fi

# ugum enable/disable
CHOICE=$(Choose enable disable cancel)

# Enable/Disable. Recurse if bad option.
case "${CHOICE,,}" in
"enable")
if is-bling-installed "${shell}"; then
main "Bling is already configured ..."
fi
trap ctrl_c SIGINT
add-bling "${shell}"
printf "%s%sInstallation Complete%s ... please close and reopen your terminal!" "${green}" "${bold}" "${normal}"
printf "Check out the documentation at: https://docs.projectbluefin.io/command-line\n"
exit 0
;;
"disable")
if ! is-bling-installed "${shell}"; then
main "Bling is not yet configured ..."
fi
trap ctrl_c SIGINT
remove-bling "${shell}"
printf "%s%sBling Removed%s ... please close and reopen your terminal\n" "${red}" "${bold}" "${normal}"
exit 0
;;
*)
Exiting
;;
esac
}

BLING_CLI_NAME="$(get_config '."bling-cli-name"' "bluefin-cli")"
BLING_CLI_DIRECTORY="$(get_config '."bling-cli-path"' "/usr/share/ublue-os/bling")"
BLING_BREW_BUNDLE_PATH="$(get_config '."bling-brew-bundle-path"' "/usr/share/ublue-os/homebrew/$BLING_CLI_NAME.Brewfile")"
BLING_PIXI_PACKAGES_FILE="$(get_config '."bling-pixi-package-path"' "/usr/share/ublue-os/bling/${BLING_CLI_NAME}.pixi.list")"
BLING_USE_PIXI="$(get_config '."use-pixi-bling"' "0")"

# Entrypoint
main ""
echo "Bling removed. Reopen your terminal so that the configurations may be removed"
else
gum confirm "${BLING_MESSAGE_ENABLE}" --affirmative="Bling me up!" --negative "No, I'm boring"
echo "Adding bling to your $(basename "${TARGET_CONFIG_FILE}")"
cat<<EOF >> "${TARGET_CONFIG_FILE}"
### ${BLING_SCRIPT_SOURCE} source start
test -f ${BLING_CLI_DIRECTORY}/${BLING_SCRIPT_SOURCE} && source ${BLING_CLI_DIRECTORY}/${BLING_SCRIPT_SOURCE}
### ${BLING_SCRIPT_SOURCE} source end
EOF
echo "Installation complete. Reopen your terminal so that the configurations may be applied"
fi
34 changes: 15 additions & 19 deletions system_files/shared/usr/share/ublue-os/bling/bling.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env sh

# KEEP THIS POSIX - Needs to work on Bash and ZSH

# Check if bling has already been sourced so that we dont break atuin. https://github.com/atuinsh/atuin/issues/380#issuecomment-1594014644
[ "${BLING_SOURCED:-0}" -eq 1 ] && return
BLING_SOURCED=1
Expand All @@ -25,30 +27,24 @@ fi
# bat for cat
alias cat='bat --style=plain --pager=never' 2>/dev/null

HOMEBREW_PREFIX="${HOMEBREW_PREFIX:-/home/linuxbrew/.linuxbrew}"

# set ATUIN_INIT_FLAGS in your ~/.bashrc before ublue-bling is sourced.
# Atuin allows these flags: "--disable-up-arrow" and/or "--disable-ctrl-r"
ATUIN_INIT_FLAGS=${ATUIN_INIT_FLAGS:-""}
ATUIN_INIT_FLAGS="${ATUIN_INIT_FLAGS:-}"

if [ "$(basename $(readlink /proc/$$/exe))" = "bash" ]; then
# Initialize direnv before bash-preexec to avoid PROMPT_COMMAND conflicts
# See: https://github.com/rcaloras/bash-preexec/pull/143
[ "$(command -v direnv)" ] && eval "$(direnv hook bash)"
BLING_SHELL="$(basename "$(readlink /proc/$$/exe)")"

# Initialize direnv before bash-preexec to avoid PROMPT_COMMAND conflicts
# See: https://github.com/rcaloras/bash-preexec/pull/143
if [ "${BLING_SHELL}" = "bash" ]; then
[ -f "/etc/profile.d/bash-preexec.sh" ] && . "/etc/profile.d/bash-preexec.sh"
[ -f "/usr/share/bash-prexec" ] && . "/usr/share/bash-prexec"
[ -f "/usr/share/bash-prexec.sh" ] && . "/usr/share/bash-prexec.sh"
[ -f "${HOMEBREW_PREFIX}/etc/profile.d/bash-preexec.sh" ] && . "${HOMEBREW_PREFIX}/etc/profile.d/bash-preexec.sh"
# Initialize atuin before starship to ensure proper command history capture
# See: https://github.com/atuinsh/atuin/issues/2804
[ "$(command -v atuin)" ] && eval "$(atuin init bash ${ATUIN_INIT_FLAGS})"
[ "$(command -v starship)" ] && eval "$(starship init bash)"
[ "$(command -v zoxide)" ] && eval "$(zoxide init bash)"
elif [ "$(basename $(readlink /proc/$$/exe))" = "zsh" ]; then
# Initialize direnv before atuin to avoid PROMPT_COMMAND conflicts
[ "$(command -v direnv)" ] && eval "$(direnv hook zsh)"
# Initialize atuin before starship to ensure proper command history capture
[ "$(command -v atuin)" ] && eval "$(atuin init zsh ${ATUIN_INIT_FLAGS})"
[ "$(command -v starship)" ] && eval "$(starship init zsh)"
[ "$(command -v zoxide)" ] && eval "$(zoxide init zsh)"
fi

[ "$(command -v direnv)" ] && eval "$(direnv hook "${BLING_SHELL}")"
# Initialize atuin before starship to ensure proper command history capture
# See: https://github.com/atuinsh/atuin/issues/2804
[ "$(command -v atuin)" ] && eval "$(atuin init "${BLING_SHELL}" ${ATUIN_INIT_FLAGS})"
[ "$(command -v starship)" ] && eval "$(starship init "${BLING_SHELL}")"
[ "$(command -v zoxide)" ] && eval "$(zoxide init "${BLING_SHELL}")"
6 changes: 1 addition & 5 deletions system_files/shared/usr/share/ublue-os/homebrew/cli.Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ brew "dysk"
brew "eza"
brew "fd"
brew "gh"
brew "glab"
brew "rg"
brew "ripgrep"
brew "starship"
brew "shellcheck"
brew "stress-ng"
brew "tealdeer"
brew "trash-cli"
brew "television"
brew "uutils-coreutils"
brew "ugrep"
brew "yq"
Expand Down