How To: Remove grub theme during boot?

yea this idea is a good one :wink:

1 Like

@manuel, this is what I’ve done so far:

#/bin/bash

function cleanup() {
  printf '\e[?25h' # unhide cursor
  stty echo
}
trap cleanup EXIT

stty -echo
printf '\e[?25l' # hide cursor

CSI_fg=$'\e[38;2;'
CSI_bg=$'\e[48;2;'
esc_reset=$'\e[0m'

esc=(
  "0;0;0m"         # black
  "0;0;168m"       # blue
  "0;168;0m"       # green
  "0;168;168m"     # cyan
  "168;0;0m"       # red
  "168;0;168m"     # magenta
  "168;84;0m"      # brown
  "168;168;168m"   # light-gray
  "84;84;84m"      # dark-gray
  "84;84;254m"     # light-blue
  "84;254;84m"     # light-green
  "84;254;254m"    # light-cyan
  "254;84;84m"     # light-red
  "254;84;254m"    # light-magenta
  "254;254;84m"    # yellow
  "254;254;254m"   # white
)

# make black opaque for truecolor terminal emulators:
[[ $COLORTERM = "truecolor" ]] && esc[0]="1;1;1m"

cname=(
  "black"
  "blue"
  "green"
  "cyan"
  "red"
  "magenta"
  "brown"
  "light-gray"
  "dark-gray"
  "light-blue"
  "light-green"
  "light-cyan"
  "light-red"
  "light-magenta"
  "yellow"
  "white"
)

val=(0 9 1 11) #normal bg, normal fg, highlighted bg, highlighted fg
selected=0;

print_menu() {
  gb=$CSI_bg${esc[0]}$CSI_fg${esc[7]}
  no=$CSI_bg${esc[${val[0]}]}$CSI_fg${esc[${val[1]}]}
  hl=$CSI_bg${esc[${val[2]}]}$CSI_fg${esc[${val[3]}]}

  cat \
<< EOF
$gb           Colour Picker for GRUB - EXAMPLE           $esc_reset
$gb    $noβ”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”$gb    $esc_reset
$gb    $noβ”‚ Normal option                              β”‚$gb    $esc_reset
$gb    $noβ”‚ Normal option                              β”‚$gb    $esc_reset
$gb    $noβ”‚$hl Highlighted option                         $noβ”‚$gb    $esc_reset
$gb    $noβ”‚ Normal option                              β”‚$gb    $esc_reset
$gb    $noβ”‚                                            β”‚$gb    $esc_reset
$gb    $noβ”‚                                            β”‚$gb    $esc_reset
$gb    $noβ”‚                                            β”‚$gb    $esc_reset
$gb    $noβ””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜$gb    $esc_reset
$gb    Use the arrow keys to change the values below.    $esc_reset
$gb    Press ENTER when done.                            $esc_reset
$gb                                                      $esc_reset
EOF

  local SO
  local SC
  SO[$selected]='>'
  SC[$selected]='<'

  printf "%s      Normal background:      %-2s%-14s%s%2s    %s\n" \
    "$gb" "${SO[0]}" "${cname[${val[0]}]}" "$CSI_fg${esc[${val[0]}]}β–ˆβ–ˆ$gb" \
    "${SC[0]}" "$esc_reset"
  printf "%s      Normal foreground:      %-2s%-14s%s%2s    %s\n" \
    "$gb" "${SO[1]}" "${cname[${val[1]}]}" "$CSI_fg${esc[${val[1]}]}β–ˆβ–ˆ$gb" \
    "${SC[1]}" "$esc_reset"
  printf "%s      Highlighted background: %-2s%-14s%s%2s    %s\n" \
    "$gb" "${SO[2]}" "${cname[${val[2]}]}" "$CSI_fg${esc[${val[2]}]}β–ˆβ–ˆ$gb" \
    "${SC[2]}" "$esc_reset"
  printf "%s      Highlighted foreground: %-2s%-14s%s%2s    %s\n" \
    "$gb" "${SO[3]}" "${cname[${val[3]}]}" "$CSI_fg${esc[${val[3]}]}β–ˆβ–ˆ$gb" \
    "${SC[3]}" "$esc_reset"
}

move_cursor_top() {
  #printf "\e[17F" # does not work on some terminals?
  printf "\e[17A\r" # same thing
}


while true; do
  print_menu
  # wait for input
  read -rsn1 key
  [[ $key = $'' ]] && break
  [[ $key = $'\u1b' ]] && {
    read -rsn2 key
  }
  [[ -n $key ]] && {
    case "$key" in
      '[D'|h ) val[$selected]=$(((val[selected]+15)%16)) ;;
      '[B'|j ) selected=$((selected >= 3 ? 3 : selected+1)) ;;
      '[A'|k ) selected=$((selected <= 0 ? 0 : selected-1)) ;;
      '[C'|l ) val[$selected]=$(((val[selected]+1) % 16)) ;;
      #q ) break ;;
      #* ) continue ;;
    esac
  }
  move_cursor_top
done

move_cursor_top
selected=5
print_menu

