My Manjaro cheatsheet in a menu form

Xdialog doesn’t work for me .
Changing to dialog works.
I will see if on my system what is causing this.
xdialog 2.3.1-9

This works but I don’t know how to apply it to your script:

#!/bin/bash
cmd=(Xdialog --keep-tite --menu "Select options:" 22 76 16)

options=(1 "Option 1"
         2 "Option 2"
         3 "Option 3"
         4 "Option 4")

choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)

for choice in $choices
do
    case $choice in
        1)
            echo "First Option"
            ;;
        2)
            echo "Second Option" ; pacman-mirrors
            ;;
        3)
            echo "Third Option"
            ;;
        4)
            echo "Fourth Option"
            ;;
    esac
done

Hi,
love your script.
I just put a loop around, so i can execute more than one command.

Version 11.04.2024-2 with loop added
#!/bin/bash
# Creator: Todor Uzunov
# License: GNU - free like free speech and free beer for everybody!
# Version: 11.04.2024-2
# Changelog: try to find dependencies and compatibility mode

MODE=Xdialog
# check if dependencies are present and fall back to dialog
if ! [[ "$(which dialog)" =~ (dialog) ]] &>/dev/null; then
if ! [[ "$(which Xdialog)" =~ (Xdialog) ]] &>/dev/null; then
	echo "Xdialog dependency is not found, please install with: sudo pacman -S xdialog"
	echo "Alternatively for TUI version install dialog: sudo pacman -S xdialog"
	exit 1
fi
if ! [[ "$(which /usr/lib/gtk-2.0/2.10.0/engines/libmurrine.so)" =~ (/usr/lib/gtk-2.0/2.10.0/engines/libmurrine.so) ]] &>/dev/null; then
	echo "Libmurrine dependency is not found, please install with: sudo pacman -S gtk-engine-murrine"
	echo "Alternatively for TUI version install dialog: sudo pacman -S xdialog"
	exit 1
fi
else
if ! [[ "$(which Xdialog)" =~ (Xdialog) ]]; then
	MODE=dialog
	if [[ "$(which notify-send)" =~ (notify-send) ]]; then notify-send "Xdialog dependency is not found, please install with"  "sudo pacman -S xdialog"; fi
fi
if ! [[ "$(which /usr/lib/gtk-2.0/2.10.0/engines/libmurrine.so)" =~ (/usr/lib/gtk-2.0/2.10.0/engines/libmurrine.so) ]]; then
	MODE=dialog
	if [[ "$(which notify-send)" =~ (notify-send) ]]; then notify-send "libmurrine dependency is not found, please install with"  "sudo pacman -S gtk-engine-murrine"; fi
