Is there an alternative to whiptail for macOS?

I would like to try out a shell script that makes use of whiptail, but I am on a MAC and whiptail doesn't seem to exist there. Does anyone know if there exists a drop-in alternative (like, for example exa for ls)?

This is the script I would like to test out (It's a WP-CLI script that would allow me to select local WordPress installs, using a dialog. Found it at the bottom of this page):

#!/bin/bash

WP_TOP_PATH="/home/"
MENU_TEXT="Choose an installation"
GAUGE_TEXT="Searching for WordPress"

declare -a MENU
WPS="$(wp --allow-root find "$WP_TOP_PATH" --field=version_path)"
WP_TOTAL="$(wc -l <<< "$WPS")"
WP_COUNT="0"

while read -r WP; do
    WP_LOCAL="${WP%wp-includes/version.php}"

    NAME="$(cd "$WP_LOCAL"; sudo -u "$(stat . -c %U)" -- wp --no-debug --quiet option get blogname)"
    if [ -z "$NAME" ]; then
        NAME="(unknown)"
    fi
    MENU+=( "$WP_LOCAL" "$NAME" )

    echo "$((++WP_COUNT * 100 / WP_TOTAL))".
done <<< "$WPS" > >(whiptail --gauge "$GAUGE_TEXT" 7 74 0)

WP_LOCAL="$(whiptail --title "WordPress" --menu "$MENU_TEXT"  $((${#MENU[*]} / 2 + 7)) 74 10 "${MENU[@]}" 3>&1 1>&2 2>&3)"

if [ $? -ne 0 ] || [ ! -d "$WP_LOCAL" ]; then
    echo "Cannot find '${WP_LOCAL}'" 1>&2
    exit 100
fi

echo "cd ${WP_LOCAL}"

Solution 1:

I would start with brew install dialog from https://brew.sh and then

alias whiptail=dialog

Hopefully you don’t have to alter your script other than dropping the alias as a new line 3 in your script. For people not already using Wordpress on other Unix, the Apple specific apps and installers seem like a great option as well due to extensive documentation and native apps.

  • https://wordpress.org/download/

Lastly, if you find you need whiptail, containers are a great option so you don’t have to fork your tools and edit scripts.

  • https://localwp.com/

Solution 2:

Thanks to the answer of bmike and the comment from @nohillside I was able to make this work. After running brew install dialog, I put this in my ~/.bashrc:

alias whiptail=dialog

And to make my script actually respect the alias, I followed the instructions found here and put this in my script at the very beginning:

#!/bin/bash

shopt -s expand_aliases
source ~/.bashrc