Sponsored Content
Top Forums Shell Programming and Scripting Paging/Scrolling a List of files for selection Post 302342434 by Festus Hagen on Sunday 9th of August 2009 07:12:36 PM
Old 08-09-2009
Paging/Scrolling a List of files for selection

Hi All,

I have the following script and would like to add page up and down functionality to be able to stroll through the list.

Is this possible?
If so, Any pointers to examples, info, tips, suggestions would be appreciated.

BTW, Any suggestion for better practices on the following code is also welcome, one cannot learn if they are not told something is incorrect!

Code:
#!/bin/sh

#set -x

CHOICE=0
ITEM=0
ITEMNUM=1
ITEMCOUNT=0

CountItemsInList()
{
# Arguments
# ITEMLIST    1

  while read ITEM
  do
    ITEMCOUNT=$(expr ${ITEMCOUNT} + 1)
  done << EOF
${1}
EOF
}

ListFiles()
{
# Arguments
# ITEMLIST    1

  ITEMNUM=1
  while read ITEM; do
    echo "${ITEMNUM} : ${ITEM}"
    ITEMNUM=$(expr ${ITEMNUM} + 1)
  done << EOF
${1}
EOF
}

ItemSelected()
{
# Arguments
# ITEMLIST    1
# CHOICE    2

  I=1
  while read ITEM; do
    if [ ${2} -eq ${I} ]; then
      break
    fi
    I=$(expr ${I} + 1)
  done << EOF
${1}
EOF
}

ITEMLIST=$(ls -dr /home/*)

CountItemsInList "${ITEMLIST}"
echo "Item count: ${ITEMCOUNT}"

while [ true ]; do
  ListFiles "${ITEMLIST}"
  echo -n " Q)uit, N)ext P)revious page or numeric Choice: "
  read CHOICE
  case ${CHOICE} in
    q|Q)
      break
    ;;
    n|N)
    ;;
    p|P)
    ;;
    [0-9]*)
      if [ ${CHOICE} -le ${ITEMCOUNT} ] && [ ! ${CHOICE} = "0" ] ; then
        ItemSelected "${ITEMLIST}" "${CHOICE}"
        echo "Selected Item: ${ITEM}"
#        break
      fi
    ;;
    *)
    ;;
  esac
done

Thanks

-Enjoy
fh : )_~
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Vi horizontal scrolling

I have to look through logfiles where lines are several hundred characters long and if I open the log in Vi it automatically word wraps the line. In Vim you can use the -nowrap option to stop this, but how can you do this in Vi? I ask because I don't want to see the whole line, just the first few... (8 Replies)
Discussion started by: rupweb
8 Replies

2. UNIX for Advanced & Expert Users

selection of files based on its types

Daily we are getting some datafiles to our unix server location FTPIN. Incoming File names will be present in the location "/xyz/test/" as below: "infile_A1_YYYYMMDD", "infile_A2_YYYYMMDD", "infile_B1_YYYYMMDD", "infile_C1_YYYYMMDD" "infile_C2_YYYYMMDD" Where A, B and C are the... (3 Replies)
Discussion started by: ganapati
3 Replies

3. UNIX for Dummies Questions & Answers

Help! scrolling numbers and letters

Hello all I am a unix newbie.... I have a sun netra t1 and it is freaking out I am connected to it through a console port, and it is just spitting out a ton on numbers and letters like below its just keeps going and going. I have tried rebooting it and I cannot get it back to any kind of a... (1 Reply)
Discussion started by: intraining11
1 Replies

4. AIX

vi scrolling issue

Hello, I am using poderosa to open a terminal in an aix box. The problem is when i use a sudo, the vi scroll doesnt work properly, It will scroll through the first page, but when it reaches the end, only the last line scrolls, not the whole screen, making it hard to read and work. Its like... (1 Reply)
Discussion started by: jinxor
1 Replies

5. Shell Programming and Scripting

scrolling cursor

Hi, I'm writing scripts in perl and shell and want to add the oprion of scrolling cursor on the screen when there is no output to the screen for long time. I saw it in some script but I don't have the source code. Are anyone know how can I perform this ? Thanks (1 Reply)
Discussion started by: Alalush
1 Replies

6. UNIX and Linux Applications

command scrolling using arrow keys

hi, can anyone tell me how to enable arrow keys to scroll thru the commands on command prompt. I am using C shell ( I know, in k shell, set -o vi would enable vi command history, but set -o doesnte exist in c shell) (4 Replies)
Discussion started by: hemangi13
4 Replies

7. Shell Programming and Scripting

selection of context in files

I have a file like this QUEUE: <ITEM(69)> "/NLA///ACHO_EQU_IDX" Q_KEY: <ITEM(69)> "/NLA///ACHO_EQU_IDX" Q_TYPE: <VSTR(32)> "GEN_VSTR_INDEX" ... (1 Reply)
Discussion started by: manas_ranjan
1 Replies

8. UNIX for Dummies Questions & Answers

Scrolling text continued

Perderabo * Unix Daemon * Join Date: Aug 2001 Location: Ashburn, Virginia Posts: 9,071 Using head and tail like that is terribly inefficient. I decided to try a rewrite. Sheesh...I spent all morning on this.... Code: #! /usr/bin/ksh # # scroller --- display text, but sleep every... (0 Replies)
Discussion started by: jamesapp
0 Replies

9. Solaris

How to view all the emails without scrolling over the screen

When I enter Solaris mail command, I get many emails on the screen on scrolling. How can I get it in one by one. BTW, if I delete the long list of emails by d command at the end, rest of the emails comes in one after other :rolleyes: Thanks... (0 Replies)
Discussion started by: wimaxpole
0 Replies

10. UNIX for Beginners Questions & Answers

Bash selection of files with similar name

Hi all, This is my first day on Linux shell!!! So, I am trying to write a script that that will pick up pairs of files with the same name (not the same content) but that are different in one character (one is *R1 the other is *R2)... Something like: look ate the files, whenever they are the... (3 Replies)
Discussion started by: ALou
3 Replies
mitem_new(3X)															     mitem_new(3X)

NAME
mitem_new - create and destroy menu items SYNOPSIS
#include <menu.h> ITEM *new_item(const char *name, const char *description); int free_item(ITEM *item); DESCRIPTION
The function new_item allocates a new item and initializes it from the name and description pointers. Please notice that the item stores only the pointers to the name and description. Those pointers must be valid during the lifetime of the item. So you should be very carefull with names or descriptions allocated on the stack of some routines. The function free_item de-allocates an item. Please notice that it is the responsibility of the application to release the memory for the name or the description of the item. RETURN VALUE
The function new_item returns NULL on error. The function free_item returns one of the following: E_OK The routine succeeded. E_SYSTEM_ERROR System error occurred (see errno). E_BAD_ARGUMENT Routine detected an incorrect or out-of-range argument. E_CONNECTED Item is connected to a menu. SEE ALSO
curses(3X), menu(3X). NOTES
The header file <menu.h> automatically includes the header file <curses.h>. PORTABILITY
These routines emulate the System V menu library. They were not supported on Version 7 or BSD versions. AUTHORS
Juergen Pfeifer. Manual pages and adaptation for new curses by Eric S. Raymond. mitem_new(3X)
All times are GMT -4. The time now is 01:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy