9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Romano <me+unobe@fallglow.com>
To: 9front@9front.org
Subject: Re: [9front] Re: /bin/"" use of rc -c instead of eval
Date: Sat, 06 Jul 2024 02:41:20 -0700	[thread overview]
Message-ID: <9B97890FFC11EBEF9081B4D16E0DB78D@smtp.pobox.com> (raw)
In-Reply-To: <217ca7f7-6c1d-4f6e-9c71-696c463ff24d@sirjofri.de>

On Sat Jul  6 01:04:30 -0700 2024, sirjofri+ml-9front@sirjofri.de wrote:
> 06.07.2024 03:49:46 Romano <me+unobe@fallglow.com>:
> > cpu% pwd
> > /
> > cpu% "" cd /sys
> >      cpu% cd /sys/src
> > cpu% pwd
> > /sys/src
> > cpu%
> 
> That's not how it's supposed to work though. Let me illustrate:
> 
> > cpu% pwd
> > /sys/src
> > cpu% "
> >     cpu% pwd
> > cpu% ""
> >     cpu% pwd
> > /sys/src
> > cpu%
> 
> " only displays the last command while "" executes it. An optional argument can be used for filtering:
> 
> > cpu% pwd
> > /sys/src
> > cpu% cd /lib
> > cpu% "" p
> >     cpu% pwd
> > /lib
> > cpu%
> 

Maybe I did not give enough context in my reply: I know
that " lists *previous* commands and "" executes them. So
'cd /sys/src' was something I had previously run in that
window. Here's a comparison of the current "" functionality:

|cpu% cd /sys/src
|cpu% cd /sys
|cpu% pwd
|/sys
|cpu% " cd
|	cpu% cd /sys/src
|	cpu% cd /sys
|cpu% "" cd.*src
|	 cpu% cd /sys/src
|cpu% pwd
|/sys
|cpu% 

And here it is using "" as a fn with eval:

|cpu% fn "" {
|		PROMPT='[^ 	]*(%|;)+[ 	]+'
|		_x=`{
|			" $*|tail -1
|		}
|		if(~ $#_x 0){
|			>[1=2]echo no such command found
|			exit notfound
|		}
|		>[1=2]echo '	' $_x
|		_x=`{
|			echo -n 'eval '''; echo $_x|sed 's/^'^$PROMPT^'//; s/''/''''/g; s/$/''/'
|		}
|		eval $"_x
|	}
|cpu% cd /sys/src
|cpu% cd /sys
|cpu% pwd
|/sys
|cpu% " cd
|	cpu% cd /sys/src
|	cpu% cd /sys
|cpu% "" cd.*src
|	 cpu% cd /sys/src
|cpu% pwd
|/sys/src
|cpu% 

Did you think I was saying it worked differently?

My main point is that built-in rc commands don't
like other commands with "". That is, even tho'
it'll happily print out the cd command, it has
no effect in the shell since it's run in a
subshell. The most I could do is then copy-and-
paste if I wanted to use it. AFAICT a handful
would really make a difference with the fn-form
of "": cd, eval, flag, fn, and '.'.

> Note that I never tested cd'ing with "", which means a lot. It's probably not as useful in most cases, which makes sense if you think about it: you use cd to switch to another directory. When you're there, running it again is a no-op at best, or it fails.

Switching back and forth between different directories
is a common occurrence during development for me, so
I wanted something akin to bash-like 'cd -' or '^R cd'
without having to use the mouse.

  reply	other threads:[~2024-07-06  9:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-05 22:23 [9front] " Romano
2024-07-05 23:14 ` Stanley Lieber
2024-07-05 23:49 ` [9front] " Anthony Martin
2024-07-06  1:48   ` Romano
2024-07-06  8:00     ` sirjofri
2024-07-06  9:41       ` Romano [this message]
2024-07-06 14:05         ` sirjofri
2024-07-06 14:08         ` sirjofri
2024-07-11  6:02           ` Romano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9B97890FFC11EBEF9081B4D16E0DB78D@smtp.pobox.com \
    --to=me+unobe@fallglow.com \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).