Topic
2 replies Latest Post - ‏2005-10-05T13:02:31Z by SystemAdmin
SystemAdmin
SystemAdmin
232 Posts
ACCEPTED ANSWER

Pinned topic Menu system for scripts

‏2005-02-11T10:46:37Z |
Old enough to have used IBM's fixed disk organizer which is what is sorely needed for linux CLI. So what do you use to keep track of your scripts and hopefully execute them from a centralized menu?
Be nice if IBM would release an open source linux version of the old DOS fixed disk organizer!
Updated on 2005-10-05T13:02:31Z at 2005-10-05T13:02:31Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    232 Posts
    ACCEPTED ANSWER

    Re: Menu system for scripts

    ‏2005-06-09T23:10:08Z  in response to SystemAdmin
    > Old enough to have used IBM's fixed disk organizer
    > which is what is sorely needed for linux CLI. So what
    > do you use to keep track of your scripts and
    > hopefully execute them from a centralized menu?
    > Be nice if IBM would release an open source linux
    > version of the old DOS fixed disk organizer!

    The most popular command line "menu" system I am aware of is Midnight Commander though I'm sure others exist.

    A minimalist solution might be to rig your own menu system...

    #!/bin/sh
    echo "1. foo"
    echo "2. bar"
    read choice
    case $choice in
    1) ./shell_script_1
    ;;
    2) ./shell_script_2
    ;;
    *) echo "unknown choice"
    esac

    The above script prints a simple menu and lets the user choose which script to execute.
  • SystemAdmin
    SystemAdmin
    232 Posts
    ACCEPTED ANSWER

    Re: Menu system for scripts

    ‏2005-10-05T13:02:31Z  in response to SystemAdmin
    This works for me

    #!/usr/bin/perl
    1. General purpose menu front end.
    2. Simon Taylor - IBM, May 21, 2001
    3. simonta@za.ibm.com
    #
    1. Menu format rules (place in each menu file)
    2. 1. All lines where the first non-blank character is '#' are comments.
    3. 2. Any line may be a comment line.
    4. 3. No blank lines are permitted.
    5. 4. Menu options and commands are separated by a ':' character.
    6. example (no quotes needed) "list current directory":ls
    7. 5. The first line without a ':' is the heading.
    8. 6. There should be only one heading line.
    9. 7. Commands must be entered exactly as they would be entered on the command line
    10. 8. The heading should be less than 40 characters long.
    11. 9. Menu options should be less than 70 characters long.
    12. 10. A line with a single ':' makes a blank line separator.
    #
    ################################################################################
    $args=$#ARGV+1;
    $ThisProg=$0;
    $thispath=`dirname $ThisProg`;
    chomp($thispath);
    if ( $args == 1 ) {
    $menufile=$ARGV[0];
    chomp($menufile);
    } else {
    $menufile=$thispath."/../menus/main.mnu";
    }
    open (MENUFILE, $menufile) or
    die "Can't open $menufile, stopped";
    1. Read the menu file
    $i=0;
    while (<MENUFILE>) {
    chomp; # avoid \n on last field
    if ( $_ !~ /\s?#/ ) {
    if ( ( $Idx = index($_ , ":" )) == -1) {
    $MenuOpt[0]=$_;
    } else {
    $i++;
    $Idx = index($_ , ":" );
    $MenuOpt$i=substr($_, 0, $Idx);
    $MenuCmd$i=substr($_, $Idx+1);
    }
    }
    }
    $menulen=$#MenuOpt + 1;
    1. Display the menu
    $blanks = " " x 78;
    $dayt=`date|cut -c-19`;

    chomp($dayt);
    $headlen=length($MenuOpt[0]);
    $hfm=39-($headlen/2);
    $spc1=" " x $hfm;
    $headlin=$spc1 . $MenuOpt[0];
    $hfm=80-(length($headlin));

    $spc=" " x 60;
    $datelin=$spc . $dayt;

    $go=1;
    while ( $go > 0 ){
    $i=1;
    system("clear");
    print "\n$headlin\n";
    print "$datelin\n\n";

    while ( $i < $menulen ) {
    if (length($MenuCmd$i) == 0) {
    print "\n";
    } else {
    $pline=sprintf("%2s %s", $i, $MenuOpt$i);
    print "$pline" . "\n";
    }
    $i++;
    }
    print "\n";
    print "Enter q ";
    $ans= <STDIN>;
    chomp($ans);
    if ($ans == 0 && $ans ne "0") {
    if ( $ans eq "q" ) {
    #$go=0;
    exit(0);
    }
    } else {
    if ( ( $ans > 0 ) && ( $ans < $menulen ) ) {
    system("clear");
    system($MenuCmd$ans);
    if ( index($MenuCmd$ans , "$ThisProg") == -1) {
    print "Enter to continue ";
    $junk = <STDIN>;
    }
    }
    }
    }