numberwang icon indicating copy to clipboard operation
numberwang copied to clipboard

Recognize ~ in file paths

Open jrunning opened this issue 10 years ago • 2 comments

I know it's impractical to handle all shell expansions, but it would be nice if numberwang recognized ~.

This came up recently when a file I piped to numberwang included the text ~/.ssh/known_hosts and numberwang came back with ~{/.}ssh/known_hosts, which wasn't the expected result at all. Similarly, if both the current directory and the home directory contain a file named foo.txt and the input to numberwang includes the test ~/foo.txt, numberwang will return ~/{foo.txt}. Here's a test case:

$ ls -d -1 $PWD/*
/Users/jrunning/misc/foo.txt
/Users/jrunning/misc/test.txt

$ touch ~/foo.txt

$ cat test.txt
A: ~/foo.txt
B: ~/.ssh/known_hosts

$ cat test.txt | nw
{1} A: ~/{foo.txt}
{2} B: ~{/.}ssh/known_hosts

to clipboard:

The output I would prefer would be:

{1} A: {~/foo.txt}
{2} B: {~/.ssh/known_hosts}

Perhaps there could be an option to turn this behavior on or off?

jrunning avatar Nov 30 '15 18:11 jrunning

It would be great to support it but it is a bit more complex than that: https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html

Other things to watch out for

  1. It's possible to quote it e.g. "~/foo.txt" meaning the ~ is now a literal
  2. Not all shells might behave as bash does

robbiev avatar Dec 02 '15 10:12 robbiev

Like I said, I think it's impractical to support cases other than ~/foo. As far as I know sh, bash, zsh, csh and fish all work the same for this case. I'm not sure who that leaves (0.01%?), but you could supply an option to disable the behavior for those users.

Quoting is a more interesting problem and I'm not sure what the ideal behavior is there.

jrunning avatar Dec 02 '15 18:12 jrunning