cat << EOF

To apply the changes, add the following two lines
to your /etc/default/grub file:

$CSI_fg${esc[7]}GRUB_COLOR_NORMAL="${cname[${val[1]}]}/${cname[${val[0]}]}"
GRUB_COLOR_HIGHLIGHT="${cname[${val[3]}]}/${cname[${val[2]}]}"$esc_reset

Do not forget to run:

sudo grub-mkconfig -o /boot/grub/grub.cfg

EOF

A big thanks to @dalto who helped me determine the RGB values of GRUB colours.

For now, it only works in a terminal that supports truecolor (like Konsole). I will make it so that it works on terminals that support only 16 colours, but the values will not be accurate, of course.

Currently, it does not edit /etc/default/grub, but simply tells the user what two lines to add. This could be implemented, but I’m not sure I would trust a script to do it instead of me. If you want me to do it, let me know, it shouldn’t be a problem.

This is now quite off topic.

EDIT: Updated the script. It looks good now in Konsole and in the TTY, needs testing on other terminal emulators.

EDIT2: thanks to @keybreak for reporting that the script did not work properly in Cool Retro Term. The issue is fixed now.

10 Likes

Thanks for your hard work and others who helped as well! :+1:

One idea is to have an option like --save for this. Then user can decide.
But anyway, it is up to you if you are willing to make more changes.

I’ll try your script as soon as I have more time, hopefully later today.

4 Likes

I’m certainly willing to implement that, it’s not too difficult. What I am not 100% sure I’m able to do is offer 24/7 tech support for n00bs who used this script and, due to some unforeseen conflict with some other option, made their computers unbootable1. And I’m certainly not willing to take any blame for that. :wink:


1I can already see it, all over reddit: β€œKresimir’s script bricked my Manjaro PC, whaaaaaaaa :sob:”

4 Likes

Tried your script with xfce4-terminal, qterminal and terminator.
The graphics worked well on all of them.
Great work! And thanks!

No problem, we can add disclaimer:

This is EndeavourOS community software - made by Kresimir.
No warranty whatsoever. Use it at your own risk.
:wink:

But seriously, the script as-is should already be very useful for many people.
Did you already have any (command) name in mind for it?

5 Likes

How about HUGE letters in UI itself - MADE BY KRESIMIR!!! :frog:

Can’t wait for reddit & Manjaro… :rofl:

3 Likes

I don’t know… grub-colour-chooser? I’m bad at names… :rofl:

I’ll implement writing the changes to a file. It will be a very simple sed script that will just comment out all lines starting with GRUB_COLOR_NORMAL= or GRUB_COLOR_HIGHLIGHT= and add the two lines at the end of the file.

3 Likes

The name sounds OK to me.

Just a suggestion: write also a comment in the end of file saying something like:

  # modified by "the-name-of-your-script"
  GRUB_COLOR_NORMAL=...

Then people will know why there are modifications.

4 Likes

@Kresimir
I hope you are sticking with the EndeavourOS color scheme like the purple side. :grinning:

david-clode-IY9bfJAM2zM-unsplash

8 Likes

Oh I love this image. Do you have it in 1440p? Or at least in 1080p? I want to use it as my SDDM background!

stars

5 Likes

I can scale it for you in an hour or so :+1:

1 Like

1920x1080-5403057-frog-tree-frog-petal-macro-frog-eye-flower-david-clode-wake-up-frog-close-up-frog-litoria-gracilentum-dainty-treefrog-waterlily-frog-rise-and-shine-green-creative-commons-images

2 Likes

Thanks, I can scale it myself in GIMP, I just asked if someone had a better quality version.

@anon12581665, this is not good, unfortunately, the water lily is cropped poorly.

https://mocah.org/5403057-frog-tree-frog-petal-macro-frog-eye-flower-david-clode-wake-up-frog-close-up-frog-litoria-gracilentum-dainty-treefrog-waterlily-frog-rise-and-shine-green-creative-commons-images.html

2 Likes

I just found it on the net. Maybe there are some others?

Edit: As @anon12581665 has posted a link.

2560x1600

2560x1600-5403057-frog-tree-frog-petal-macro-frog-eye-flower-david-clode-wake-up-frog-close-up-frog-litoria-gracilentum-dainty-treefrog-waterlily-frog-rise-and-shine-green-creative-commons-images

6 Likes

@Kresimir
For a special grub theme.
david-clode-n3myBqaVtWc-unsplash

7 Likes

By the way, looks like the GRUB_THEME variable needs to be commented out if it isn’t.
Otherwise the color variables seem to have no effect.

2 Likes

So maybe the easiest change in the end of file /etc/default/grub is:

# modified by grub-colour-chooser
GRUB_COLOR_NORMAL=...
GRUB_COLOR_HIGHLIGHT=...
unset GRUB_THEME

?

1 Like

Yeah, I’ll figure it out, it shouldn’t be difficult. Today or tomorrow, when I get some time to focus on it.

3 Likes

No hurry! We all do voluntary stuff here! :wink:

3 Likes