summaryrefslogtreecommitdiffstats
path: root/fish/fish.c
diff options
context:
space:
mode:
authorRichard Jones <rjones@trick.home.annexia.org>2009-07-15 11:39:04 +0100
committerRichard Jones <rjones@trick.home.annexia.org>2009-07-15 11:39:04 +0100
commit9449b0fce4145a56df9d43169d61e8b2c4e41b09 (patch)
tree02b52334c5712ab9ef98414807db03dc71ea3320 /fish/fish.c
parent1d29b4e40bed1145e2ca359bda62d5aa218dbc41 (diff)
downloadlibguestfs-9449b0fce4145a56df9d43169d61e8b2c4e41b09.tar.gz
libguestfs-9449b0fce4145a56df9d43169d61e8b2c4e41b09.tar.xz
libguestfs-9449b0fce4145a56df9d43169d61e8b2c4e41b09.zip
guestfish: Add tilde expansion for paths (RHBZ#511372).
This commit adds tilde expansion for local users in guestfish: ><fs> echo "~" ~ ><fs> echo ~ /home/rjones ><fs> echo ~foo ~foo ><fs> echo ~rjones/bar /home/rjones/bar ><fs> echo ~roo ~roo ><fs> echo ~root/foo /root/foo ><fs> echo ~root /root
Diffstat (limited to 'fish/fish.c')
-rw-r--r--fish/fish.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/fish/fish.c b/fish/fish.c
index 4042bbcf..f5d538d1 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -514,6 +514,7 @@ script (int prompt)
char *argv[64];
int i, len;
int global_exit_on_error = !prompt;
+ int tilde_candidate;
if (prompt)
printf (_("\n"
@@ -587,6 +588,8 @@ script (int prompt)
/* Get the parameters. */
while (*p && i < sizeof argv / sizeof argv[0]) {
+ tilde_candidate = 0;
+
/* Parameters which start with quotes or pipes are treated
* specially. Bare parameters are delimited by whitespace.
*/
@@ -647,6 +650,11 @@ script (int prompt)
*(pend-1) = '\0';
*/
} else if (*p != ' ' && *p != '\t') {
+ /* If the first character is a ~ then note that this parameter
+ * is a candidate for ~username expansion. NB this does not
+ * apply to quoted parameters.
+ */
+ tilde_candidate = *p == '~';
len = strcspn (p, " \t");
if (p[len]) {
p[len] = '\0';
@@ -659,7 +667,11 @@ script (int prompt)
abort ();
}
- argv[i++] = p;
+ if (!tilde_candidate)
+ argv[i] = p;
+ else
+ argv[i] = try_tilde_expansion (p);
+ i++;
p = pend;
if (*p)