Skip to content

Allows a bash script to use the best available TUI or GUI dialog system

License

Notifications You must be signed in to change notification settings

lunarcloud/script-dialog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

script-dialog

GitHub License GitHub top language

Code Quality

Create bash scripts that utilize the best dialog system that is available. Intended for Linux, but has been tested on macOS and Windows, and should work on other unix-like OSs.

  • If it's launched from a GUI (like a .desktop shortcut or the dolphin file manager),
    1. It will prefer kdialog in Qt-based desktops and zenity in other environments.
    2. If neither of those are available, then relaunch-if-not-visible will relaunch the app in a terminal so that a terminal UI can be used.
  • If it's launched in a terminal,
    1. It will use whiptail or dialog.
    2. If neither of those are available, then it will fallback to basic terminal input/output with tools like read and echo.

To Use

Source script-dialog.sh. Then use the library's variables and functions. The test.sh script will contain examples of each feature.

The following example assumes it's in the same folder as your script:

    SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    source "${SCRIPT_DIR}"/script-dialog.sh

    APP_NAME="My Utility Script"

    ACTIVITY="Intro"
    message-info "Hello!"

FAQ

Scripts open in a text editor instead of running, what gives? One of 2 things has happened:

  • The script has not been marked as "executable" in it's permission properties.

    That's the execute bit, chmod +x test.sh, for you terminal folks.

  • Some desktop environments do this as default script behavior, assuming scripts are only run from terminal and edited from GUIs.

    You may have to change your file manager preferences on scripts or "Executable Text Files", or right click and choose to "Run As Program".

    The latter option may run the script in a terminal instead of GUI. Not much can be done about "GNOME choses to force scripts to open via terminal" type issues. If this is for a permanent script, create an application shortcut (by creating a .desktop file in $HOME/.local/share/applications/).

Global Variables

Name Use Description
APP_NAME User-defined The script's app name, for title bars
ACTIVITY User-defined The current activity, for title bars
INTERFACE Override or Detected the GUI or TUI to use
GUI Detected Whether the interface is a GUI not TUI
DETECTED_DESKTOP Detected Desktop in use
NOCOLORS Optional override disables otherwise-detected use of colored/bolded text basic CLI
NOSYMBOLS Optional override disables otherwise-detected use of unicode symbols in TUIs
ZENITY_HEIGHT Optional override height of zenity dialogs
ZENITY_WIDTH Optional override width of zenity dialogs

Functions

Name Description Arguments Output or Return
superuser Attempts to run a priviledged command (sudo or eqiuvalent) Command to run with elevated priviledge return code 0 if success, non-zero otherwise
relaunch-if-not-visible if neither GUI nor terminal interfaces can be used, relaunch the script in a terminal emulator
message-info Display an 'info' message box The text to display
message-warn Display a 'warning' message box The text to display
message-error Display an 'error' message box The text to display
messagebox Display a message box The text to display
yesno Display a yes-no decision message box The text to display return code 0 if yes, 1 if no
inputbox Display a text input box
  1. The text to display
  2. The initial input value
the entered text
userandpassword Display a (single or series of) input box(es) for entering a username and a password
  1. The name of the username variable
  2. The name of the password variable
  3. The initial username input value
  4. The text to display for username entry
  5. The text to display for password entry
password Display an input box for entering a password The text to display for password entry the entered text
display-file Display the contents of a file
  1. The file whose text to display
  2. width of GUI display (512 if omitted)
  3. height of GUI display (640 if omitted)
checklist Display a list of multiply-selectable items
  1. The file whose text to display
  2. Number of options
  3. First item's value
  4. First item's description
  5. First item's default checked status (ON or OFF)
  6. (repeat for all items)
Value text of the selected item (or the default item)
radiolist Display a list of singularly-selectable items
  1. The file whose text to display
  2. Number of options
  3. First item's value
  4. First item's description
  5. First item's default selected status (ON or OFF)
  6. (repeat for all items)
Value text of the selected item (or the default item)
progressbar A pipe that displays a progressbar the current value of the bar (repeatable, should be piped)
progressbar_update Updates the value of the progressbar (call from within the progressbar piped block)
  1. the new percentage value/li>
  2. the new status text
progressbar_finish Completes the the progressbar (call from within the progressbar piped block)
filepicker Display a file selector dialog
  1. The starting folder
  2. "save" or "open" (assume "open" if omitted)
Path to selected file
folderpicker Display a folder selector dialog The starting folder Path to selected folder
datepicker Display a calendar date selector dialog The starting folder Selected date text (DD/MM/YYYY)

About

Allows a bash script to use the best available TUI or GUI dialog system

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages