Skip to content

Instantly share code, notes, and snippets.

@projectivemotion
Last active February 14, 2021 07:17
Show Gist options
  • Select an option

  • Save projectivemotion/0ba0f4049cc28b4edff5865ff97b7958 to your computer and use it in GitHub Desktop.

Select an option

Save projectivemotion/0ba0f4049cc28b4edff5865ff97b7958 to your computer and use it in GitHub Desktop.

Revisions

  1. projectivemotion revised this gist Feb 14, 2021. 1 changed file with 5 additions and 8 deletions.
    13 changes: 5 additions & 8 deletions zenneby.sh
    Original file line number Diff line number Diff line change
    @@ -8,20 +8,16 @@

    cd $(dirname "$0")

    declare -a sections
    declare -A vars

    function read_ini(){
    if [ ! -f ./run.ini ] ; then
    cat << EOF > ./run.ini
    [hello-from-zenity]
    run=zenity --info --text "Hello from Zenity"
    title="Zenity"
    [gedit]
    run=gedit run.ini
    title="Edit run.ini"
    [sleep]
    run=sleep 5
    title="Sleep for 5 seconds"
    @@ -47,11 +43,13 @@ if [[ 1 -eq $? ]] ; then
    exit 1
    fi

    read_ini

    exitnow=0
    while [[ 0 -eq $exitnow ]]; do

    declare -a sections
    declare -A vars
    read_ini

    declare -a rows
    for section in "${sections[@]}" ; do
    run="section_${section}_run"
    @@ -70,6 +68,5 @@ while [[ 0 -eq $exitnow ]]; do
    echo $(date): $chosen
    eval $chosen
    fi
    unset rows
    unset rows sections vars
    done

  2. projectivemotion revised this gist Feb 14, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions zenneby.sh
    Original file line number Diff line number Diff line change
    @@ -19,8 +19,8 @@ run=zenity --info --text "Hello from Zenity"
    title="Zenity"
    [gedit]
    run=gedit
    title="Open Gedit"
    run=gedit run.ini
    title="Edit run.ini"
    [sleep]
    run=sleep 5
  3. projectivemotion created this gist Feb 14, 2021.
    75 changes: 75 additions & 0 deletions zenneby.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,75 @@
    #!/bin/bash
    # github.com/projectivemotion
    #
    # This script displays a listbox and allows a user
    # to select and execute any of the commands from a given
    # ini file. (run.ini)
    #

    cd $(dirname "$0")

    declare -a sections
    declare -A vars

    function read_ini(){
    if [ ! -f ./run.ini ] ; then
    cat << EOF > ./run.ini
    [hello-from-zenity]
    run=zenity --info --text "Hello from Zenity"
    title="Zenity"
    [gedit]
    run=gedit
    title="Open Gedit"
    [sleep]
    run=sleep 5
    title="Sleep for 5 seconds"
    EOF
    fi

    section=""
    while IFS='=]' read vleft vright
    do
    if [[ $vleft == \[* ]] ; then
    section=${vleft/[/}
    sections+=("$section")
    elif [[ $vright ]] ; then
    todeclare="section_${section}_$vleft"
    vars[$todeclare]="$vright"
    fi
    done < ./run.ini
    }

    which zenity 2>&1 >/dev/null
    if [[ 1 -eq $? ]] ; then
    echo "Please install zenity."
    exit 1
    fi

    read_ini

    exitnow=0
    while [[ 0 -eq $exitnow ]]; do

    declare -a rows
    for section in "${sections[@]}" ; do
    run="section_${section}_run"
    title="section_${section}_title"
    rows+=("$section" "${vars[$title]}" "${vars[$run]}")
    done

    chosen=$(zenity --height 300 --width 800 --list \
    --title="Choose the command you wish to execute." \
    --column="Section" --column="Title" --column="Cmd" \
    --print-column=3 \
    "${rows[@]}")
    exitnow=$?

    if [[ 0 -eq $exitnow ]] ; then
    echo $(date): $chosen
    eval $chosen
    fi
    unset rows
    done