fi
fi
OPTIONS=(
	1 "Mirror Sync status and branch || pacman-mirrors"
	2 "Refresh the mirror list || sudo pacman-mirrors -f5" # sudo pacman-mirrors --country Germany --api --protocol https
	3 "Update all without AUR || sudo pacman -Syu"
	4 "Download all updates for offline install later || sudo pacman -Syuw"
	5 "Force refresh database and update || sudo pacman -Syyu"
	6 "Check which dependencies are already installed (paste packagename) || for i in \$(expac -S '%D' \$pkg); do pacman -Q \$i"
	7 "Run pacdiff with Meld to compare changed configs || DIFFPROG=meld pacdiff -s" # pamac install meld
	8 "List foreign (AUR) packages || pacman -Qm"
	9 "List orphaned packages || pacman -Qdt"
	10 "Check for updates of AUR with YAY, do not update || yay -Qua" # pamac install yay
	11 "Update only AUR packages with YAY || yay -Sua" # pamac install yay
	12 "Pamac update AUR packages || pamac update --aur"
	13 "Remove orphaned packages || sudo pacman -Rsu ..."
	14 "Clean Pacman cache || sudo pacman -Scc"
	15 "Trim the root of the SSD || sudo fstrim -v /"
	16 "S.M.A.R.T. status of the disk and write cycles || sudo smartctl --all /dev/nvme0" # smartctl --scan
	17 "Show journal errors from current boot || journalctl -b -p3 --no-pager"
	18 "Show journal errors from previous boot || journalctl -b -1 -p3 --no-pager"
	19 "Dmesg || sudo dmesg"
	20 "Check for coredumps || coredumpctl"
	21 "Run Wavemonitor to check Wifi channel and strength with wavemon || wavemon" # pamac install wavemon
	22 "Read sensors || sensors"
	23 "Gather system info || inxi -zv8"
	24 "Update database for locate || sudo updatedb"
	25 "Temporary disable Ideapad battery conservation mode || sudo conservation_mode.sh 0" # pamac build conservation_mode
	26 "Show hidden spaceeaters above 100M in HOME || du -sh -t +100M ~/.cache/* ~/.config/* ~/.local/share/*"
	27 "Show journal size || journalctl --disk-usage"
	28 "Cut journal to 2 weeks || sudo journalctl --vacuum-time=2weeks"
	29 "List coredumps on disk and used space || du -sh /var/lib/systemd/coredump/"
	30 "Clear coredumps on disk || sudo rm -f /var/lib/systemd/coredump/*"
	31 "Show systemd bootlog only || journalctl -b -t systemd"
	32 "Check for missing files from packages  || sudo pacman -Qk 2>/dev/null | grep -v ' 0 missing files' "
	33 "Which package owns an existing file (paste filepath) || read fileowner; pacman -Qo \$fileowner"
	34 "Which (installed or not) package contains a file (paste filename) || read whogotit; sudo pacman -Fyx \$whogotit"
	35 "Check for flatpak updates and update || flatpak update"
	36 "Remove orphaned (unused) flatpak runtimes || flatpak uninstall --unused"
	37 "Clean flatpak cache || sudo rm -rfv /var/tmp/flatpak-cache-*"
	38 "Clean tmp bash history files and Totem stream cache || rm -f ~/.bash_history-*.tmp && rm -f ~/.cache/totem/stream-buffer/*"
	39 "A 10-20 sec. cpu benchmark using bc to calculate PI || time echo \"scale=5000; 4*a(1)\" | bc -l > /dev/null" # pamac install bc
)
#if you prefer TUI or have compatibility issues just replace Xdialog with dialog in the line below
CHOICE='99'
while [[ $CHOICE != '' ]]; do
	CHOICE=$($MODE --clear \
			--no-shadow \
			--scrollbar \
			--column-separator "||" \
			--separator "||" \
					--backtitle "" \
					--title "A Manjaro cheatsheet by Teo" \
			--menu "" \
					79 185 79 \
					"${OPTIONS[@]}" \
					2>&1 >/dev/tty)
	#clear
	case $CHOICE in
		1) echo "pacman-mirrors"; pacman-mirrors ;;
		2) echo "sudo pacman-mirrors -f5"; sudo pacman-mirrors -f5 ;;
		3) echo "sudo pacman -Syu"; sudo pacman -Syu ;;
		4) echo "sudo pacman -Syuw"; sudo pacman -Syuw ;;
		5) echo "sudo pacman -Syyu"; sudo pacman -Syyu ;;
		6) echo "read wantedpackage; for i in \$(expac -S '%D' \$wantedpackage); do pacman -Q \$i;  done"; read wantedpackage; for i in $(expac -S '%D' $wantedpackage); do pacman -Q $i;  done ;;
		7) echo "DIFFPROG=meld pacdiff -s"; DIFFPROG=meld pacdiff -s ;;
		8) echo "pacman -Qm"; pacman -Qm ;;
		9) echo "pacman -Qdt"; pacman -Qdt ;;
		10) echo "yay -Qua"; yay -Qua ;;
		11) echo "yay -Sua"; yay -Sua ;;
		12) echo "pamac update --aur"; pamac update --aur ;;
		13) echo "sudo pacman -Rsu $(pacman -Qtdq)"; sudo pacman -Rsu $(pacman -Qtdq) ;;
		14) echo "sudo pacman -Scc"; sudo pacman -Scc ;;
		15) echo "sudo fstrim -v /"; sudo fstrim -v / ;;
		16) echo "sudo smartctl --all /dev/nvme0"; sudo smartctl --all /dev/nvme0 ;;
		17) echo "journalctl -b -p3 --no-pager"; journalctl -b -p3 --no-pager ;;
		18) echo "journalctl -b -1 -p3 --no-pager"; journalctl -b -1 -p3 --no-pager ;;
		19) echo "sudo dmesg"; sudo dmesg ;;
		20) echo "coredumpctl"; coredumpctl ;;
		21) echo "wavemon"; wavemon ;;
		22) echo "sensors"; sensors ;;
		23) echo "inxi -zv8"; inxi -zv8 ;;
		24) echo "sudo updatedb"; sudo updatedb ;;
		25) echo "sudo conservation_mode.sh 0"; sudo conservation_mode.sh 0 ;;
		26) echo "du -sh -t +100M ~/.cache/* ~/.config/* ~/.local/share/*"; du -sh -t +100M ~/.cache/* ~/.config/* ~/.local/share/* ;;
		27) echo "journalctl --disk-usage"; journalctl --disk-usage ;;
		28) echo "sudo journalctl --vacuum-time=2weeks"; sudo journalctl --vacuum-time=2weeks ;;
		29) echo "du -sh /var/lib/systemd/coredump/"; du -sh /var/lib/systemd/coredump/ ;;
		30) echo "sudo rm -f /var/lib/systemd/coredump/*"; sudo rm -f /var/lib/systemd/coredump/* ;;
		31) echo "journalctl -b -t systemd"; journalctl -b -t systemd ;;
		32) echo "sudo pacman -Qk 2>/dev/null | grep -v ' 0 missing files' "; sudo pacman -Qk 2>/dev/null | grep -v ' 0 missing files' ;;
		33) echo "read fileowner; pacman -Qo \$fileowner"; read fileowner; pacman -Qo $fileowner ;;
		34) echo "read whogotit; sudo pacman -Fyx \$whogotit"; read whogotit; sudo pacman -Fyx $whogotit ;;
		35) echo "flatpak update"; flatpak update ;;
		36) echo "flatpak uninstall --unused"; flatpak uninstall --unused ;;
		37) echo "sudo rm -rfv /var/tmp/flatpak-cache-*"; sudo rm -rfv /var/tmp/flatpak-cache-* ;;
		38) echo "rm -f ~/.bash_history-*.tmp && rm -f ~/.cache/totem/stream-buffer/*"; rm -f ~/.bash_history-*.tmp && rm -f ~/.cache/totem/stream-buffer/* ;;
		39) echo "time echo \"scale=5000; 4*a(1)\" | bc -l > /dev/null"; time echo "scale=5000; 4*a(1)" | bc -l > /dev/null ;;
	esac
	# if we use a launcher shortcut with -launcher, pause before exit
	#if [ "$1" == "-launcher" ]; then
	if [[ $CHOICE != '' ]]; then
		read -n 1 -s -r -p "Press any key to return to menu.";
	fi
done
echo "ended"

Edit: Fixed an error, when ‘cancel’ is chosen.

Can someone else with KDE test? I think it has something to do with it, and somehow silently replacing Xdialog with kdialog, and that does not work, the syntax is very different.
Cause i do not see how the example of Maybl8 can change anything, the difference is one loop and one invalid option --keep-title.(which does not work with pure dialog)

First run;

which: no Xdialog in (~/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
Xdialog dependency is not found, please install with: sudo pacman -S xdialog

After installing xdialog (using first option as it is no transaction);

pacman-mirrors
Pacman-mirrors version 4.24.0
Local mirror status for unstable branch
[... ~ mirrors ~ ...]

So seems fine, at least as far as launching, from what I could gather. :person_shrugging:

I put all the choices in and it works for me.

#!/bin/bash
cmd=(Xdialog --keep-tite --menu "Select options:" 79 185 79)

options=(1 "Mirror Sync status and branch || pacman-mirrors"
  2 "Refresh the mirror list || sudo pacman-mirrors -f5" 
  3 "Update all without AUR || sudo pacman -Syu"
  4 "Download all updates for offline install later || sudo pacman -Syuw"
  5 "Force refresh database and update || sudo pacman -Syyu"
  6 "Check which dependencies are already installed (paste packagename) || for i in \$(expac -S '%D' \$pkg); do pacman -Q \$i"
  7 "Run pacdiff with Meld to compare changed configs || DIFFPROG=meld pacdiff -s" # pamac install meld
  8 "List foreign (AUR) packages || pacman -Qm"
  9 "List orphaned packages || pacman -Qdt"
  10 "Check for updates of AUR with YAY, do not update || yay -Qua" # pamac install yay
  11 "Update only AUR packages with YAY || yay -Sua" # pamac install yay
  12 "Pamac update AUR packages || pamac update --aur"
  13 "Remove orphaned packages || sudo pacman -Rsu ..."
  14 "Clean Pacman cache || sudo pacman -Scc"
  15 "Trim the root of the SSD || sudo fstrim -v /"
  16 "S.M.A.R.T. status of the disk and write cycles || sudo smartctl --all /dev/nvme0" # smartctl --scan
  17 "Show journal errors from current boot || journalctl -b -p3 --no-pager"
  18 "Show journal errors from previous boot || journalctl -b -1 -p3 --no-pager"
  19 "Dmesg || sudo dmesg"
  20 "Check for coredumps || coredumpctl"
  21 "Run Wavemonitor to check Wifi channel and strength with wavemon || wavemon" # pamac install wavemon
  22 "Read sensors || sensors"
  23 "Gather system info || inxi -zv8"
  24 "Update database for locate || sudo updatedb"
  25 "Temporary disable Ideapad battery conservation mode || sudo conservation_mode.sh 0" # pamac build conservation_mode
  26 "Show hidden spaceeaters above 100M in HOME || du -sh -t +100M ~/.cache/* ~/.config/* ~/.local/share/*"
  27 "Show journal size || journalctl --disk-usage"
  28 "Cut journal to 2 weeks || sudo journalctl --vacuum-time=2weeks"
  29 "List coredumps on disk and used space || du -sh /var/lib/systemd/coredump/"
  30 "Clear coredumps on disk || sudo rm -f /var/lib/systemd/coredump/*"
  31 "Show systemd bootlog only || journalctl -b -t systemd"
  32 "Check for missing files from packages  || sudo pacman -Qk 2>/dev/null | grep -v ' 0 missing files' "
  33 "Which package owns an existing file (paste filepath) || read fileowner; pacman -Qo \$fileowner"
  34 "Which (installed or not) package contains a file (paste filename) || read whogotit; sudo pacman -Fyx \$whogotit"
  35 "Check for flatpak updates and update || flatpak update"
  36 "Remove orphaned (unused) flatpak runtimes || flatpak uninstall --unused"
  37 "Clean flatpak cache || sudo rm -rfv /var/tmp/flatpak-cache-*"
  38 "Clean tmp bash history files and Totem stream cache || rm -f ~/.bash_history-*.tmp && rm -f ~/.cache/totem/stream-buffer/*"
  39 "A 10-20 sec. cpu benchmark using bc to calculate PI || time echo \"scale=5000; 4*a(1)\" | bc -l > /dev/null" # pamac install bc          
  )
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)

for choice in $choices
do
    case $choice in 
    1) echo "pacman-mirrors"; pacman-mirrors ;;
    2) echo "sudo pacman-mirrors -f5"; sudo pacman-mirrors -f5 ;;
    3) echo "sudo pacman -Syu"; sudo pacman -Syu ;;
    4) echo "sudo pacman -Syuw"; sudo pacman -Syuw ;;
    5) echo "sudo pacman -Syyu"; sudo pacman -Syyu ;;
    6) echo "read wantedpackage; for i in \$(expac -S '%D' \$wantedpackage); do pacman -Q \$i;  done"; read wantedpackage; for i in $(expac -S '%D' $wantedpackage); do pacman -Q $i;  done ;;
    7) echo "DIFFPROG=meld pacdiff -s"; DIFFPROG=meld pacdiff -s ;;
    8) echo "pacman -Qm"; pacman -Qm ;;
    9) echo "pacman -Qdt"; pacman -Qdt ;;
    10) echo "yay -Qua"; yay -Qua ;;
    11) echo "yay -Sua"; yay -Sua ;;
    12) echo "pamac update --aur"; pamac update --aur ;;
    13) echo "sudo pacman -Rsu $(pacman -Qtdq)"; sudo pacman -Rsu $(pacman -Qtdq) ;;
    14) echo "sudo pacman -Scc"; sudo pacman -Scc ;;
    15) echo "sudo fstrim -v /"; sudo fstrim -v / ;;
    16) echo "sudo smartctl --all /dev/nvme0"; sudo smartctl --all /dev/nvme0 ;;
    17) echo "journalctl -b -p3 --no-pager"; journalctl -b -p3 --no-pager ;;
    18) echo "journalctl -b -1 -p3 --no-pager"; journalctl -b -1 -p3 --no-pager ;;
    19) echo "sudo dmesg"; sudo dmesg ;;
    20) echo "coredumpctl"; coredumpctl ;;
    21) echo "wavemon"; wavemon ;;
    22) echo "sensors"; sensors ;;
    23) echo "inxi -zv8"; inxi -zv8 ;;
    24) echo "sudo updatedb"; sudo updatedb ;;
    25) echo "sudo conservation_mode.sh 0"; sudo conservation_mode.sh 0 ;;
    26) echo "du -sh -t +100M ~/.cache/* ~/.config/* ~/.local/share/*"; du -sh -t +100M ~/.cache/* ~/.config/* ~/.local/share/* ;;
    27) echo "journalctl --disk-usage"; journalctl --disk-usage ;;
    28) echo "sudo journalctl --vacuum-time=2weeks"; sudo journalctl --vacuum-time=2weeks ;;
    29) echo "du -sh /var/lib/systemd/coredump/"; du -sh /var/lib/systemd/coredump/ ;;
    30) echo "sudo rm -f /var/lib/systemd/coredump/*"; sudo rm -f /var/lib/systemd/coredump/* ;;
    31) echo "journalctl -b -t systemd"; journalctl -b -t systemd ;;
    32) echo "sudo pacman -Qk 2>/dev/null | grep -v ' 0 missing files' "; sudo pacman -Qk 2>/dev/null | grep -v ' 0 missing files' ;;
    33) echo "read fileowner; pacman -Qo \$fileowner"; read fileowner; pacman -Qo $fileowner ;;
    34) echo "read whogotit; sudo pacman -Fyx \$whogotit"; read whogotit; sudo pacman -Fyx $whogotit ;;
    35) echo "flatpak update"; flatpak update ;;
    36) echo "flatpak uninstall --unused"; flatpak uninstall --unused ;;
    37) echo "sudo rm -rfv /var/tmp/flatpak-cache-*"; sudo rm -rfv /var/tmp/flatpak-cache-* ;;
    38) echo "rm -f ~/.bash_history-*.tmp && rm -f ~/.cache/totem/stream-buffer/*"; rm -f ~/.bash_history-*.tmp && rm -f ~/.cache/totem/stream-buffer/* ;;
    39) echo "time echo \"scale=5000; 4*a(1)\" | bc -l > /dev/null"; time echo "scale=5000; 4*a(1)" | bc -l > /dev/null ;;

     esac
done

I just stumbled across the fact, that i have to change three places to set my device for smartctrl command.

Assuming that $options is set correctly, i removed the case-block and read the command from the array and use eval. (i think, since there is no direct user-input involved, it’s ok)

Version 11.04.2024-2 with loop and single place to edit
#!/bin/bash
# Creator: Todor Uzunov
# License: GNU - free like free speech and free beer for everybody!
# Version: 11.04.2024-2
# Changelog: try to find dependencies and compatibility mode

MODE=Xdialog
# check if dependencies are present and fall back to dialog
if ! [[ "$(which dialog)" =~ (dialog) ]] &>/dev/null; then
if ! [[ "$(which Xdialog)" =~ (Xdialog) ]] &>/dev/null; then
	echo "Xdialog dependency is not found, please install with: sudo pacman -S xdialog"
	echo "Alternatively for TUI version install dialog: sudo pacman -S xdialog"
	exit 1
fi
if ! [[ "$(which /usr/lib/gtk-2.0/2.10.0/engines/libmurrine.so)" =~ (/usr/lib/gtk-2.0/2.10.0/engines/libmurrine.so) ]] &>/dev/null; then
	echo "Libmurrine dependency is not found, please install with: sudo pacman -S gtk-engine-murrine"
	echo "Alternatively for TUI version install dialog: sudo pacman -S xdialog"
	exit 1
fi
else
if ! [[ "$(which Xdialog)" =~ (Xdialog) ]]; then
	MODE=dialog
	if [[ "$(which notify-send)" =~ (notify-send) ]]; then notify-send "Xdialog dependency is not found, please install with"  "sudo pacman -S xdialog"; fi
fi
if ! [[ "$(which /usr/lib/gtk-2.0/2.10.0/engines/libmurrine.so)" =~ (/usr/lib/gtk-2.0/2.10.0/engines/libmurrine.so) ]]; then
	MODE=dialog
	if [[ "$(which notify-send)" =~ (notify-send) ]]; then notify-send "libmurrine dependency is not found, please install with"  "sudo pacman -S gtk-engine-murrine"; fi
fi
fi
OPTIONS=(
	1 "Mirror Sync status and branch || pacman-mirrors"
	2 "Refresh the mirror list || sudo pacman-mirrors -f5" # sudo pacman-mirrors --country Germany --api --protocol https
	3 "Update all without AUR || sudo pacman -Syu"
	4 "Download all updates for offline install later || sudo pacman -Syuw"
	5 "Force refresh database and update || sudo pacman -Syyu"
	6 "Check which dependencies are already installed (paste packagename) || for i in \$(expac -S '%D' \$pkg); do pacman -Q \$i"
	7 "Run pacdiff with Meld to compare changed configs || DIFFPROG=meld pacdiff -s" # pamac install meld
	8 "List foreign (AUR) packages || pacman -Qm"
	9 "List orphaned packages || pacman -Qdt"
	10 "Check for updates of AUR with YAY, do not update || yay -Qua" # pamac install yay
	11 "Update only AUR packages with YAY || yay -Sua" # pamac install yay
	12 "Pamac update AUR packages || pamac update --aur"
	13 "Remove orphaned packages || sudo pacman -Rsu ..."
	14 "Clean Pacman cache || sudo pacman -Scc"
	15 "Trim the root of the SSD || sudo fstrim -v /"
	16 "S.M.A.R.T. status of the disk and write cycles || sudo smartctl --all /dev/sdc" # smartctl --scan
	17 "Show journal errors from current boot || journalctl -b -p3 --no-pager"
	18 "Show journal errors from previous boot || journalctl -b -1 -p3 --no-pager"
	19 "Dmesg || sudo dmesg"
	20 "Check for coredumps || coredumpctl"
	21 "Run Wavemonitor to check Wifi channel and strength with wavemon || wavemon" # pamac install wavemon
	22 "Read sensors || sensors"
	23 "Gather system info || inxi -zv8"
	24 "Update database for locate || sudo updatedb"
	25 "Temporary disable Ideapad battery conservation mode || sudo conservation_mode.sh 0" # pamac build conservation_mode
	26 "Show hidden spaceeaters above 100M in HOME || du -sh -t +100M ~/.cache/* ~/.config/* ~/.local/share/*"
	27 "Show journal size || journalctl --disk-usage"
	28 "Cut journal to 2 weeks || sudo journalctl --vacuum-time=2weeks"
	29 "List coredumps on disk and used space || du -sh /var/lib/systemd/coredump/"
	30 "Clear coredumps on disk || sudo rm -f /var/lib/systemd/coredump/*"
	31 "Show systemd bootlog only || journalctl -b -t systemd"
	32 "Check for missing files from packages  || sudo pacman -Qk 2>/dev/null | grep -v ' 0 missing files' "
	33 "Which package owns an existing file (paste filepath) || read fileowner; pacman -Qo \$fileowner"
	34 "Which (installed or not) package contains a file (paste filename) || read whogotit; sudo pacman -Fyx \$whogotit"
	35 "Check for flatpak updates and update || flatpak update"
	36 "Remove orphaned (unused) flatpak runtimes || flatpak uninstall --unused"
	37 "Clean flatpak cache || sudo rm -rfv /var/tmp/flatpak-cache-*"
	38 "Clean tmp bash history files and Totem stream cache || rm -f ~/.bash_history-*.tmp && rm -f ~/.cache/totem/stream-buffer/*"
	39 "A 10-20 sec. cpu benchmark using bc to calculate PI || time echo \"scale=5000; 4*a(1)\" | bc -l > /dev/null" # pamac install bc
)
#if you prefer TUI or have compatibility issues just replace Xdialog with dialog in the line below
CHOICE='99'
while [[ $CHOICE != '' ]]; do
	CHOICE=$($MODE --clear \
			--no-shadow \
			--scrollbar \
			--column-separator "||" \
			--separator "||" \
					--backtitle "" \
					--title "A Manjaro cheatsheet by Teo" \
			--menu "" \
					79 185 79 \
					"${OPTIONS[@]}" \
					2>&1 >/dev/tty)
	clear
	# if we use a launcher shortcut with -launcher, pause before exit
	#if [ "$1" == "-launcher" ]; then

	if [[ $CHOICE != '' ]]; then
		# get value from selected line
		CHOICETEXT=${OPTIONS[(($CHOICE * 2 - 1))]}
		# split to get command
		CHOICECMD=${CHOICETEXT##*||}
		echo "$CHOICECMD"
		eval "$CHOICECMD"
		read -n 1 -s -r -p "Press any key to return to menu.";
	fi
done
echo "ended"

I tested it and it seems to work, but be carefull with destructive commands.

Another interesting suggestion. Has to be tested, if the splitting works correctly (one or two of the commands have escaped characters in the explanation and you take it as a command).
I will see it tomorrow or in the weekend.

1 Like

Thanks for all the input and ideas and esp. @AlexBoldt i made a total rewrite. Not ideal because of eval (but well, this is never thought to be used on servers), but a lot better.
Removed is the tripling of everything, the --launcher argument, all runs now in an endless loop. Also, about a Dosen smaller refinements and nice side effects, for example with the loop sudo is remembered, commands are now more logically arranged, 1-2 strings are optimized, 1 command is removed, naming of the buttons instead of the generic “cancel”, separator between the commands, if dialog is used it does not leave a blue mess anymore, the pause screen has Q(uit) option, etc.

complete rewrite

#!/bin/bash
# Creator: Todor Uzunov 
# License: GNU - free like free speech and free beer for everybody!
# Version: 12.04.2024
# major rewrite to get rid of the tripling of everything, endless loop to stay in menu, dosens of small improvements

MODE=Xdialog
# check if dependencies are present and fall back to dialog
if ! [[ "$(which dialog)" =~ (dialog) ]] &>/dev/null; then
if ! [[ "$(which Xdialog)" =~ (Xdialog) ]] &>/dev/null; then
	echo "Xdialog dependency is not found, please install with: sudo pacman -S xdialog"
	echo "Alternatively for TUI version install dialog: sudo pacman -S xdialog"
	exit 1
fi
if ! [[ "$(which /usr/lib/gtk-2.0/2.10.0/engines/libmurrine.so)" =~ (/usr/lib/gtk-2.0/2.10.0/engines/libmurrine.so) ]] &>/dev/null; then
	echo "Libmurrine dependency is not found, please install with: sudo pacman -S gtk-engine-murrine"
	echo "Alternatively for TUI version install dialog: sudo pacman -S xdialog"
	exit 1
fi
else
if ! [[ "$(which Xdialog)" =~ (Xdialog) ]]; then
	MODE=dialog
	if [[ "$(which notify-send)" =~ (notify-send) ]]; then notify-send "Xdialog dependency is not found, please install with"  "sudo pacman -S xdialog"; fi
fi
if ! [[ "$(which /usr/lib/gtk-2.0/2.10.0/engines/libmurrine.so)" =~ (/usr/lib/gtk-2.0/2.10.0/engines/libmurrine.so) ]]; then
	MODE=dialog
	if [[ "$(which notify-send)" =~ (notify-send) ]]; then notify-send "libmurrine dependency is not found, please install with"  "sudo pacman -S gtk-engine-murrine"; fi
fi
fi
OPTIONS=(
	1 "Mirror Sync status and branch" "pacman-mirrors"
	2 "Refresh the mirror list" "sudo pacman-mirrors -f5" # sudo pacman-mirrors --country Germany --api --protocol https
	3 "Update all without AUR" "sudo pacman -Syu"
	4 "Download all updates for offline install later" "sudo pacman -Syuw"
	5 "Force refresh database and update (only for emergencies)" "sudo pacman -Syyu"
	6 "Run pacdiff with Meld to compare changed configs" "DIFFPROG=meld pacdiff -s" # pamac install meld
	7 "List foreign (AUR) packages" "pacman -Qm"
	8 "List orphaned packages" "pacman -Qdt"
	9 "Check for updates of AUR with YAY, do not update" "yay -Qua" # pamac install yay
	10 "Update only AUR packages with YAY" "yay -Sua" # pamac install yay
	11 "Pamac update AUR packages" "pamac update --aur"
	12 "Remove orphaned packages" "sudo pacman -Rsu \$(pacman -Qtdq)"
	13 "Clean Pacman cache" "sudo pacman -Scc"
	14 "Show journal errors from current boot" "journalctl -b -p3 --no-pager"
	15 "Show journal errors from previous boot" "journalctl -b -1 -p3 --no-pager"
	16 "Show systemd bootlog only" "journalctl -b -t systemd"
	17 "Show dmesg" "sudo dmesg"
	18 "Check for coredumps" "coredumpctl"
	19 "List coredumps on disk and used space" "du -sh /var/lib/systemd/coredump/"
	20 "Clear coredumps on disk" "sudo rm -f /var/lib/systemd/coredump/*"
	21 "Trim the root of the SSD" "sudo fstrim -v /"
	22 "S.M.A.R.T. status of the disk and write cycles" "sudo smartctl --all /dev/nvme0" # smartctl --scan
	23 "Run wavemonitor to check Wifi channel and strength with wavemon" "wavemon" # pamac install wavemon
	24 "Read sensors" "sensors"
	25 "Gather system info with inxi (filtered)" "inxi -zv8"
	26 "Update database for locate" "sudo updatedb"
	27 "Temporary disable Ideapad battery conservation mode" "sudo conservation_mode.sh 0" # pamac build conservation_mode
	28 "Show hidden spaceeaters above 100M in HOME" "du -sh -t +100M ~/.cache/* ~/.config/* ~/.local/share/*"
	29 "Show journal size" "journalctl --disk-usage"
	30 "Cut journal to 2 weeks" "sudo journalctl --vacuum-time=2weeks"
	31 "Check for missing files from packages" "sudo pacman -Qk 2>/dev/null | grep -v ' 0 missing files' "
	32 "Which package owns an existing file (paste filepath)" "read fileowner; pacman -Qo \$fileowner"
	33 "Which (installed or not) package contains a file (paste filename)" "read whogotit; sudo pacman -Fyx \$whogotit"
	34 "Check for flatpak updates and update" "flatpak update"
	35 "Remove orphaned (unused) flatpak runtimes" "flatpak uninstall --unused"
	36 "Clean flatpak cache" "rm -rfv /var/tmp/flatpak-cache-*"
	37 "Clean tmp bash history files and Totem stream cache" "rm -f ~/.bash_history-*.tmp && rm -f ~/.cache/totem/stream-buffer/*"
	38 "A 10-20 sec. cpu benchmark using bc to calculate PI" "time echo \"scale=5000; 4*a(1)\" | bc -l > /dev/null" # pamac install bc
)
while true; do
CHOICE=$($MODE --clear \
		--no-shadow \
		--item-help \
		--keep-tite \
		--scrollbar \
		--ok-label "Run" \
		--cancel-label "Exit" \
                --backtitle "" \
                --title "A Manjaro cheatsheet by Teo" \
		--menu "" \
                78 120 0 \
                "${OPTIONS[@]}" \
                2>&1 >/dev/tty)
#clear
[[ $CHOICE ]] || break
echo "${OPTIONS[$(($(($CHOICE*3))-1))]}"
eval "${OPTIONS[$(($(($CHOICE*3))-1))]}"
read -n 1 -s -r -p "Press any key to return to menu or q to exit." $REPLY;
echo ""
echo ""
echo "================================================="
echo ""
if [[ $REPLY == "q" ]]; then break; fi
done


1 Like

elegant rewrite. i guess, my bash skills still have a lot of potential for improvement :wink:

I am very thankful because my bash skills are more or less non-existent. I actually tried to find alternative to eval but i could not make what i found as alternatives work (like using source<() or $() ) so i kept your code.

1 Like