rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* tilde featuritis alert
@ 1999-12-09  7:52 Decklin Foster
  1999-12-09  8:26 ` Markus Friedl
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Decklin Foster @ 1999-12-09  7:52 UTC (permalink / raw)
  To: rc

I'm sure this has come up before, but being a relative rc newbie, I
really miss my '~' for home directory from bash. my question is, what
exactly is the pattern matching '~' in rc *good* for? can't you just
use 'switch' and end up with more readable code? couldn't we call it
'match'? is the lack of an sh-like '~' a personal preference of the
author, or just not feasible to implement due to rc's eval-once
semantics?

I know i probably ought to be quiet and retrain my fingers, but old
habits die hard. if i can't patch rc for this, how can i set up
readline to get along with it? my problem is that readline will do tab
completion on ~/wwwd<TAB> if i have a directory in my home called
wwwdocs. but it *won't* do anything with $home/wwwd<TAB>, presumably
since rc is not telling it what's in $home. i note that if I use bash,
$HOME/wwwd<TAB> magically becomes '/home/decklin/wwwdocs/'. bash must
know how interact a little more closley with readline. While this sort
of sets off my bloat detector, it's better than typing a ~, doing tab
completion, and then going back and changing it to $home.

One other thing - is there a replacement for the '~user' idiom? What's
the rc way? grep through /etc/passwd?

-- 
Decklin
Written with Debian GNU/Linux - http://www.debian.org/


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: tilde featuritis alert
  1999-12-09  7:52 tilde featuritis alert Decklin Foster
@ 1999-12-09  8:26 ` Markus Friedl
  1999-12-09  8:52 ` Gert-Jan Vons
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Markus Friedl @ 1999-12-09  8:26 UTC (permalink / raw)
  To: Decklin Foster; +Cc: rc

On Thu, Dec 09, 1999 at 02:52:05AM -0500, Decklin Foster wrote:
> I'm sure this has come up before, but being a relative rc newbie, I
> really miss my '~' for home directory from bash.

this has been discussed ages ago.
see the mailing list archives from
	ftp://ftp.sys.utoronto.ca/pub/rc/rc-list
	ftp://ftp.sys.utoronto.ca/pub/rc/rc-list.1994.gz


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: tilde featuritis alert
  1999-12-09  7:52 tilde featuritis alert Decklin Foster
  1999-12-09  8:26 ` Markus Friedl
@ 1999-12-09  8:52 ` Gert-Jan Vons
  1999-12-09 14:20   ` Decklin Foster
  1999-12-09 16:48   ` Paul Haahr
  1999-12-09 16:27 ` Mark K. Gardner
  1999-12-09 22:08 ` kim kubik
  3 siblings, 2 replies; 9+ messages in thread
From: Gert-Jan Vons @ 1999-12-09  8:52 UTC (permalink / raw)
  To: rc, Decklin Foster

Decklin Foster wrote:

>I'm sure this has come up before, but being a relative rc newbie, I
>really miss my '~' for home directory from bash. my question is, what
>exactly is the pattern matching '~' in rc *good* for? can't you just
>use 'switch' and end up with more readable code? couldn't we call it
>'match'? is the lack of an sh-like '~' a personal preference of the
>author, or just not feasible to implement due to rc's eval-once
>semantics?

Something like "if (~ a b || ~ c d)" becomes quite messy when you only
have 'switch'.

>I know i probably ought to be quiet and retrain my fingers, but old
>habits die hard. if i can't patch rc for this, how can i set up
>readline to get along with it? my problem is that readline will do tab
>completion on ~/wwwd<TAB> if i have a directory in my home called
>wwwdocs. but it *won't* do anything with $home/wwwd<TAB>, presumably
>since rc is not telling it what's in $home.

I doubt you will see tilde expansion in rc anytime soon, since it doesn't 
go with the philosophy behind the shell (just look at the debates over 
'echo' being built-in or not). The conflict with the ~ operator is 
another reason of course.

You can get rc to expand $home (or any other environment variable) when
you hit [tab] for filename completion by using the "vrl" commandline 
editor instead of readline.

I've been thinking and discussing a bit with other rc/vrl users about 
adding ~ expansion to the vrl command-line editor, but it ain't that 
simple since there's no easy way to know whether the user wants the ~ to 
be the ~ operator or not.

I now have the habit of typing $home/foo instead of ~/foo, or /home/user 
instead of ~user. Typing can be reduced by defining h=$home and using 
$h/foo, but I agree it is hard to change old habits :)

Something that I still haven't gotten used to even after 5-6 years of 
using rc is the need to quote command arguments if there's an equal sign 
like in "dd 'if=infile' 'of=outfile'". I once asked for an extension that 
would allow me to do "dd if\=infile of\=outfile" but that got killed 
pretty fast :-/


         Gert-Jan
-----
"If you are good, you will be assigned all the work. If you
  are really good, you will get out of it."
     - Dilbert



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: tilde featuritis alert
  1999-12-09  8:52 ` Gert-Jan Vons
