Sponsored Content
Top Forums Shell Programming and Scripting Dynamic Bash Dialog from directory listing Post 303021070 by shrout1 on Friday 3rd of August 2018 12:17:50 PM
Old 08-03-2018
Ok! A coworker helped me noodle this through; turns out the input required for dialog is rather odd...

Code:
#! /bin/bash
#usage: Dynamic_Menu.bash /home/user/target_directory
declare -a array

i=1 #Index counter for adding to array
j=1 #Option menu value generator

while read line
do		
#Dynamic dialogs require an array that has a staggered structure
#array[1]=1
#array[2]=First_Menu_Option
#array[3]=2
#array[4]=Second_Menu_Option

	array[ $i ]=$j
	(( j++ ))
	array[ ($i + 1) ]=$line
        (( i=($i+2) ))
	
done < <(find $1 -type f) #consume file path provided as argument

##uncomment for debug
#printf '%s\n' "${array[@]}"
#read -rsp "Press any key to continue..." -n1 key

#Build the menu with dynamic content
TERMINAL=$(tty) #Gather current terminal session for appropriate redirection
HEIGHT=20
WIDTH=76
CHOICE_HEIGHT=16
BACKTITLE="Back_Title"
TITLE="Dynamic Dialog"
MENU="Choose a file:"

CHOICE=$(dialog --clear \
                --backtitle "$BACKTITLE" \
                --title "$TITLE" \
                --menu "$MENU" \
                $HEIGHT $WIDTH $CHOICE_HEIGHT \
                "${array[@]}" \
                2>&1 >$TERMINAL)

I haven't fully debugged this yet, but from a directory with less than 10 files it's working!

Last edited by shrout1; 08-03-2018 at 05:10 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies

2. UNIX for Dummies Questions & Answers

Timestamp in directory listing

Hi, I need a help. I want to see all the files in the directory with the Time Stamp. I use the following command. $ls -lt This displays the files with time stamp, but not all the files. Only last few months, the files are displayed with timestamp, the old files are only have dates. ... (2 Replies)
Discussion started by: vijashok
2 Replies

3. UNIX for Dummies Questions & Answers

Full Directory Listing...

Is there a way of listing everything under a directory. So for example if you wanted to know everything under the USR directory you would get all the sub directories and files in those directories as well as the file directly under the USR directory. I would imagine that you could do this... (5 Replies)
Discussion started by: B14speedfreak
5 Replies

4. UNIX for Dummies Questions & Answers

How can i get directory listing?

