9front - general discussion about 9front
 help / color / mirror / Atom feed
From: igor@9lab.org
To: 9front@9front.org
Cc: igor@9lab.org
Subject: [9front] [PATCH] rio: allow spaces in working directory path (-cd) when creating a new window
Date: Thu, 25 Nov 2021 03:17:31 +0100	[thread overview]
Message-ID: <0F86B9BF6BB00E5721AFCE94A8A6FECF@9lab.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 2102 bytes --]

The below patch is for review and testing.  It enables rio to open new
windows in a working directory `dirname` (i.e.  using `-cd dirname`)
where the dirname path contains spaces.  I ran into this issue while
browsing hierarchies imported via sshfs(4) in vdir⁽¹⁾, using vdir's
feature to open a window with the working directory set to the
selected path via right clicking on a path.

Please give this a try and/or provide feedback if you run into any
issues or disagree with the solution.  If there is agreement and no
one runs into problems over the next week or two I will merge this
patch.

¹…http://shithub.us/phil9/vdir/HEAD/info.html

<snip>
From: Igor Böhm <igor@9lab.org>
Date: Thu, 25 Nov 2021 01:57:04 +0000
Subject: [PATCH] rio: allow spaces in working directory path (-cd) when creating a new window


The initial working directory of the new window may be set by a
`-cd directory` option. However, the `-cd directory` option is
not capable of handling paths with spaces.

To enable paths with spaces the function
/sys/src/cmd/rio/wctl.c:/^parsewctl is extended to handle quoted
directory paths, using a closing quote as the end of a path instead
of a space.

Before applying the patch the following will fail to open a new
window by writing to /dev/wctl:

<snip>
 % rio -i window
 % mkdir '/tmp/path with space'
 % echo new -cd '''/tmp/path with space''' window -x rc >> /dev/wctl
 % pwd
 /tmp/path with space
<snap>

After applying the patch the above sequence works as expected,
opening a window running rc and the working directory set to
'/tmp/path with space'.
---
diff f8dc73782d90c741e7886629252215c13e35af40 343aafa3a09dd808a1652670d8a7e20021cb0057
--- a/sys/src/cmd/rio/wctl.c	Mon Nov  8 00:31:11 2021
+++ b/sys/src/cmd/rio/wctl.c	Thu Nov 25 02:57:04 2021
@@ -252,8 +252,13 @@
 			s++;
 		if(param == Cd){
 			*cdp = s;
-			while(*s && !isspace(*s))
-				s++;
+			if(*s == '\''){	/* quoted directory */
+				*cdp = ++s;
+				while(*s && *s != '\'')
+					s++;
+			}else
+				while(*s && !isspace(*s))
+					s++;
 			if(*s != '\0')
 				*s++ = '\0';
 			continue;
</snap>

[-- Attachment #2: rio-working-directory-with-spaces.patch --]
[-- Type: text/plain, Size: 1437 bytes --]

From: Igor Böhm <igor@9lab.org>
Date: Thu, 25 Nov 2021 01:57:04 +0000
Subject: [PATCH] rio: allow spaces in working directory path (-cd) when creating a new window


The initial working directory of the new window may be set by a
`-cd directory` option. However, the `-cd directory` option is
not capable of handling paths with spaces.

To enable paths with spaces the function
/sys/src/cmd/rio/wctl.c:/^parsewctl is extended to handle quoted
directory paths, using a closing quote as the end of a path instead
of a space.

Before applying the patch the following will fail to open a new
window by writing to /dev/wctl:

<snip>
 % rio -i window
 % mkdir '/tmp/path with space'
 % echo new -cd '''/tmp/path with space''' window -x rc >> /dev/wctl
 % pwd
 /tmp/path with space
<snap>

After applying the patch the above sequence works as expected,
opening a window running rc and the working directory set to
'/tmp/path with space'.
---
diff f8dc73782d90c741e7886629252215c13e35af40 343aafa3a09dd808a1652670d8a7e20021cb0057
--- a/sys/src/cmd/rio/wctl.c	Mon Nov  8 00:31:11 2021
+++ b/sys/src/cmd/rio/wctl.c	Thu Nov 25 02:57:04 2021
@@ -252,8 +252,13 @@
 			s++;
 		if(param == Cd){
 			*cdp = s;
-			while(*s && !isspace(*s))
-				s++;
+			if(*s == '\''){	/* quoted directory */
+				*cdp = ++s;
+				while(*s && *s != '\'')
+					s++;
+			}else
+				while(*s && !isspace(*s))
+					s++;
 			if(*s != '\0')
 				*s++ = '\0';
 			continue;

             reply	other threads:[~2021-11-25  2:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-25  2:17 igor [this message]
2021-11-25  9:57 ` cinap_lenrek
2021-11-25 10:40   ` igor
2021-11-29  0:29   ` igor

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=0F86B9BF6BB00E5721AFCE94A8A6FECF@9lab.org \
    --to=igor@9lab.org \
    --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).