srsudar / eg

Useful examples at the command line.
MIT License
1.8k stars 99 forks source link

Color is failing on Msys2 on Windows #27

Closed cool-RR closed 9 years ago

cool-RR commented 9 years ago

See #16 .

cool-RR commented 9 years ago

A theory I have is that --pager-cmd isn't handling the space between the less and the -R. I would test this by using -R in ~/.less (or ~/_less) but I don't know what the syntax for that is.

srsudar commented 9 years ago

Can you try 'more -Z' in that case and see if it throws an error?

On Wed, May 13, 2015, 11:09 AM Ram Rachum notifications@github.com wrote:

A theory I have is that --pager-cmd isn't handling the space between the less and the -R. I would test this by using -R in ~/.less (or ~/_less) but I don't know what the syntax for that is.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-101762180.

cool-RR commented 9 years ago

Says Cannot access file C:\Users\Administrator\Desktop\-Z

On Wed, May 13, 2015 at 10:00 PM, Sam Sudar notifications@github.com wrote:

Can you try 'more -Z' in that case and see if it throws an error?

On Wed, May 13, 2015, 11:09 AM Ram Rachum notifications@github.com wrote:

A theory I have is that --pager-cmd isn't handling the space between the less and the -R. I would test this by using -R in ~/.less (or ~/_less) but I don't know what the syntax for that is.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-101762180.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-101778059.

srsudar commented 9 years ago

How interesting...so the full command was eg --pager-cmd 'cat -Z' find? If so, it looks like you're right.

Are you running from the source repo, with something like eg_exec.py, or are you running something you've installed with pip?

srsudar commented 9 years ago

Actually, I wonder if it is more that the command is making it all the way in but the command is getting invoked is causing the problem. It looks as if "cat -Z" is being invoked directly, and the -Z isn't being interpreted as a flag.

What does using "cat -b" as your pager command do? It should number non blank lines.

On Wed, May 13, 2015, 12:04 PM Ram Rachum notifications@github.com wrote:

Says Cannot access file C:\Users\Administrator\Desktop\-Z

On Wed, May 13, 2015 at 10:00 PM, Sam Sudar notifications@github.com wrote:

Can you try 'more -Z' in that case and see if it throws an error?

On Wed, May 13, 2015, 11:09 AM Ram Rachum notifications@github.com wrote:

A theory I have is that --pager-cmd isn't handling the space between the less and the -R. I would test this by using -R in ~/.less (or ~/_less) but I don't know what the syntax for that is.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-101762180.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-101778059.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-101778683.

cool-RR commented 9 years ago

The result of eg --pager-cmd 'cat -z' ls is:

cat: unknown option -- z Try 'cat --help' for more information.

What I gave previously was for more, not cat.

Using eg --pager-cmd 'cat -b' ls indeed numbers the lines, that's a pretty cool trick to know by the way :)

On Wed, May 13, 2015 at 11:51 PM, Sam Sudar notifications@github.com wrote:

Actually, I wonder if it is more that the command is making it all the way in but the command is getting invoked is causing the problem. It looks as if "cat -Z" is being invoked directly, and the -Z isn't being interpreted as a flag.

What does using "cat -b" as your pager command do? It should number non blank lines.

On Wed, May 13, 2015, 12:04 PM Ram Rachum notifications@github.com wrote:

Says Cannot access file C:\Users\Administrator\Desktop\-Z

On Wed, May 13, 2015 at 10:00 PM, Sam Sudar notifications@github.com wrote:

Can you try 'more -Z' in that case and see if it throws an error?

On Wed, May 13, 2015, 11:09 AM Ram Rachum notifications@github.com wrote:

A theory I have is that --pager-cmd isn't handling the space between the less and the -R. I would test this by using -R in ~/.less (or ~/_less) but I don't know what the syntax for that is.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-101762180.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-101778059.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-101778683.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-101813223.

srsudar commented 9 years ago

In that case it looks like eg is parsing getting the option in correctly, so I don't think the space issue is a problem after all.

What about eg --pager-cmd ' less -R' find and eg --pager-cmd ' less -Z' find? Note the leading space inside the single quotes.

cool-RR commented 9 years ago

Holy shit, adding that leading space before less made color work. I don't know what kind of black magic you practice... But I think I'm going to put it in my .egrc and avoid asking further questions before I find out things I can't handle.

On Thu, May 14, 2015 at 5:19 PM, Sam Sudar notifications@github.com wrote:

In that case it looks like eg is parsing getting the option in correctly, so I don't think the space issue is a problem after all.

What about eg --pager-cmd ' less -R' find and eg --pager-cmd ' less -Z' find? Note the leading space inside the single quotes.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102049193.

srsudar commented 9 years ago

That kind of thing just means that I implemented something fragile, I'm afraid. I think the problem is here:

elif pager_cmd.startswith('less'):
    # stealing this check from pydoc.getpager()
    if hasattr(os, 'system') and os.system('(less) 2>/dev/null') != 0:
       # no less!
       use_fallback_page_function = True

The issue is that if the command begins with less, I try to see if it's installed. The "is less installed" bit is the os.system call above, which I stole from pydoc. Odds are this is failing on Windows, which then makes it use the fallback pager, but the fallback pager mechanism is finding your normal less without the -R command. Adding the space tricks the startswith invocation. I'll fix this in the next release.

srsudar commented 9 years ago

Can you try the current tip and see if eg --pager-cmd 'less -R' find works now? I think it should.

cool-RR commented 9 years ago

It doesn't, still seeing control characters.

Also, the shebang #!/usr/bin/python didn't work, I had to change it. I think that #!/usr/bin/env python is considered the most portable.

On Sat, May 16, 2015 at 12:41 AM, Sam Sudar notifications@github.com wrote:

Can you try the current tip and see if eg --pager-cmd 'less -R' find works now? I think it should.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102531915.

srsudar commented 9 years ago

Whoops, my bad. I think that is probably using the pip-installed module, not the tip. What about, from the root directory of the repo, python eg_exec.py --pager-cmd 'less - R' find? It shouldn't depend on the shebang line.

On Sat, May 16, 2015, 12:35 AM Ram Rachum notifications@github.com wrote:

It doesn't, still seeing control characters.

Also, the shebang #!/usr/bin/python didn't work, I had to change it. I think that #!/usr/bin/env python is considered the most portable.

On Sat, May 16, 2015 at 12:41 AM, Sam Sudar notifications@github.com wrote:

Can you try the current tip and see if eg --pager-cmd 'less -R' find works now? I think it should.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102531915.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102584369.

cool-RR commented 9 years ago

It won't let me:

You are invoking eg via the script at /eg/eg_exec.py. This file has been deprecated in order to work with both python 2 and 3.

Please instead invoke /eg_exec.py, or install with pip.

If you're using a symlink and need to update it, try something like the following:

rm `which eg`
ln -s <absolute-path-to-eg-repo>/eg_exec.py /usr/local/bin/eg

Or, simply install with pip:

sudo pip install eg

On Sat, May 16, 2015 at 10:41 AM, Sam Sudar notifications@github.com wrote:

Whoops, my bad. I think that is probably using the pip-installed module, not the tip. What about, from the root directory of the repo, python eg_exec.py --pager-cmd 'less - R' find? It shouldn't depend on the shebang line.

On Sat, May 16, 2015, 12:35 AM Ram Rachum notifications@github.com wrote:

It doesn't, still seeing control characters.

Also, the shebang #!/usr/bin/python didn't work, I had to change it. I think that #!/usr/bin/env python is considered the most portable.

On Sat, May 16, 2015 at 12:41 AM, Sam Sudar notifications@github.com wrote:

Can you try the current tip and see if eg --pager-cmd 'less -R' find works now? I think it should.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102531915.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102584369.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102584560.

srsudar commented 9 years ago

You're trying the one located at "eg/eg_exec.py". Instead do the one at the root of the repo, at the same level as the .git directory.

On Sat, May 16, 2015, 12:43 AM Ram Rachum notifications@github.com wrote:

It won't let me:

You are invoking eg via the script at /eg/eg_exec.py. This file has been deprecated in order to work with both python 2 and 3.

Please instead invoke /eg_exec.py, or install with pip.

If you're using a symlink and need to update it, try something like the following:

rm which eg ln -s /eg_exec.py /usr/local/bin/eg

Or, simply install with pip:

sudo pip install eg

On Sat, May 16, 2015 at 10:41 AM, Sam Sudar notifications@github.com wrote:

Whoops, my bad. I think that is probably using the pip-installed module, not the tip. What about, from the root directory of the repo, python eg_exec.py --pager-cmd 'less - R' find? It shouldn't depend on the shebang line.