@ 1999-12-09 14:20   ` Decklin Foster
  1999-12-09 16:48   ` Paul Haahr
  1 sibling, 0 replies; 9+ messages in thread
From: Decklin Foster @ 1999-12-09 14:20 UTC (permalink / raw)
  To: rc

Gert-Jan Vons writes:

> Something like "if (~ a b || ~ c d)" becomes quite messy when you
> only have 'switch'.

Ah, true.

> I doubt you will see tilde expansion in rc anytime soon, since it
> doesn't go with the philosophy behind the shell (just look at the
> debates over 'echo' being built-in or not).

Yeah, i read up on the archives and I see what you mean; I don't agree
with the idea that tilde expansion makes rc more bloated or somehow
doesn't 'belong' in a shell (computers are supposed to work for us,
not the other way around, no?) I was just hoping that perhaps someone
else who was bothered by this had already done the work of writing a
patch.

> I've been thinking and discussing a bit with other rc/vrl users
> about adding ~ expansion to the vrl command-line editor, but it
> ain't that simple since there's no easy way to know whether the user
> wants the ~ to be the ~ operator or not.

I bet i can get readline to do this before passing the command to rc,
now that I think of this. After all, it *does* come from the people
who brought you (ick) Emacs. ;-)

> Something that I still haven't gotten used to even after 5-6 years
> of using rc is the need to quote command arguments if there's an
> equal sign like in "dd 'if=infile' 'of=outfile'".

It seems to me that a simple rule would suffice here. An '=' in the
first word of a command is interpreted as a metacharacter. An '=' in
the rest of it is not. Oh, but there is the issue of 'foo = bar' (I
find myself trying to do that frequently in sh now.) OK, an unquoted
'=' is a metacharacter iff (it's part of the first word || it's the
first character in the second word). That should continue to allow
'foo =bar' as well.

Does lex/yacc let us do this? I'm not much of an expert there.

-- 
Decklin
Written with Debian GNU/Linux - http://www.debian.org/


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: tilde featuritis alert
  1999-12-09  7:52 tilde featuritis alert Decklin Foster
  1999-12-09  8:26 ` Markus Friedl
  1999-12-09  8:52 ` Gert-Jan Vons
@ 1999-12-09 16:27 ` Mark K. Gardner
  1999-12-09 22:08 ` kim kubik
  3 siblings, 0 replies; 9+ messages in thread
From: Mark K. Gardner @ 1999-12-09 16:27 UTC (permalink / raw)
  To: rc

Hi Decklin,

Welcome to rc.

[clip...]

> I really miss my '~' for home directory from bash.

[clip...]

> One other thing - is there a replacement for the '~user' idiom?
> What's the rc way? grep through /etc/passwd?

I have a patch to rc that adds tilde expansion for both these cases. I
have also monkeyed with modifications to solve the "readline expands
it but rc doesn't grok it" problem. And I have had discussions with
Gert-Jan Vons, the author of vrl, about how to do tilde expansion in
vrl. Based on this experience (some may say bull-headed stubborness),
I make two observations.

 1) Tilde expansion for rc is fundamentally hard.

    The primary reason is the conflict with pattern matching. Tilde is
    already spoken for as the pattern matching operator. Its use as a
    file path component will always be problematic. My implementation
    of tilde expansion correctly interprets "ls ~", "ls ~/foo", "ls
    ~mkg" or "ls ~mkg/foo" but it cannot handle "ls ~ " (note the
    space after the tilde). You would have to type "ls ~/" instead to
    disambiguate with the use of tilde as the pattern matching
    operator.

    I tried snarfing % as the expansion character for a while, as it
		appears to be unencumbered by prior use. Its use in the place of
		tilde seemed... well ugly. Especially considering that tilde is
		still used in emacs, which I use alot. It was confusing switching
		back and forth between % and ~. Perhaps I just didn't give it
		enough time. Maybe I could have changed emacs, I don't know. I
		abandoned the idea.

 2) rc will never have tilde expansion as "standard equipment".

    The primary reason is cultural. Most of us were attracted to rc
    because of its simplicity. Nearly all changes are seen as
    creeping featuritis and soundly rejected (witness the "echo
    debate"). I have come to appreciate this view and even embrace it.

That said, I must confess that I am still lazily using a patched
version of rc with tilde expansion (along with "false", "true",
"version", "test" and "C-d trapping" features). Next to the bloat
caused by statically linking in GNU Readline, these features are
nearly free! However, I should warn you that my New Year's resolution
is to "go on a diet" by suffering through tilde withdrawals,
eliminating "false" and "true", and adopting vrl.

[PS: Since you are about to ask for it anyway, I am including my patch
for tilde expansion. Add -DTILDEHOME to CFLAGS and recompile. I will
answer simple questions, but I "...MAKE NO WARRANTY...EXPRESSED OR
IMPLIED...", yada, yada, yada.]

[PPS: I have been reluctant to waste bandwidth with its publication.
However, the question of tilde expansion frequently keeps popping up.
I hope by publishing it that requests can be answered by the archive.]

Mark

-- 
Mark K. Gardner
RADIANT Team
Network Engineering, CIC-5
Los Alamos National Laboratory
P.O. Box 1663, M.S. K766
Los Alamos, NM 87545
Email: mkg@lanl.gov
Phone: 1-505-665-4809
-- 

================================ Cut here ======================================
--- rc-1.6/lex.c	Fri Jul 24 09:48:27 1998
+++ rc-1.6-mkg/lex.c	Mon Oct 18 13:33:34 1999
@@ -3,6 +3,12 @@
 #include "rc.h"
 #include "parse.h"
 
+#if defined(TILDEHOME)
+#	include <assert.h>
+#	include <ctype.h>
+#	include <pwd.h>
+#endif /* TILDEHOME */
+
 /*
 	Special characters (i.e., "non-word") in rc:
 		\t \n # ; & | ^ $ = ~ ` ' { } @ ! ( ) < > \
@@ -33,6 +39,18 @@
 
 int lineno;
 
+#if defined(TILDEHOME)
+const char nw[] = {
+	1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
+	1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0,
+	1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, /* ~ */ 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+#else /* TILDEHOME */
 const char nw[] = {
 	1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 	1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
@@ -43,6 +61,7 @@
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };
+#endif /* TILDEHOME */
 
 const char dnw[] = {
 	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -97,9 +116,22 @@
 		checkfreecaret;
 		w = RW;
 		i = 0;
+#if defined(TILDEHOME)
+ 		if (c == '~') {
+ 			c = gchar();
+ 			ugchar(c);
+ 			if (c == ' ' || c == '\t')
+ 				return TWIDDLE;
+ 			c = '~';
+ 		}
+#endif /* TILDEHOME */
 	read:	do {
 			buf[i++] = c;
+#if defined(TILDEHOME)
+			if (c == '?' || c == '[' || c == '*' || c == '~')
+#else
 			if (c == '?' || c == '[' || c == '*')
+#endif /* TILDEHOME */
 				saw_meta = TRUE;
 			if (i >= bufsize)
 				buf = realbuf = erealloc(buf, bufsize *= 2);
@@ -137,6 +169,46 @@
 		if (streq(buf, "while")) return WHILE;
 		if (streq(buf, "case")) return CASE;
 		w = RW;
+#if defined(TILDEHOME)
+		if (buf[0] == '~') {
+		  if (buf[1] == '\0' || buf[1] == '/') {
+			/* ~ or ~/... */
+			char *home = varlookup("home")->w;
+			int hlen, blen;
+			hlen = strlen(home);
+			blen = strlen(buf) - 1;
+			if (i + hlen >= bufsize) {
+			  buf = realbuf = erealloc(buf, bufsize *= 2);
+			}
+			memmove(buf + hlen, &buf[1], blen);
+			memmove(buf, home, hlen);
+			buf[blen + hlen] = '\0';
+		  } else if (buf[1] != '\0' && buf[1] != '/') {
+			/* ~username */
+			char *n, name[256], *b;
+			struct passwd *pwentry;
+			n = name;
+			b = &buf[1];
+			while (isalnum(*b)) {
+			  *n++ = *b++;
+			}
+			*n = '\0';
+			pwentry = getpwnam(name);
+			if (pwentry != NULL) {
+			  char *path = pwentry->pw_dir;
+			  int plen, blen;
+			  plen = strlen(path);
+			  blen = strlen(buf) - 1;
+			  if (i + plen >= bufsize) {
+				buf = realbuf = erealloc(buf, bufsize *= 2);
+			  }
+			  memmove(buf + plen, &buf[strlen(name) + 1], blen);
+			  memmove(buf, path, plen);
+			  buf[blen + plen] = '\0';
+			}
+		  }
+		}
+#endif /* TILDEHOME */
 		y->word.w = ncpy(buf);
 		if (saw_meta) {
 			char *r, *s;
================================= End Cut ======================================


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: tilde featuritis alert
  1999-12-09  8:52 ` Gert-Jan Vons
  1999-12-09 14:20   ` Decklin Foster
@ 1999-12-09 16:48   ` Paul Haahr
  1 sibling, 0 replies; 9+ messages in thread
From: Paul Haahr @ 1999-12-09 16:48 UTC (permalink / raw)
  To: Decklin Foster, Gert-Jan Vons; +Cc: rc

[I hate to jump into an incipient flame war, but...]

Decklin Foster wrote:
> is the lack of an sh-like '~' a personal preference of the author, or
> just not feasible to implement due to rc's eval-once semantics?

Tom Duff's rc (the Plan 9 version) didn't support ~, probably because
none of the Bell Labs shells used ~ for home directory expansion.

Byron kept just about everything the same as Duff's rc in his version,
with the merciful exception of ``if not.''  And, at the time, we were
both strong Bell Labs purists and mocked the people who suggested that
~-expansion was an appropriate shell feature.

When we wrote es, it got almost all the features which real rc users had
complained were missing in rc, in addition to the extensibility features.
(Can you say ``second system effect''?  I thought you could.)  Of course,
this includes ~-expansion.  In fact, ~-expansion is configurable, so you
can have it do whatever you want, including throw an error if you're
offended by having the feature in the shell.

These days, I use es and swear by ~-expansion.  Byron never bothered to
switch (why would he?  rc is perfect for all practical purposes) and
still wonders why anyone would want ~-expansion.  And despite this major
rift, we've somehow stayed friends.

Gert-Jan Vons wrote
> Something that I still haven't gotten used to even after 5-6 years of 
> using rc is the need to quote command arguments if there's an equal sign 
> like in "dd 'if=infile' 'of=outfile'".

Me neither.  I still consider it a bug in both rc and es.

(An intermediate program between rc and es called hs, for ``hypothetical
shell,'' actually fixed this by hacking the grammar, but I've never seen
another Yacc grammar that unpleasant.*  If I remember, the interactions
with ^, which are already horrible, became combinatorily worse.  But it
definitely is possible to make it work.)

> I once asked for an extension that would allow me to do "dd if\=infile
> of\=outfile" but that got killed pretty fast :-/

This, actually, does work in es.

--p

* Ok, you're right, the C++ parsers are that bad.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: tilde featuritis alert
  1999-12-09  7:52 tilde featuritis alert Decklin Foster
                   ` (2 preceding siblings ...)
  1999-12-09 16:27 ` Mark K. Gardner
@ 1999-12-09 22:08 ` kim kubik
  3 siblings, 0 replies; 9+ messages in thread
From: kim kubik @ 1999-12-09 22:08 UTC (permalink / raw)
  To: Decklin Foster; +Cc: rc

Decklin Foster wrote:

>
> I know i probably ought to be quiet and retrain my fingers, but old
> habits die hard. if i can't patch rc for this, how can i set up
> readline to get along with it? my problem is that readline will do tab
> completion on ~/wwwd<TAB> if i have a directory in my home called
> wwwdocs. but it *won't* do anything with $home/wwwd<TAB>, presumably
> since rc is not telling it what's in $home. i note that if I use bash,
> $HOME/wwwd<TAB> magically becomes '/home/decklin/wwwdocs/'. bash must
> know how interact a little more closley with readline. While this sort
> of sets off my bloat detector, it's better than typing a ~, doing tab
> completion, and then going back and changing it to $home.
>

Just this week I noted on Freshmeat a pgm Cle (Command Line Editor)
that claims it 'provides the editing/history/completion commands of
the readline package to any line-oriented Unix command.'

Latest version (FWiW):

    ftp://kaolin.unice.fr/pub/Cle

Maybe it'll help some (?).

 - kim



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: tilde featuritis alert
  1999-12-10  7:45 Byron Rakitzis
@ 1999-12-10  9:32 ` Gert-Jan Vons
  0 siblings, 0 replies; 9+ messages in thread
From: Gert-Jan Vons @ 1999-12-10  9:32 UTC (permalink / raw)
  To: rc

Byron Rakitzis wrote:

>For better or for worse, rc's grammar allows for multiple temporary
>assignments:
>
>         ; foo=1 bar=2 echo $foo $bar
>         1 2
>         ; echo $foo $bar
>
>So you have to account for that as well.
>
>With sufficient tweaking to the parser and lexer perhaps you could allow
>unquoted '='s in a parameter list, but I tried my hand at it years ago
>and I wasn't able to come up with anything remotely pleasant.

On the other hand:

         ; echo foo=1 bar=2
         syntax error

so it does detect that the assignment is not valid in this case. If it 
just could take the equals-sign as is...


         Gert-Jan
-----
"A little government and a little luck are necessary in life,
  but only a fool trusts either of them."
     - P.J. O'Rourke



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: tilde featuritis alert
@ 1999-12-10  7:45 Byron Rakitzis
  1999-12-10  9:32 ` Gert-Jan Vons
  0 siblings, 1 reply; 9+ messages in thread
From: Byron Rakitzis @ 1999-12-10  7:45 UTC (permalink / raw)
  To: fosterd, rc

>It seems to me that a simple rule would suffice here. An '=' in the
>first word of a command is interpreted as a metacharacter. An '=' in
>the rest of it is not. Oh, but there is the issue of 'foo = bar' (I
>find myself trying to do that frequently in sh now.) OK, an unquoted
>'=' is a metacharacter iff (it's part of the first word || it's the
>first character in the second word). That should continue to allow
>'foo =bar' as well.

For better or for worse, rc's grammar allows for multiple temporary
assignments:

	; foo=1 bar=2 echo $foo $bar
	1 2
	; echo $foo $bar
	
	; 

So you have to account for that as well.

With sufficient tweaking to the parser and lexer perhaps you could allow
unquoted '='s in a parameter list, but I tried my hand at it years ago
and I wasn't able to come up with anything remotely pleasant.

Byron.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~1999-12-10 10:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-09  7:52 tilde featuritis alert Decklin Foster
1999-12-09  8:26 ` Markus Friedl
1999-12-09  8:52 ` Gert-Jan Vons
1999-12-09 14:20   ` Decklin Foster
1999-12-09 16:48   ` Paul Haahr
1999-12-09 16:27 ` Mark K. Gardner
1999-12-09 22:08 ` kim kubik
1999-12-10  7:45 Byron Rakitzis
1999-12-10  9:32 ` Gert-Jan Vons

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).