moving cursor up and other things


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting moving cursor up and other things
# 1  
Old 11-28-2008
moving cursor up and other things

Hi guys, this is how my script looks like so far:

height=$(($(tput lines) -2))

echo 'Owner Group Other Filename'
echo '----- ----- ----- --------'
echo
cd $directory
path=$(pwd)

levels=0
level=$(($(echo $path | tr '/' ' ' | wc -w) +1))

for dir in / $(echo $path | tr '/' ' ' )
do
cd $dir
levels=$((levels +1))
echo "$(ls -ld | cut -c2-10 | sed 's/.\{3\}/& /' | sed 's/.\{7\}/& /' | sed 's/.\{1\}/& /g') $dir"
echo
done


tput cup $((height)) 0
printf "Valid commands: u(p) d(own) q(uit)"

tput cup $((level * 2 + 4)) 25

#----------------------------I am having problem from here below-------------------------------------

oldsettings=$(stty -g)
stty -icanon min 1 time 0 -echo
key='u'

read key
while [ "$key" != "q" ]
do
if [ "$key" = "u" ]
then tput cup "$((level +1))"
elif [ "$key" = "q" ]
then exit 0
fi
done

stty $oldsettings


--------------------------------------------------------------


This is kinda confusing on how this script works. If you don't know how it works, just paste the code and try it.

Okay, what I'm trying to accomplish is that when this script is executed ( usage : scriptname directory-name-in-the-current-directory ) the cursor is supposed to be on the first letter of the current directory's name.

Then when the user presses the "u" key, the cursor will go up, which is the parent directory of the current directory. So it will keep going up till it hits the root directory.

And same with the "d" key. When "d" is pressed, it will go down until it hits the current directory.

And finally, when the user enters the "q" key, the script will quit.

I would appreciate a lot if someone can fix the script.

Please try to response asap.

Thank you.

Last edited by darkhider; 11-29-2008 at 01:48 PM..
# 2  
Old 11-29-2008
I'm still trying to figure out on what I'm doing wrong. Any help is greatly appreciated.
# 3  
Old 11-30-2008
Quote:
Originally Posted by darkhider
Hi guys, this is how my script looks like so far:

Please put code inside [code] tags.

And please keep line lengths to less than approximately 80 characters.
Quote:
Code:
height=$(($(tput lines) -2))

echo 'Owner   Group   Other    Filename'
echo '-----   -----   -----    --------'
echo
cd $directory
path=$(pwd)


There's no need for command substitution which is slow in all shells except ksh93. The current directory is stored in the PWD variable:

Code:
path=$PWD

Quote:
Code:
levels=0 
level=$(($(echo $path | tr '/' ' ' | wc -w) +1))
   
for dir in / $(echo $path | tr '/' ' ' )
do
cd $dir
levels=$((levels +1))
echo "$(ls -ld | cut -c2-10 | sed 's/.\{3\}/& /' |
 sed 's/.\{7\}/& /' | sed 's/.\{1\}/& /g')   $dir"
echo 
done


Code:
oldIFS=$IFS
IFS=/
set -- $path
level=$#
set -- "/$@"
IFS=$oldIFS

for dir
do
  cd $dir || exit
  levels=$(( $levels + 1 ))
  printf "%s   %s\n\n" "$(
   ls -ld |
    sed  -e 's/.\(...\)\(...\)\(...\).*/\1 \2 \3/' -e 's/./& /g'
   )" "$dir"
done

Quote:
Code:
tput cup $((height)) 0
printf "Valid commands: u(p) d(own) q(uit)"

tput cup $((level * 2 + 4)) 25

#----------------------------I am having problem from here 
# below-------------------------------------


Then that's the part you should post. Always post just enough of your code to demonstrate the problem. Use some simple statements to set things up if you have to.
Quote:
Code:
oldsettings=$(stty -g)
stty -icanon min 1 time 0 -echo
key='u'

read key
while [ "$key" != "q" ]


Code:
How do you expect the value of $key to change? You have read outside the loop.

Quote:
Code:
do
if [ "$key" = "u" ]
then tput cup "$((level +1))"
elif [ "$key" = "q" ]
then exit 0
fi
done  

stty $oldsettings

--------------------------------------------------------------


This is kinda confusing on how this script works. If you don't know how it works, just paste the code and try it.

Okay, what I'm trying to accomplish is that when this script is executed ( usage : scriptname directory-name-in-the-current-directory ) the cursor is supposed to be on the first letter of the current directory's name.

Then when the user presses the "u" key, the cursor will go up, which is the parent directory of the current directory. So it will keep going up till it hits the root directory.

And same with the "d" key. When "d" is pressed, it will go down until it hits the current directory.

How is "d" going to affect anything? You don't have any code to deal with it.
Quote:

And finally, when the user enters the "q" key, the script will quit.

I would appreciate a lot if someone can fix the script.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Passing the value of a cursor to another cursor

i have 2 cursors. i want to assign the value of first cursor(employee_id) to the where condition of cursor c2(please refer the bold statement). how do i do if i want to assign the value of c1 to where condition of cursor c2? declare cursor c1 IS select employee_id from employee cursor c2... (1 Reply)
Discussion started by: vkca
1 Replies

2. Shell Programming and Scripting

Getting the cursor position

I need to get the cursor position, and put it inside a variable. Problem is, i don't have the tput command, or ncurses. Apparently I was supposed to try the following: echo -e '\E But I don't get a value or anything. Please help. (3 Replies)
Discussion started by: tinman47
3 Replies

3. Shell Programming and Scripting

Using Cursor in Unix - How to do it (Need Help)

Hi, I have a table in which i have the following data JOB_NO FILE_ID FILE_NAME 1546148 1378788 PDF Sample -1.pdf 1546148 1378789 PDF Sample -2.pdf 1546149 1378790 PDF Sample -3.pdf Now I would like use a cursor like thing in unix to download the files using the file ids and send... (1 Reply)
Discussion started by: uuuunnnn
1 Replies

4. UNIX for Dummies Questions & Answers

Problem to map VIM cursor moving in InsertMode

Hi all What I want? I want in Insert mode, press Alt-hjkl move cursor, and then back to insert mode. I know ctrl-o, hjkl can do the job. but everytime I want to move, i have to press ctrl-o, or I have to count how many hjkl I will do, do a C-O (n)hjkl. What I tried (example only with 'j')... (2 Replies)
Discussion started by: sk1418
2 Replies

5. Shell Programming and Scripting

ksh - moving cursor position

hi all, am trying to modify a ksh script to group server names together depending on the cluster they sit in. currently the script does a find . -name '*.pid' to find all running servers and prints out their pids and names. current output looks something like this : serverA ... (1 Reply)
Discussion started by: cesarNZ
1 Replies

6. UNIX for Dummies Questions & Answers

Cursor position

Is there a way of finding the current cursor position (line & column) within AIX (4 Replies)
Discussion started by: gefa
4 Replies

7. 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

8. UNIX for Dummies Questions & Answers

Cursor Positioning

Can anyone tell me how to ouput the current cursor coordinate? I have tried using tput sc and tput rc. However I want to know what the coordinate is. Thanks. (1 Reply)
Discussion started by: bestbuyernc
1 Replies

9. Shell Programming and Scripting

Get the cursor position

Hello, Is there a way to get the current cursor position? I know "tput sc" saves it. Is there a way to find out the value saved? Thanks. (0 Replies)
Discussion started by: bestbuyernc
0 Replies
Login or Register to Ask a Question