04-15-2010
How on earth can zsh know whether it's starting at the beginning of a line or not?
Hi everyone,
I'm currently developing my own shell and I've been wondering how this awesome "printing a reverse-video percent character and a newline when the prompt doesn't start at the beginning of a line" feature is implemented in zsh.
Although it is obvious what is needed to implement this (a way to figure out whether you are at the beginning of a line or not), how to get it is much more complicated. Very weirdly, there seems to exist no way to know the cursor position in a terminal without clearing it and keeping track of the cursor, which a shell obviously cannot do since it can't control the output of the programs it launches (that is why my theory that zsh uses ncurses doesn't seem to hold, although it is very possible that it uses some ncurses functions).
I checked the zsh source code but I'm not used to doing such things, and besides, it's quite like looking for a needle in a haystack (even though I'm fairly confident the code is situated in the zle part)...
I although figured there might be a way to check for the beginning of the line indirectly, I didn't find any yet, so would anyone be able to help me find how zsh does this, or a way to get similar results?
Thanks a lot in advance.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
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
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
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 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
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
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
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
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
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
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
LEARN ABOUT PHP
mb_strrichr
MB_STRRICHR(3) 1 MB_STRRICHR(3)
mb_strrichr - Finds the last occurrence of a character in a string within another, case insensitive
SYNOPSIS
string mb_strrichr (string $haystack, string $needle, [bool $part = false], [string $encoding = mb_internal_encoding()])
DESCRIPTION
mb_strrichr(3) finds the last occurrence of $needle in $haystack and returns the portion of $haystack. Unlike mb_strrchr(3), mb_strrichr(3)
is case-insensitive. If $needle is not found, it returns FALSE.
PARAMETERS
o $haystack
- The string from which to get the last occurrence of $needle
o $needle
- The string to find in $haystack
o $part
- Determines which portion of $haystack this function returns. If set to TRUE, it returns all of $haystack from the beginning to
the last occurrence of $needle. If set to FALSE, it returns all of $haystack from the last occurrence of $needle to the end,
o $encoding
- Character encoding name to use. If it is omitted, internal character encoding is used.
RETURN VALUES
Returns the portion of $haystack. or FALSE if $needle is not found.
SEE ALSO
mb_stristr(3), mb_strrchr(3).
PHP Documentation Group MB_STRRICHR(3)