From 267e5be35d824a5c921f18bce9fc151ed6762947 Mon Sep 17 00:00:00 2001 From: m2 <69128853+m2Giles@users.noreply.github.com> Date: Sun, 11 Feb 2024 11:57:57 -0800 Subject: [PATCH 1/4] feat: improve prompt integration with quadlets (#889) --- usr/libexec/enable-bluefin-cli.sh | 28 ++++++++- usr/libexec/prompt-add-profile.sh | 7 ++- usr/libexec/prompt-create-profile.sh | 61 ++++++++++++++++--- usr/libexec/prompt-remove-profile.sh | 43 ++++++++----- .../ublue-os/bluefin-cli/known-containers | 19 ++++++ 5 files changed, 132 insertions(+), 26 deletions(-) create mode 100644 usr/share/ublue-os/bluefin-cli/known-containers diff --git a/usr/libexec/enable-bluefin-cli.sh b/usr/libexec/enable-bluefin-cli.sh index 037cb5fe655..0e56a08d6b4 100755 --- a/usr/libexec/enable-bluefin-cli.sh +++ b/usr/libexec/enable-bluefin-cli.sh @@ -7,7 +7,7 @@ # shellcheck disable=2154 source /usr/lib/ujust/ujust.sh -bluefin_cli=(${red}Disabled${n} ${red}Inactive${n}) +bluefin_cli=(${red}Disabled${n} ${red}Inactive${n} ${red}Not Default${n}) function get_status(){ if systemctl --quiet --user is-enabled bluefin-cli.target; then @@ -20,8 +20,29 @@ function get_status(){ else bluefin_cli[1]="${red}Inactive${n}" fi - echo "Bluefin-cli is currently ${b}${bluefin_cli[0]}${n} and ${b}${bluefin_cli[1]}${n}" + get_default=$(dconf read /org/gnome/Prompt/Profiles/default-profile-uuid) + if test "$get_default" = "'a21a910811504857bea4c96b3d937b93'"; then + bluefin_cli[2]="${green}Default${n}" + else + bluefin_cli[2]="${red}Not-Default${n}" + fi + echo "Bluefin-cli is currently ${b}${bluefin_cli[0]}${n} (run status), ${b}${bluefin_cli[1]}${n} (on boot status), and ${b}${bluefin_cli[2]}${n} (terminal profile)." +} + +function default_login(){ + toggle=$(Choose Default Not-Default Cancel) + if test "$toggle" = "Default"; then + echo "Setting Bluefin-CLI to default Prompt Profile" + /usr/libexec/prompt-create-profile bluefin-cli default + elif test "$toggle" = "Not-Default"; then + echo "Setting Host back to default Prompt Profile" + /usr/libexec/prompt-create-profile Host default + else + dconf write /or + echo "Not Changing" + fi } + function logic(){ if test "$toggle" = "Enable"; then echo "${b}${green}Enabling${n} Bluefin-CLI" @@ -31,6 +52,7 @@ function logic(){ echo "${b}${green}Starting${n} Bluefin-CLI" systemctl --user start bluefin-cli.service fi + default_login elif test "$toggle" = "Disable"; then echo "${b}${red}Disabling${n} Bluefin-CLI" systemctl --user disable --now bluefin-cli.target > /dev/null 2>&1 @@ -42,6 +64,8 @@ function logic(){ systemctl --user reset-failed bluefin-cli.service > /dev/null 2>&1 || true fi fi + echo "Setting Host back to default Prompt Profile" + /usr/libexec/prompt-create-profile Host default else echo "Not Changing" fi diff --git a/usr/libexec/prompt-add-profile.sh b/usr/libexec/prompt-add-profile.sh index 8286a591c74..348ae3cc482 100755 --- a/usr/libexec/prompt-add-profile.sh +++ b/usr/libexec/prompt-add-profile.sh @@ -2,7 +2,7 @@ # Read the current value of the array CURRENT_VALUE=$(dconf read /org/gnome/Prompt/profile-uuids) -guid=$1 +guid="$1" # remove the leading and trailing brackets CURRENT_VALUE=${CURRENT_VALUE:1:-1} @@ -13,6 +13,9 @@ CURRENT_VALUE=${CURRENT_VALUE// /} # split the string into an array IFS=',' read -r -a array <<<"$CURRENT_VALUE" +# Exit if the guid already is in the array +[[ $CURRENT_VALUE =~ $guid ]] && exit 0 + # add the new value array+=("'$guid'") @@ -26,4 +29,4 @@ UPDATED_VALUE=${UPDATED_VALUE%?} UPDATED_VALUE="[$UPDATED_VALUE]" # Write the updated array back to dconf -dconf write /org/gnome/Prompt/profile-uuids "$UPDATED_VALUE" \ No newline at end of file +dconf write /org/gnome/Prompt/profile-uuids "$UPDATED_VALUE" diff --git a/usr/libexec/prompt-create-profile.sh b/usr/libexec/prompt-create-profile.sh index 87d8161856b..2665e59623b 100755 --- a/usr/libexec/prompt-create-profile.sh +++ b/usr/libexec/prompt-create-profile.sh @@ -15,28 +15,75 @@ # if dconf doesn't exist, just return if ! command -v dconf >/dev/null; then - return + exit 0 fi +# shellcheck disable=SC1091 +. /usr/share/ublue-os/bluefin-cli/known-containers + # shellcheck disable=SC2001 gen_uuid() { uuid="$(cat /proc/sys/kernel/random/uuid)" echo "$uuid" | sed 's/-//g' } -guid=$(gen_uuid) name="$1" -palette="$2" +default="$2" +palette="$3" + +for check in "${!known_container[@]}"; do + if test "$check" = "$name"; then + guid=${known_container[$check]} + fi +done + +if test -z "$guid"; then + guid=$(gen_uuid) +fi + +default_guid=$(dconf read /org/gnome/Prompt/default-profile-uuid) +default_guid=${default_guid:1:-1} + +# If default profile is trying to be made, just exit +if test "$guid" = "$default_guid"; then + exit 0 +fi + +if test -z "$default"; then + make_default=0 +elif test "$default" = "default" || test "$default" -eq 1; then + make_default=1 +fi + +# Write the default value if specified +if test "$make_default" -eq 1; then + dconf write /org/gnome/Prompt/default-profile-uuid "'${guid}'" +fi profile="/org/gnome/Prompt/Profiles/${guid}/" +opacity=$(dconf read /org/gnome/Prompt/Profiles/"${default_guid}"/opacity) + +if test "$name" = "Host"; then + dconf write "${profile}label" "'${name}'" +else + dconf write "${profile}custom-command" "'sh -c \"[ ! -e /run/.containerenv ] && exec distrobox enter ${name} || ${SHELL}\"'" + dconf write "${profile}label" "'${name}'" + dconf write "${profile}use-custom-command" "true" + dconf write "${profile}ublue-os" "true" +fi + +if test -n "$opacity"; then + dconf write "${profile}opacity" "'${opacity}'" +fi -dconf write "${profile}custom-command" "'sh -c \"[ ! -e /run/.containerenv ] && [ ! -e /run/.dockerenv ] && distrobox enter ${name} || ${SHELL}\"'" -dconf write "${profile}label" "'${name}'" -dconf write "${profile}use-custom-command" "true" if test -n "$palette"; then dconf write "${profile}palette" "'${palette}'" -elif test "$name" = "bluefin-cli"; then +elif test "$name" = "bluefin-cli" || test "$name" = "bluefin-dx-cli"; then dconf write "${profile}palette" "'catppuccin-dynamic'" +elif test "$name" = "fedora-toolbox"; then + dconf write "${profile}palette" "'Elio'" +elif test "$name" = "ubuntu-toolbox"; then + dconf write "${profile}palette" "'Clone Of Ubuntu'" fi /usr/libexec/prompt-add-profile.sh "$guid" diff --git a/usr/libexec/prompt-remove-profile.sh b/usr/libexec/prompt-remove-profile.sh index 2cd33642975..40bd55a1d00 100755 --- a/usr/libexec/prompt-remove-profile.sh +++ b/usr/libexec/prompt-remove-profile.sh @@ -6,6 +6,12 @@ if ! command -v dconf >/dev/null; then return fi +# Cleanup any stale profiles +for i in $(dconf list /org/gnome/Prompt/Profiles/); do + i=${i:0:-1} + [[ $(dconf read /org/gnome/Prompt/profile-uuids) =~ $i ]] || dconf reset -f "/org/gnome/Prompt/Profiles/${i}/" +done + name="$1" # Read the current value of the array @@ -20,33 +26,40 @@ CURRENT_VALUE=${CURRENT_VALUE// /} # split the string into an array IFS=',' read -r -a array <<<"$CURRENT_VALUE" +# Get Default +DEFAULT_VALUE=$(dconf read /org/gnome/Prompt/default-profile-uuid) + # loop through the array and remove any that don't exist for i in "${!array[@]}"; do guid=${array[i]} # remove single quotes from guid - guid=${guid//\'/} #echo "Checking profile for $(red $guid)" profile="/org/gnome/Prompt/Profiles/${guid}/" - custom_shell=$(dconf read "${profile}custom-command") + ublue_os=$(dconf read "${profile}ublue-os") + label=$(dconf read "${profile}label") + label=${label:1:-1} - if [[ $custom_shell == *"[ ! -e /run/.containerenv ] && [ ! -e /run/.dockerenv ] && distrobox enter ${name}"* ]]; then - dconf reset -f "${profile}" - # remove the guid from the array - unset 'array[i]' - # join the array back into a string - UPDATED_VALUE=$(printf "%s," "${array[@]}") + if test "$ublue_os" = "true"; then + # Don't delete the profile if it's the default or if it's enabled + if ! test "$DEFAULT_VALUE" = "$guid" && test "$name" = "$label" && ! systemctl --user --quiet is-enabled "${name}".target; then + dconf reset -f "${profile}" + # remove the guid from the array + unset 'array[i]' + # join the array back into a string + UPDATED_VALUE=$(printf "%s," "${array[@]}") - # remove the trailing comma - UPDATED_VALUE=${UPDATED_VALUE%?} + # remove the trailing comma + UPDATED_VALUE=${UPDATED_VALUE%?} - # add the leading and trailing brackets - UPDATED_VALUE="[$UPDATED_VALUE]" + # add the leading and trailing brackets + UPDATED_VALUE="[$UPDATED_VALUE]" - # Write the updated array back to dconf - dconf write /org/gnome/Prompt/profile-uuids "$UPDATED_VALUE" + # Write the updated array back to dconf + dconf write /org/gnome/Prompt/profile-uuids "$UPDATED_VALUE" + fi fi -done \ No newline at end of file +done diff --git a/usr/share/ublue-os/bluefin-cli/known-containers b/usr/share/ublue-os/bluefin-cli/known-containers new file mode 100644 index 00000000000..0e9b3aa88d3 --- /dev/null +++ b/usr/share/ublue-os/bluefin-cli/known-containers @@ -0,0 +1,19 @@ +# shellcheck shell=bash +declare -Ar known_container=( + ["bluefin-cli"]="a21a910811504857bea4c96b3d937b93" + ["bluefin-dx-cli"]="276d25e6065b497b96dd57e4f95ff50a" + ["fedora-toolbox"]="d6fe45489ed74fada5d95d715449ce7e" + ["ubuntu-toolbox"]="4741cb2eb3614750b79edc5c4b8c08b3" + ["wolfi-toolbox"]="33bd8e9953224e6985d8524e9b7294a1" + ["wolfi-dx-toolbox"]="03d42eab38f740089cbe2fa5e2d6a374" + ["Host"]="2871e8027773ae74d6c87a5f659bbc74" +) +declare -Ar known_guid=( + ["a21a910811504857bea4c96b3d937b93"]="bluefin-cli" + ["276d25e6065b497b96dd57e4f95ff50a"]="bluefin-dx-cli" + ["d6fe45489ed74fada5d95d715449ce7e"]="fedora-toolbox" + ["4741cb2eb3614750b79edc5c4b8c08b3"]="ubuntu-toolbox" + ["33bd8e9953224e6985d8524e9b7294a1"]="wolfi-toolbox" + ["03d42eab38f740089cbe2fa5e2d6a374"]="wolfi-dx-toolbox" + ["2871e8027773ae74d6c87a5f659bbc74"]="Host" +) \ No newline at end of file From 36adbfdb37e66b6a66320255da068348b234aee7 Mon Sep 17 00:00:00 2001 From: m2 <69128853+m2Giles@users.noreply.github.com> Date: Sun, 11 Feb 2024 14:15:33 -0800 Subject: [PATCH 2/4] fix: correct name in enable-bluefin-cli.sh (#894) --- usr/libexec/enable-bluefin-cli.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/usr/libexec/enable-bluefin-cli.sh b/usr/libexec/enable-bluefin-cli.sh index 0e56a08d6b4..2a98acf5fd6 100755 --- a/usr/libexec/enable-bluefin-cli.sh +++ b/usr/libexec/enable-bluefin-cli.sh @@ -33,10 +33,10 @@ function default_login(){ toggle=$(Choose Default Not-Default Cancel) if test "$toggle" = "Default"; then echo "Setting Bluefin-CLI to default Prompt Profile" - /usr/libexec/prompt-create-profile bluefin-cli default + /usr/libexec/prompt-create-profile.sh bluefin-cli default elif test "$toggle" = "Not-Default"; then echo "Setting Host back to default Prompt Profile" - /usr/libexec/prompt-create-profile Host default + /usr/libexec/prompt-create-profile.sh Host default else dconf write /or echo "Not Changing" @@ -65,7 +65,7 @@ function logic(){ fi fi echo "Setting Host back to default Prompt Profile" - /usr/libexec/prompt-create-profile Host default + /usr/libexec/prompt-create-profile.sh Host default else echo "Not Changing" fi @@ -78,4 +78,4 @@ function main(){ get_status } -main \ No newline at end of file +main From 95ca17f462604e9f40b77367c359ccea0e893966 Mon Sep 17 00:00:00 2001 From: m2 <69128853+m2Giles@users.noreply.github.com> Date: Sun, 11 Feb 2024 15:22:55 -0800 Subject: [PATCH 3/4] feat: Get Atuin from bluefin-cli (#895) --- Containerfile | 4 ++++ just/custom.just | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Containerfile b/Containerfile index a95b44c7534..664eda04fba 100644 --- a/Containerfile +++ b/Containerfile @@ -75,6 +75,10 @@ RUN curl -Lo /tmp/starship.tar.gz "https://github.com/starship/starship/releases install -c -m 0755 /tmp/starship /usr/bin && \ echo 'eval "$(starship init bash)"' >> /etc/bashrc +# Copy atuin from bluefin-cli +COPY --from=ghcr.io/ublue-os/bluefin-cli /usr/bin/atuin /usr/bin/atuin +COPY --from=ghcr.io/ublue-os/bluefin-cli /usr/share/bash-prexec /usr/share/bash-prexec + RUN wget https://copr.fedorainfracloud.org/coprs/ublue-os/staging/repo/fedora-"${FEDORA_MAJOR_VERSION}"/ublue-os-staging-fedora-"${FEDORA_MAJOR_VERSION}".repo -O /etc/yum.repos.d/ublue-os-staging-fedora-"${FEDORA_MAJOR_VERSION}".repo && \ /tmp/build.sh && \ /tmp/image-info.sh && \ diff --git a/just/custom.just b/just/custom.just index 8a57bfaa97f..792961c9d05 100644 --- a/just/custom.just +++ b/just/custom.just @@ -243,3 +243,18 @@ dx-group: sudo usermod -aG lxd $USER sudo usermod -aG libvirt $USER @echo "Logout to use docker, incus-admin, lxd, libvirt" + +# Add atuin +atuin: + #!/usr/bin/bash + shell=$(basename $SHELL) + if test $shell = "fish"; then + echo "Adding atuin to your config.fish" + printf '\nif status is-interactive\n atuin init fish | source\nend\n' >> ${XDG_CONFIG_HOME:-$HOME/.config}/fish/config.fish + elif test $shell = "zsh"; then + echo "Adding atuin to your .zshrc" + printf '\neval "$(atuin init zsh)"\n' >> ${ZDOTDIR:-$HOME}/.zshrc + elif test $shell = "bash"; then + echo "Adding bash-prexec and atuin to your .bashrc" + printf '\n[[ -f /usr/share/bash-prexec ]] && source /usr/share/bash-prexec\neval "$(atuin init bash)"\n' >> ~/.bashrc + fi From 954d4e05437c3f15d3d31bebfd845a49edb32f40 Mon Sep 17 00:00:00 2001 From: m2 <69128853+m2Giles@users.noreply.github.com> Date: Sun, 11 Feb 2024 19:04:54 -0800 Subject: [PATCH 4/4] fix: enable MOTD for fish (#897) --- usr/share/fish/functions/fish_greeting.fish | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 usr/share/fish/functions/fish_greeting.fish diff --git a/usr/share/fish/functions/fish_greeting.fish b/usr/share/fish/functions/fish_greeting.fish new file mode 100644 index 00000000000..42676df7f33 --- /dev/null +++ b/usr/share/fish/functions/fish_greeting.fish @@ -0,0 +1,13 @@ +function fish_greeting + if test -d "$HOME" + if test ! -e "$HOME"/.config/no-show-user-motd + if test -x "/usr/libexec/ublue-motd" + /usr/libexec/ublue-motd + end + end + end + + if set -q fish_private_mode + echo "fish is running in private mode, history will not be persisted." + end +end \ No newline at end of file