Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize ~ in file paths #5

Open
jrunning opened this issue Nov 30, 2015 · 2 comments
Open

Recognize ~ in file paths #5

jrunning opened this issue Nov 30, 2015 · 2 comments

Comments

@jrunning
Copy link

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?

@robbiev
Copy link
Owner

robbiev commented Dec 2, 2015

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

@jrunning
Copy link
Author

jrunning commented Dec 2, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants