Pagination need enhancement.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pagination need enhancement.
# 1  
Old 01-04-2012
Pagination need enhancement.

I have below folder structure
Code:
.
|--summit
|    |----xpnldetails
|    |----trades
|    |----svar
|    |  |------checksum
|    |----xpnl
|    |----adjustment
|    |        |------summit
|    |        |------ap
|    |----risks
|    |----hypopnl
|    |----fxeffect
|    |----audittrail
|    |----xpnlmarket

Now I have a simple pagedriven script , which expect a directory and it will list the files present under that directory in kind of below format ; let's say for folder ./summit/adjustment/ap
Code:
Choice  Filename                                               Total Files: 43
===============================================================================
   1.   ap_pagination.sh
   2.   ap_reboot_services.sh
   3.   ap_sod.sh
   4.   archive.sh
   5.   bookstructure_eod.sh
   6.   call_pagination_main.sh
   7.   cashbalance_eod.sh
   8.   CheckBookStructure.sh
   9.   copy_cashbalance.sh
  10.   CopyFX.sh
  11.   createdirectory_eod.sh
  12.   CreateDirectory.sh
  13.   datediff.sh
  14.   filesorting.sh
  15.   fill_masklist.sh
  16.   fx_eod.sh
  17.   mytest_script_10.txt
  18.   mytest_script_11.txt
  19.   mytest_script_12.txt

[Choice+Enter=Select File, Enter=Next Page, 'x'=exit]
Action:

and then it will get the file name and do different actions.

Now my question, how to update this script for more maintainbility ? as below
like if I will give folder summit as input then it diginto that folder and check whether folders and/or files exist and then it list boths.
if underneath are folders, then it will display folder names as below
if underneath are files then it straight jumps or call my little script....

Code:
Choice  Foldername                                               Total Folder: xx
===============================================================================
1	  summit

[Choice+Enter=Select File, Enter=Next , - , 'x'=exit]

if I hit enter 1
then
Code:
Choice  Foldername                                               Total Folder: xx
===============================================================================
1	  xpnldetails
2	  trades
3       svar
4       adjustment 
etc
[Choice+Enter=Select File, Enter=Next , summit,'p'+Enter=Previous,  'x'=exit]

now if I enter 4
then
Code:
Choice  Foldername                                               Total Folder: xx
===============================================================================
1	  summit
2	  ap
[Choice+Enter=Select File, Enter=Next , summit/adjustment,'p'+Enter=Previous,  'x'=exit]

now if I enter 2 , it should call my pagination script for files as underneath ap there are no folders exist
(if ap have other folders then it should recursively get into that one, till the files section reached)
Code:
Choice  Filename                                               Total Files: 43
===============================================================================
  20.   mytest_script_13.txt
  21.   mytest_script_14.txt
  22.   mytest_script_15.txt
  23.   mytest_script_16.txt
  24.   mytest_script_17.txt
  25.   mytest_script_18.txt
  26.   mytest_script_19.txt
  27.   mytest_script_1.txt
  28.   mytest_script_20.txt
  29.   mytest_script_21.txt
  30.   mytest_script_22.txt
  31.   mytest_script_23.txt
  32.   mytest_script_24.txt
  33.   mytest_script_25.txt
  34.   mytest_script_2.txt
  35.   mytest_script_3.txt
  36.   mytest_script_4.txt
  37.   mytest_script_5.txt
  38.   mytest_script_6.txt

[Choice+Enter=Select File, Enter=Next Page, summit/adjustment/ap, 'p'+Enter=Previous Page, 'x'=exit]
Action: x

can anyone help me out?

My main script for file listing goes like this,
Code:
BASEDIR=$1
RETURN="0"

if [[ ! -d ${BASEDIR} ]]; then
        clear
        printf "\n\n%s is not a valid input directory. Please provide a valid directory!\n\n" ${BASEDIR}
        unset BASEDIR
        return 1
fi

# Read files into Array
totFiles=1
for FILE in $(cd ${BASEDIR};ls -A)
do
        if [ -f ${BASEDIR}/${FILE} ]; then
                filesArray[${totFiles}]=${FILE}
                totFiles=`expr ${totFiles} + 1`
        fi
done

unset FILE

if [[ ${totFiles} -eq 1 ]]; then
        clear
        printf "\n\nDirectory %s is empty!\n\n" ${BASEDIR}
        unset BASEDIR
        return 1
fi

# Start display function / Pagination
# fetch the size of the window

sSize=$(resize | grep LINES= | awk -F= '{ print $2 }' | sed 's/;//g')
sSize=$(expr ${sSize} - 5)

skip=0
page=0
FILENAME=""

while [ "${skip}" == "0" ];
do
        dAction="continue"
        cpt=$(expr ${page} \* ${sSize})
        cpt=$(expr ${cpt} + 1)
        end=$(expr ${cpt} + ${sSize})

        clear
        printf "Choice  Filename                                          %20s\n" "Total Files: "${totFiles}
        printf "===============================================================================\n"

        while [ "${cpt}" != "${end}" ]
        do
                printf "%4s.   %s\n" ${cpt} ${filesArray[${cpt}]}
                cpt=$(expr ${cpt} + 1)

                if [ "${cpt}" == "${totFiles}" ]; then
                        dAction="end"
                        break
                fi
        done

        case ${dAction} in
        end)
                if [ "${page}" == "0" ]; then
                        printf "\n[Choice+Enter=Select File, 'x'=exit]\nAction: "
                else
                        printf "\n[Enter=Next Page, 'p'+Enter=Previous Page, 'x'=exit]\nAction: "
                fi;;
        *)      if [ "${page}" == "0" ]; then
                        printf "\n[Choice+Enter=Select File, Enter=Next Page, 'x'=exit]\nAction: "
                else
                        printf "\n[Choice+Enter=Select File, Enter=Next Page, 'p'+Enter=Previous Page, 'x'=exit]\nAction: "
                fi;;
        esac

        read answer

        if [ "${answer}" == "" ]; then
                answer="empty"
        fi

        answer=$(echo ${answer} | tr '[A-Z]' '[a-z]')

        case ${answer} in
        0)      page=0 ;;
        x)      RETURN="1"
                break;;
        p)      page=$(expr ${page} - 1)
                if [ "${page}" == "-1" ]; then
                        page="0"
                fi;;
        *)      choice=$(echo ${answer} ${totFiles} | awk '{
                a=int($1);
                b=int($2);

                if (a>=b) print 0;
                else print a;
                }')

                if [ "${choice}" != "0" ]; then
                        FILENAME=${filesArray[${choice}]}

                        printf "\nFile '%s' has been selected, is this OK (Yes/<none>): " ${FILENAME}
                        read answer

                        answer=$(echo ${answer} | tr '[A-Z]' '[a-z]')
                        if [ "${answer}" == "yes" ] || [ "${answer}" == "y" ]; then
                                FILENAME=${FILENAME}
                                skip="1"
                        else
                                FILENAME=""
                        fi
                fi

                if [ "${dAction}" != "end" ]; then
                        page=$(expr ${page} + 1)
                fi;;
        esac
done

unset skip
unset sSize
unset cpt
unset end
unset answer
unset choice
unset dAction
unset page
unset BASEDIR

return ${RETURN}

Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unix script enhancement

Hi, Please help me out with this new enhancment with this shell script which i have written below. ******************************************************** #!/bin/ksh #File contains Only New Records that sent in the Current Load export ORACLE_BASE=/oracle export... (18 Replies)
Discussion started by: msrahman
18 Replies

2. UNIX for Dummies Questions & Answers

Linux Multipath Enhancement

Hi.. when i delete a Lun from a Array on a SAN, and again when i create a Lun it shows that the newly created Lun has the ID of the Old deleted Lun which is leading to data corruption. All this is handled by the Multipath software. can anybody help. (0 Replies)
Discussion started by: Praveen13
0 Replies

3. UNIX for Advanced & Expert Users

Linux Multipathing Enhancement

We are searching for DEVICE MAPPER TABLE FORMAT and how to access it through user space?? We are working on enhancement in multipatrhing as 1] scalable path testing 2] event mechanism 3] i/o load sharing. So we need to access device info as well as all paths to that device, devices status,paths... (1 Reply)
Discussion started by: rajaryan99
1 Replies
Login or Register to Ask a Question