On Sat, May 16, 2015, 12:35 AM Ram Rachum notifications@github.com wrote:

It doesn't, still seeing control characters.

Also, the shebang #!/usr/bin/python didn't work, I had to change it. I think that #!/usr/bin/env python is considered the most portable.

On Sat, May 16, 2015 at 12:41 AM, Sam Sudar notifications@github.com wrote:

Can you try the current tip and see if eg --pager-cmd 'less -R' find works now? I think it should.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102531915.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102584369.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102584560.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102584622.

cool-RR commented 9 years ago

Right, my mistake. Now it works! Shows color successfully with --pager-cmd 'find -R'!

On Sat, May 16, 2015 at 10:45 AM, Sam Sudar notifications@github.com wrote:

You're trying the one located at "eg/eg_exec.py". Instead do the one at the root of the repo, at the same level as the .git directory.

On Sat, May 16, 2015, 12:43 AM Ram Rachum notifications@github.com wrote:

It won't let me:

You are invoking eg via the script at /eg/eg_exec.py. This file has been deprecated in order to work with both python 2 and 3.

Please instead invoke /eg_exec.py, or install with pip.

If you're using a symlink and need to update it, try something like the following:

rm which eg ln -s /eg_exec.py /usr/local/bin/eg

Or, simply install with pip:

sudo pip install eg

On Sat, May 16, 2015 at 10:41 AM, Sam Sudar notifications@github.com wrote:

Whoops, my bad. I think that is probably using the pip-installed module, not the tip. What about, from the root directory of the repo, python eg_exec.py --pager-cmd 'less - R' find? It shouldn't depend on the shebang line.

On Sat, May 16, 2015, 12:35 AM Ram Rachum notifications@github.com wrote:

It doesn't, still seeing control characters.

Also, the shebang #!/usr/bin/python didn't work, I had to change it. I think that #!/usr/bin/env python is considered the most portable.

On Sat, May 16, 2015 at 12:41 AM, Sam Sudar < notifications@github.com> wrote:

Can you try the current tip and see if eg --pager-cmd 'less -R' find works now? I think it should.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102531915.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102584369.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102584560.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102584622.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102584685.

srsudar commented 9 years ago

Hoping that is 'less -R', or we have another bug. =) Thanks!

On Sat, May 16, 2015, 12:47 AM Ram Rachum notifications@github.com wrote:

Right, my mistake. Now it works! Shows color successfully with --pager-cmd 'find -R'!

On Sat, May 16, 2015 at 10:45 AM, Sam Sudar notifications@github.com wrote:

You're trying the one located at "eg/eg_exec.py". Instead do the one at the root of the repo, at the same level as the .git directory.

On Sat, May 16, 2015, 12:43 AM Ram Rachum notifications@github.com wrote:

It won't let me:

You are invoking eg via the script at /eg/eg_exec.py. This file has been deprecated in order to work with both python 2 and 3.

Please instead invoke /eg_exec.py, or install with pip.

If you're using a symlink and need to update it, try something like the following:

rm which eg ln -s /eg_exec.py /usr/local/bin/eg

Or, simply install with pip:

sudo pip install eg

On Sat, May 16, 2015 at 10:41 AM, Sam Sudar notifications@github.com wrote:

Whoops, my bad. I think that is probably using the pip-installed module, not the tip. What about, from the root directory of the repo, python eg_exec.py --pager-cmd 'less - R' find? It shouldn't depend on the shebang line.

On Sat, May 16, 2015, 12:35 AM Ram Rachum notifications@github.com wrote:

It doesn't, still seeing control characters.

Also, the shebang #!/usr/bin/python didn't work, I had to change it. I think that #!/usr/bin/env python is considered the most portable.

On Sat, May 16, 2015 at 12:41 AM, Sam Sudar < notifications@github.com> wrote:

Can you try the current tip and see if eg --pager-cmd 'less -R' find works now? I think it should.

— Reply to this email directly or view it on GitHub <https://github.com/srsudar/eg/issues/27#issuecomment-102531915 .

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102584369.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102584560.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102584622.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102584685.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#issuecomment-102584737.

cool-RR commented 9 years ago

If you could let me know at ram@rachum.com when you release the next version with this change, that'll be helpful.

On Sat, May 16, 2015 at 7:44 PM, Sam Sudar notifications@github.com wrote:

Closed #27 https://github.com/srsudar/eg/issues/27.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/27#event-306518777.