From 74e0e87568b6dcc65cd3e2d73d908dbd6d330053 Mon Sep 17 00:00:00 2001 From: m2Giles <69128853+m2Giles@users.noreply.github.com> Date: Wed, 7 Feb 2024 14:41:46 -0500 Subject: [PATCH] feat: enable fish integration --- .../profile.d/00-bluefin-cli-brew-firstrun.sh | 25 ++++++----- .../files/etc/profile.d/bash_completion.sh | 2 +- .../profile.d/command-not-found-host-exec.sh | 1 + .../files/etc/profile.d/modern-unix.sh | 1 + .../files/etc/profile.d/zz-profile_sourced.sh | 1 + .../00-bluefin-cli-brew-firstrun.fish | 45 +++++++++++++++++++ .../usr/share/fish/vendor_conf.d/bling.fish | 26 +++++++++++ .../usr/share/fish/vendor_conf.d/brew.fish | 6 +++ .../fish_command_not_found.fish | 8 ++++ 9 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 toolboxes/bluefin-cli/files/usr/share/fish/vendor_conf.d/00-bluefin-cli-brew-firstrun.fish create mode 100644 toolboxes/bluefin-cli/files/usr/share/fish/vendor_conf.d/bling.fish create mode 100644 toolboxes/bluefin-cli/files/usr/share/fish/vendor_conf.d/brew.fish create mode 100644 toolboxes/bluefin-cli/files/usr/share/fish/vendor_functions.d/fish_command_not_found.fish diff --git a/toolboxes/bluefin-cli/files/etc/profile.d/00-bluefin-cli-brew-firstrun.sh b/toolboxes/bluefin-cli/files/etc/profile.d/00-bluefin-cli-brew-firstrun.sh index 3d7fb9f..1f99684 100644 --- a/toolboxes/bluefin-cli/files/etc/profile.d/00-bluefin-cli-brew-firstrun.sh +++ b/toolboxes/bluefin-cli/files/etc/profile.d/00-bluefin-cli-brew-firstrun.sh @@ -1,20 +1,21 @@ +# shellcheck shell=sh disable=SC1091 if test "$(id -u)" -gt "0"; then - green=$'\033[32m' - bold=$'\033[1m' - normal=$'\033[0m' + blue=$(printf '\033[38;5;32m') + bold=$(printf '\033[1m') + normal=$(printf '\033[0m') HOMEBREW_REPOSITORY=/home/linuxbrew/.linuxbrew export HOMEBREW_REPOSITORY + HOMEBREW_NO_AUTO_UPDATE=0 + export HOMEBREW_NO_AUTO_UPDATE if test ! -f /etc/linuxbrew.firstrun; then printf "\nBluefin-CLI First Run Setup\n\n" - printf "Setting up sudo for %s%s%s...\t\t\t " "${bold}" "${USER}" "${normal}" - echo "#${UID} ALL = (root) NOPASSWD:ALL" | su-exec root tee -a /etc/sudoers > /dev/null - printf "%s[ OK ]%s\n" "${green}" "${normal}" + printf "Setting up sudo for %s%s%s%s...\t\t\t " "$bold" "$blue" "$USER" "$normal" + echo "#$(id -u) ALL = (root) NOPASSWD:ALL" | su-exec root tee -a /etc/sudoers > /dev/null + printf "%s[ OK ]%s\n" "${blue}" "${normal}" fi if test ! -d /home/linuxbrew/.linuxbrew; then - name="" - test -f /run/.containerenv && . /run/.containerenv - test -f /run/.dockerenv && . /run/.dockerenv + name="$(hostname -s)" linuxbrew_home="${XDG_DATA_HOME:-$HOME/.local/share}"/bluefin-cli/"${name}" printf "Setting up Linuxbrew...\t\t\t\t " if test ! -d "${linuxbrew_home}"; then @@ -28,9 +29,9 @@ if test "$(id -u)" -gt "0"; then fi su-exec root mount --bind "${linuxbrew_home}" /home/linuxbrew su-exec root cp -R /home/homebrew/.linuxbrew /home/linuxbrew/ - su-exec root chown -R $UID /home/linuxbrew + su-exec root chown -R "$(id -u)" /home/linuxbrew unset linuxbrew_home - printf "%s[ OK ]%s\n" "${green}" "${normal}" + printf "%s[ OK ]%s\n" "${blue}" "${normal}" fi if test ! -d /usr/local/share/bash-completion/completions; then @@ -40,7 +41,7 @@ if test "$(id -u)" -gt "0"; then if test -x /run/host/usr/bin/ujust; then su-exec root ln -fs /usr/bin/distrobox-host-exec /usr/local/bin/ujust fi - printf "%s[ OK ]%s\n" "${green}" "${normal}" + printf "%s[ OK ]%s\n" "${blue}" "${normal}" fi if test ! -f /etc/linuxbrew.firstrun; then diff --git a/toolboxes/bluefin-cli/files/etc/profile.d/bash_completion.sh b/toolboxes/bluefin-cli/files/etc/profile.d/bash_completion.sh index caaf563..f1fa970 100644 --- a/toolboxes/bluefin-cli/files/etc/profile.d/bash_completion.sh +++ b/toolboxes/bluefin-cli/files/etc/profile.d/bash_completion.sh @@ -15,7 +15,7 @@ if [ "x${BASH_VERSION-}" != x -a "x${PS1-}" != x -a "x${BASH_COMPLETION_VERSINFO # Source completion code. . /usr/local/share/bash-completion/bash_completion fi - if ! test -L /home/linuxbrew/.linuxbrew/etc/bash_completion.d/brew; then + if ! test -L /home/linuxbrew/.linuxbrew/etc/bash_completion.d/brew && test "$(id -u)" -gt 0; then /home/linuxbrew/.linuxbrew/bin/brew completions link fi if test -d /home/linuxbrew/.linuxbrew/etc/bash_completion.d; then diff --git a/toolboxes/bluefin-cli/files/etc/profile.d/command-not-found-host-exec.sh b/toolboxes/bluefin-cli/files/etc/profile.d/command-not-found-host-exec.sh index 0a98fc4..0961c55 100644 --- a/toolboxes/bluefin-cli/files/etc/profile.d/command-not-found-host-exec.sh +++ b/toolboxes/bluefin-cli/files/etc/profile.d/command-not-found-host-exec.sh @@ -1,3 +1,4 @@ +# shellcheck shell=sh command_not_found_handle() { # don't run if not in a container if [ ! -e /run/.containerenv ] && [ ! -e /.dockerenv ]; then diff --git a/toolboxes/bluefin-cli/files/etc/profile.d/modern-unix.sh b/toolboxes/bluefin-cli/files/etc/profile.d/modern-unix.sh index c499244..1b38fd0 100644 --- a/toolboxes/bluefin-cli/files/etc/profile.d/modern-unix.sh +++ b/toolboxes/bluefin-cli/files/etc/profile.d/modern-unix.sh @@ -1,3 +1,4 @@ +# shellcheck shell=sh # Eza for ls alias ll='eza -l --icons=auto --group-directories-first' 2>/dev/null alias l.='eza -d .*' 2>/dev/null diff --git a/toolboxes/bluefin-cli/files/etc/profile.d/zz-profile_sourced.sh b/toolboxes/bluefin-cli/files/etc/profile.d/zz-profile_sourced.sh index e08c3d3..5140d0e 100644 --- a/toolboxes/bluefin-cli/files/etc/profile.d/zz-profile_sourced.sh +++ b/toolboxes/bluefin-cli/files/etc/profile.d/zz-profile_sourced.sh @@ -1,3 +1,4 @@ +# shellcheck shell=sh if [ -z "$PROFILESOURCED" ] && [ "$PS1" ]; then PROFILESOURCED="Y" fi diff --git a/toolboxes/bluefin-cli/files/usr/share/fish/vendor_conf.d/00-bluefin-cli-brew-firstrun.fish b/toolboxes/bluefin-cli/files/usr/share/fish/vendor_conf.d/00-bluefin-cli-brew-firstrun.fish new file mode 100644 index 0000000..3dc3bb0 --- /dev/null +++ b/toolboxes/bluefin-cli/files/usr/share/fish/vendor_conf.d/00-bluefin-cli-brew-firstrun.fish @@ -0,0 +1,45 @@ +if test "$(id -u)" -gt "0" + set blue (set_color blue) + set bold (set_color -o blue) + set normal (set_color normal) + if test ! -f /etc/linuxbrew.firstrun + printf "\nBluefin-CLI First Run Setup\n\n" + printf "Setting up sudo for %s%s%s...\t\t\t " "$bold" "$USER" "$normal" + echo "#$UID ALL = (root) NOPASSWD:ALL" | su-exec root tee -a /etc/sudoers > /dev/null + printf "%s[ OK ]%s\n" "$blue" "$normal" + end + + if test ! -d /home/linuxbrew/.linuxbrew + set name $(hostname -s) + set xdg_data_home "$XDG_DATA_HOME" + test -z "$xdg_data_home"; and set xdg_data_home "$HOME/.local/share/" + set linuxbrew_home "$xdg_data_home/bluefin-cli/$name" + printf "Setting up Linuxbrew...\t\t\t\t " + if test ! -d "$linuxbrew_home" + mkdir -p "$linuxbrew_home" + end + if test ! -d /home/linuxbrew + su-exec root mkdir -p /home/linuxbrew + end + su-exec root mount --bind "$linuxbrew_home" /home/linuxbrew + su-exec root cp -R /home/homebrew/.linuxbrew /home/linuxbrew/ + su-exec root chown -R "$UID" /home/linuxbrew + set -e linuxbrew_home + printf "%s[ OK ]%s\n" "$blue" "$normal" + end + + if test ! -d /usr/local/share/bash-completion/completions + printf "Setting up Tab-Completions...\t\t\t " + su-exec root mkdir -p /usr/local/share/bash-completion + su-exec root mount --bind /run/host/usr/share/bash-completion /usr/local/share/bash-completion + if test -x /run/host/usr/bin/ujust + su-exec root ln -fs /usr/bin/distrobox-host-exec /usr/local/bin/ujust + end + printf "%s[ OK ]%s\n" "$blue" "$normal" + end + + if test ! -f /etc/linuxbrew.firstrun + su-exec root touch /etc/linuxbrew.firstrun + printf "\nBluefin-CLI first run complete!\n\n" + end +end diff --git a/toolboxes/bluefin-cli/files/usr/share/fish/vendor_conf.d/bling.fish b/toolboxes/bluefin-cli/files/usr/share/fish/vendor_conf.d/bling.fish new file mode 100644 index 0000000..1e8ef53 --- /dev/null +++ b/toolboxes/bluefin-cli/files/usr/share/fish/vendor_conf.d/bling.fish @@ -0,0 +1,26 @@ +if status is-interactive + set -gx STARSHIP_CONFIG /etc/starship.toml + eval "$(starship init fish)" + eval "$(atuin init fish)" + eval "$(zoxide init fish --cmd cd)" +end + +# Eza for ls +alias ll='eza -l --icons=auto --group-directories-first' 2>/dev/null +alias l.='eza -d .*' 2>/dev/null +alias ls='eza' 2>/dev/null +alias l1='eza -1' + +# Ripgrep for grep +alias grep='rg' 2>/dev/null +alias egrep='rg' 2>/dev/null +alias fgrep='rg -F' 2>/dev/null +alias xzgrep='rg -z' 2>/dev/null +alias xzegrep='rg -z' 2>/dev/null +alias xzfgrep='rg -z -F' 2>/dev/null + +# Zoxide is handling cd +alias cd='cd' 2>/dev/null + +# Fd for find +alias find='fd' 2>/dev/null \ No newline at end of file diff --git a/toolboxes/bluefin-cli/files/usr/share/fish/vendor_conf.d/brew.fish b/toolboxes/bluefin-cli/files/usr/share/fish/vendor_conf.d/brew.fish new file mode 100644 index 0000000..511fb5c --- /dev/null +++ b/toolboxes/bluefin-cli/files/usr/share/fish/vendor_conf.d/brew.fish @@ -0,0 +1,6 @@ +if test "$(id -u)" -gt "0" + set -gx PATH $PATH /home/linuxbrew/.linuxbrew/bin + set -gx HOMEBREW_PREFIX /home/linuxbrew/.linuxbrew + set -gx HOMEBREW_CELLAR /home/linuxbrew/.linuxbrew/Cellar + set -gx HOMEBREW_REPOSITORY /home/linuxbrew/.linuxbrew +end \ No newline at end of file diff --git a/toolboxes/bluefin-cli/files/usr/share/fish/vendor_functions.d/fish_command_not_found.fish b/toolboxes/bluefin-cli/files/usr/share/fish/vendor_functions.d/fish_command_not_found.fish new file mode 100644 index 0000000..d7243f0 --- /dev/null +++ b/toolboxes/bluefin-cli/files/usr/share/fish/vendor_functions.d/fish_command_not_found.fish @@ -0,0 +1,8 @@ +function fish_command_not_found + # "In a container" check + if test -e /run/.containerenv -o -e /.dockerenv + distrobox-host-exec $argv + else + __fish_default_command_not_found_handler $argv + end +end \ No newline at end of file