Hai friends is there any command in unix that display only directories... (I have 5 directories in my home directory, and i also have some files along with directories...But when i tried to show the directory listing using the command ls -d i wasn't presented by the directory listing...Please... (2 Replies)
Discussion started by: haisubbu
2 Replies

5. Shell Programming and Scripting

Unix / Linux Dialog Utility - how to open 2+ more dialog windows ?

Hi, example of Unix / Linux dialog utility is below. I am going to use dialog as simple GUI for testing of a modem. So I need to combine some dialog boxes into one. I need to have input box, output box, info box, dialog box, radiobox as in any standard program with graphical user... (2 Replies)
Discussion started by: jack2
2 Replies

6. Shell Programming and Scripting

Directory Listing Help

i have searched through this site and have found some useful information but i'm struggling with one thing. In my script i am created a start and end file so I can get a listing of the files within those two files. However I want to exclude any sub-directories in this listing. Below are the... (8 Replies)
Discussion started by: J-DUB
8 Replies

7. Shell Programming and Scripting

Directory listing

Hi, I have a directory with a bunch of files say around 150K. I want the directory's path and the filenames printed to a text file. Example: If I am in the directory /path/test and the files in this directory are My output file should be like this Thanks in advance ----------... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

8. Homework & Coursework Questions

Listing the files in a directory

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: A script that takes any number of directories as command line arguments and then lists the contents of each of... (3 Replies)
Discussion started by: Phaneendra G
3 Replies

9. Shell Programming and Scripting

Dynamic variable name in bash

Hello, I'm trying to build a small script to store a command into a dynamic variable, and I have trouble assigning the variable. #!/bin/bash declare -a var1array=("value1" "value2" "value3") var1arraylength=${#var1array} for (( i=1; i<${var1arraylength}+1; i++ )); do mkdir... (7 Replies)
Discussion started by: alex2005
7 Replies

10. Shell Programming and Scripting

Require input in bash dialog box

Hello. Any help would be greatly appreciated. Right now I have the following input box that works fine and well, however I would like to wrap this is a loop that requires input. Right now the script will happily continue on if the user just hits enter. I'd like to require a minimum of a 5... (5 Replies)
Discussion started by: woodson2
5 Replies
OP_VISUALISE(1) 														   OP_VISUALISE(1)

NAME
op_visualise - graphically display and annotate oprofile sample files SYNOPSIS
op_visualise [ -Sdirectory ] [ --samples-directory=directory ] [ -Bdirectory ] [ --binaries-directory=directory ] [ -sfile ] [ --samples- file=file ] [ -bfile ] [ --executable=file ] [ -ifile ] [ --initialisation-file=file ] [ -h ] [ --help ] DESCRIPTION
op_visualise is a tool that helps you visualise and interpret the data that oprofile collects. Specifically, it: o Graphically represents, and allows interaction with, the oprofile sample count histogram. o Allows the histogram to be captured in various formats (such as Postscript). o Displays information relevant to selected addresses. "OPTIONS DESCRIPTIONS" -S, --samples-directory= Specifies the directory containing the oprofile samples. Defaults to /var/lib/oprofile/samples. -B, --binaries-directory= Specifies the root directory used to locate the executable file associated with a given sample file. This defaults to / (root). If it is set to any other directory name, that name is prepended to the filename associated with the sample file. For example, if the option -B /home/moller/bin-archive is specified and the executable being sampled is /bin/bash, op_visualise will look for /home/moller/bin-archive/bin/bash. This is to allow multiple copies of executables to be archived for comparison and analysis. -s, --samples-file= Specifies the oprofile sample file to be displayed. The file is located as usual, that is, either absolutely, if it starts with a ``/'', or with respect to the current working directory otherwise. op_visualise does not use the directory specified by the -S, --samples- directory= option (or its default) to locate the sample file. (The use of the --samples-directory= is described in the section describ- ing the Set Sample Dir...(C-d) menu.) -s, --executable= Specifies the executable file against which to apply the samples file. Like the samples file this file is located as usual, without respect to the directory specified by the -B, --binaries-directory= option (or its default), the use of which is described in the section describing the Open Sample...(C-s) menu. -i, --initialisation-file= Specifies the name of an initialisation file that can be used to set any of the above options. The initialisation file consists of one or more text lines in the form of: tag : value where tag is one of: samples-directory binaries-directory samples-file executable and value is the value to be associated with that tag. MAIN MENU
The following is a description of the operations available under the main op_visualise menu. FILE MENU (M-F) SET SAMPLE DIR...(C-D) Opens a standard file selection dialog allowing you to select the directory containing oprofile samples. (See the description of the --samples-directory option above.) SET EXECUTABLES ROOT...(C-R) Opens a standard file selection dialog allowing you to select the executable's root directory. (See the description of the --binaries- directory option above.) OPEN SAMPLE...(C-S) Opens a file selection dialog allowing you to select the an oprofile sample file to display. The initial directory displayed is the one identified by either the --samples-directory option or the Set Sample Dir...(C-d) menu. After a file is selected, another dialog will be presented asking if the corresponding binary file should be opened as well. SELECT BINARY...(C-B) Opens a file selection dialog allowing you to select the an executable file to display. The initial directory displayed is the one identi- fied by either the --binaries-directory option or the Set Executables Root...(C-r) menu. After a file is selected, another dialog will be presented asking if the corresponding samples file should be opened as well. PRINT CHART...(C-P) Opens a dialog that allows you to capture the current histogram as an image in any of a number of formats, such as Postscript or GIF. (The exact options will vary depending on what capabilities are installed; if no plot capabilities are installed, this menu will not be avail- able.) QUIT (C-Q) Exit op_visualise. HELP MENU (M-H) USAGE Displays this manual. ABOUT Displays copyright and contact information. BUTTONS
SAMPLES The Samples button is a shortcut to the Open Sample...(C-s) menu. It is associated with a text label identifying the selected file. EXECUTABLES The Samples button is a shortcut to the Select Binary...(C-b) menu. It is associated with a text label identifying the selected file. TOOLBAR
The toolbar allows you to display data of various types. FUNCTIONS The Functions button (denoted by a ``{}'' glyph) opens a dialog listing the functions that make up the executable currently selected. Selecting a function name will narrow the histogram display to include just that function. (The button produces useful results only if the selected executable contains debugging information.) FILES The Files button (denoted by a ``File'' glyph) opens a dialog listing the files that compose the source of the executable currently selected. Selecting a file name will narrow the histogram display to include just that file. (The button produces useful results only if the selected executable contains debugging information.) SYSTEM The System button (denoted by a ``Filesystem'' glyph) opens a dialog listing the executables for which samples exist in the currently selected samples directory. (Future versions of op_visualise may allow selection of any of the list entries to specify a samples/exe- cutable pair.) STATUS LINE
The status line displays errors or information relevant to the executable address associated with the current location of the pointer in the histogram window. HISTOGRAM WINDOW
The histogram window graphically depicts the number of oprofile sample hits associated with each address contained in the selected exe- cutable. As the pointer is moved within this window, the status line will show such information as the number of hits, the function name, and the file name and line number associated with the address corresponding to the location of the pointer. (The precise nature of the information presented depends on what is available in the executable.) The pointer buttons may be used to select the scope of the histogram. Button 1 will zoom in by a factor of 2 around the current location, button 3 will similarly zoom out, and button 2 will return the scope to encompass the entire executable. 14 February 2003 OP_VISUALISE(1)
All times are GMT -4. The time now is 03:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy