Sponsored Content
Top Forums Programming How on earth can zsh know whether it's starting at the beginning of a line or not? Post 302413650 by AdrienE on Friday 16th of April 2010 01:15:20 PM
Old 04-16-2010
Quote:
Originally Posted by pludi
Really? I thought this is what the ^[[6n escape sequence was for?
Thanks, that does the trick (in a very ugly way though). No need to be ironical about it though, it's not as if hardcoded escape sequences were that much of an obvious solution (although it is true I could have found it myself, which I did, actually, a few hours after creating this thread).
Quote:
Originally Posted by pludi
Besides:
Code:
$ which zsh
/usr/bin/zsh
$ ldd -r $( which zsh )
        linux-gate.so.1 =>  (0xffffe000)
        libcap.so.1 => /lib/libcap.so.1 (0xb7f6b000)
        libdl.so.2 => /lib/libdl.so.2 (0xb7f67000)
        libnsl.so.1 => /lib/libnsl.so.1 (0xb7f50000)
        libncurses.so.5 => /lib/libncurses.so.5 (0xb7f1b000)
        libm.so.6 => /lib/libm.so.6 (0xb7ef6000)
        libc.so.6 => /lib/libc.so.6 (0xb7dc3000)
        /lib/ld-linux.so.2 (0xb7f89000)
$ zsh --version
zsh 4.3.4 (i686-suse-linux-gnu)

I did say zsh possibly used ncurses functions ("although it is very possible that it uses some ncurses functions"). It has, in fact, a ncurses module. But that doesn't mean it uses ncurses to get the cursor position. It can't do this because ncurses knows it by clearing the screen an keeping track of it, which is incompatible with launching external programs easily.
Quote:
Originally Posted by pludi
That makes it sound like you just started programming, and are thinking that writing your own shell can't be that hard, since there are so many around.
Well I'm sorry if it sounds like that but that's just not true.

As a matter of fact, I found a better solution to this problem than ^[[6n. The end is not to find the cursor position, this is the mean. The real purpose here is to be able to stay on the current line if we're at the beginning of it or print a % and get to the next line otherwise. To achieve this I thought the cursor position was needed but it's not.
You can get the same result by always printing a %, and number_of_columns_in_the_terminal - 1 spaces, then a carriage return and the 'ce' termcap. This is in fact what my version of zsh seems to do (I tried selecting the end of the last line to check for spaces).
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unix Script with line number at beginning of each line.

Could anybody help me. I need to create a script that reads a text file from STDIN and prints out the file to STDOUT with line numbers at the beginning of each line. Thanks. (5 Replies)
Discussion started by: mascorro
5 Replies

2. Shell Programming and Scripting

how to delete text from line starting pattern1 up to line before pattern2?

My data is xml'ish (here is an excerpt) :- <bag name="mybag1" version="1.0"/> <contents id="coins"/> <bag name="mybag2" version="1.1"/> <contents id="clothes"/> <contents id="shoes"/> <bag name="mybag3" version="1.6"/> I want to delete line containing mybag2 and its subsequent... (5 Replies)
Discussion started by: repudi8or
5 Replies

3. Shell Programming and Scripting

Space at beginning of the line

How can I delete spaces at the begining of all lines of my file ? (2 Replies)
Discussion started by: Sara_84
2 Replies

4. UNIX for Dummies Questions & Answers

How to specify beginning-of-line/end-of-line characters inside a regex range

How can I specify special meaning characters like ^ or $ inside a regex range. e.g Suppose I want to search for a string that either starts with '|' character or begins with start-of-line character. I tried the following but it does not work: sed 's/\(\)/<do something here>/g' file1 ... (3 Replies)
Discussion started by: jawsnnn
3 Replies

5. UNIX for Dummies Questions & Answers

vim copy line and paste at the beginning, middle, and end of another line

How would you do vim copy line and paste at the beginning, middle, and end of another line. I know yy copies the whole line and p pastes the whole line, but on its own separate line. Sometimes I would like to copy a line to the beginning, middle, or end of another line. I would think this would be... (3 Replies)
Discussion started by: cokedude
3 Replies

6. Shell Programming and Scripting

comment a line of the patterns is a the beginning of the line

I need to comment the lines starting with pattern "exclude" or "exclude=". If the work exclude comes at any other part, ignore it. Also, ignore, excludes, excluded etc. Ie only comment the line starting with exclude. File contents. exclude exclude= hi I am excluded excludes excludes= ... (9 Replies)
Discussion started by: anil510
9 Replies

7. Shell Programming and Scripting

beginning less from line #

Hi from a script i want to to read a file beginning at line e.g. number 21 to the EOF. less +n21 temp.txt Bevor the result, it brings an empty page, so that i cant use for scripting. Any idea how the problem can be solved? Thanks in advance! IMPe (2 Replies)
Discussion started by: IMPe
2 Replies

8. Shell Programming and Scripting

With script bash, read file line per line starting at the end

Hello, I'm works on Ubuntu server My goal : I would like to read file line per line, but i want to started at the end of file. Currently, I use instructions : while read line; do COMMAND done < /var/log/apache2/access.log But, the first line, i don't want this. The file is long... (5 Replies)
Discussion started by: Fuziion
5 Replies

9. UNIX for Dummies Questions & Answers

How to grep a line not starting with # from a file (there are two lines starting with # and normal)?

e.g. File name: File.txt cat File.txt Result: #INBOUND_QUEUE=FAQ1 INBOUND_QUEUE=FAQ2 I want to get the value for one which is not commented out. Thanks, (3 Replies)
Discussion started by: Tanu
3 Replies

10. Shell Programming and Scripting

Remove new line starting with a numeric value and append it to the previous line

Hi, i have a file with multiple entries. After some tests with sed i managed to get the file output as follows: lsn=X-LINK-IN0,apc=661:0,state=avail,avail/links=1/1, 00,2110597,2094790,0,81,529,75649011,56435363, lsn=TM1ITP1-AM1ITP1-LS,apc=500:0,state=avail,avail/links=1/1,... (5 Replies)
Discussion started by: nms
5 Replies
toe(1M) 																   toe(1M)

NAME
toe - table of (terminfo) entries SYNOPSIS
toe [-v[n]] [-huUV] file... DESCRIPTION
With no options, toe lists all available terminal types by primary name with descriptions. File arguments specify the directories to be scanned; if no such arguments are given, your default terminfo directory is scanned. If you also specify the -h option, a directory header will be issued as each directory is entered. There are other options intended for use by terminfo file maintainers: -u file says to issue a report on dependencies in the given file. This report condenses the `use' relation: each line consists of the pri- mary name of a terminal that has use capabilities, followed by a colon, followed by the whitespace-separated primary names of all terminals which occur in those use capabilities, followed by a newline -U file says to issue a report on reverse dependencies in the given file. This report reverses the `use' relation: each line consists of the primary name of a terminal that occurs in use capabilities, followed by a colon, followed by the whitespace-separated primary names of all terminals which depend on it, followed by a newline. -vn specifies that (verbose) output be written to standard error trace information showing toe's progress. The optional integer n is a number from 1 to 10, interpreted as for tic(1). -V reports the version of ncurses which was used in this program, and exits. FILES
/usr/share/terminfo/?/* Compiled terminal description database. SEE ALSO
tic(1M), infocmp(1M), captoinfo(1M), infotocap(1M), curses(3X), terminfo(5). toe(1M)
All times are GMT -4. The time now is 03:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy