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

Not able to pipe into eless #18

Closed
mobyte0 opened this Issue Feb 13, 2018 · 20 comments

Comments

3 participants
@mobyte0

mobyte0 commented Feb 13, 2018

OS: MacOS 10.12.6
Shell: fish 2.5.0/bash 4.4.0(1)-release

 rob  ~/b/eless   master ±  ls
CONTRIBUTING.org README.org       doc              eless.org
LICENSE.md       build            eless
 rob  ~/b/eless   master ±  emacs --version
GNU Emacs 25.3.1
Copyright (C) 2017 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
 rob  ~/b/eless   master ±  echo 'test' | ./eless -D
Eless Version f2eee31 (commit hash of current master~1)
https://github.com/kaushalmodi/eless/tree/master
DEBUG: --> Input from pipe/file
DEBUG:     Output to terminal -->
DEBUG: var : -D
DEBUG: Raw Args                       : -D
DEBUG: Emacs Args                     : -nw
DEBUG: Pipe Contents (up to 10 lines) : test
DEBUG: Temp File : emacs-stdin-rob.HJxNpaJ
--tmpdir
DEBUG: first_line_piped_data = test
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
	[-e pattern] [-f file] [--binary-files=value] [--color=when]
	[--context[=num]] [--directories=action] [--label] [--line-buffered]
	[--null] [pattern] [file ...]
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
	[-e pattern] [-f file] [--binary-files=value] [--color=when]
	[--context[=num]] [--directories=action] [--label] [--line-buffered]
	[--null] [pattern] [file ...]
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
	[-e pattern] [-f file] [--binary-files=value] [--color=when]
	[--context[=num]] [--directories=action] [--label] [--line-buffered]
	[--null] [pattern] [file ...]
DEBUG: No man page or info manual detected
DEBUG: Eless Command : emacs_Q_view_mode emacs-stdin-rob.HJxNpaJ
--tmpdir                          -nw                          --eval '(progn
                                   (set-visited-file-name nil)
                                   (rename-buffer "*Stdin*" :unique))'
DEBUG: Args passed to emacs_Q_view_mode : emacs-stdin-rob.HJxNpaJ

A GUI emacs opens without anything in it.

 rob  ~/b/eless   master ±  ls
--tmpdir                         build                            emacs-stdin-rob.HJxNpaJ
CONTRIBUTING.org                 doc                              emacs-stdin-rob.HJxNpaJ?--tmpdir
LICENSE.md                       eless
README.org                       eless.org
@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Feb 13, 2018

Hello,

Using the same echo 'test' | ./eless -D, I get:

https://github.com/kaushalmodi/eless/tree/master
DEBUG: --> Input from pipe/file
DEBUG:     Output to terminal -->
DEBUG: var : -D
DEBUG: Raw Args                       : -D
DEBUG: Emacs Args                     : -nw
DEBUG: Pipe Contents (up to 10 lines) : test
DEBUG: Temp File : /tmp/emacs-stdin-kmodi.1XWY7yt
DEBUG: first_line_piped_data = test
DEBUG: No man page or info manual detected
DEBUG: Eless Command : emacs_Q_view_mode /tmp/emacs-stdin-kmodi.1XWY7yt                          -nw                          --eval '(progn
                                   (set-visited-file-name nil)
                                   (rename-buffer "*Stdin*" :unique))'
DEBUG: Args passed to emacs_Q_view_mode : /tmp/emacs-stdin-kmodi.1XWY7yt -nw --eval (progn
                                   (set-visited-file-name nil)
                                   (rename-buffer "*Stdin*" :unique))

So based on the

usage: grep ..

messages you get, it looks like the macOS grep does not support -P!

It's failing for each of these 3 grep checks!

IMO grep should default to -P (Perl regex) so that we can use the super-awesome \K characters and look-ahead checks.. that I use in the above grep checks.

I am using the old (2009) GNU grep 2.6.3 that came with RHEL 6.6..

Can you get GNU grep on your machine too?


A GUI emacs opens without anything in it.

We can tackle this later once the grep issue is resolved. For me, emacs -nw launches in the same terminal with buffer contents as "test".

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Feb 13, 2018

@mobyte0 Can you try installing GNU grep using these instructions (looks like someone else using the mac-default grep was also missing the -P functionality :)). I don't have macOS on any machine, so I'll have trust stackexchange and your feedback :)

@mobyte0

This comment has been minimized.

mobyte0 commented Feb 13, 2018

I have successfully installed GNU grep on Homebrew and I'm on version 3.1. I would recommend listing the needed version of grep in the requirements.

While I'm not getting the grep errors anymore, the empty GUI emacs opens again.

 rob  ~/b/eless   master ±  ls
CONTRIBUTING.org README.org       doc              eless.org
LICENSE.md       build            eless
 rob  ~/b/eless   master ±  echo 'test' | ./eless -D
Eless Version f2eee31 (commit hash of current master~1)
https://github.com/kaushalmodi/eless/tree/master
DEBUG: --> Input from pipe/file
DEBUG:     Output to terminal -->
DEBUG: var : -D
DEBUG: Raw Args                       : -D
DEBUG: Emacs Args                     : -nw
DEBUG: Pipe Contents (up to 10 lines) : test
DEBUG: Temp File : emacs-stdin-rob.xLsUAB7
--tmpdir
DEBUG: first_line_piped_data = test
DEBUG: No man page or info manual detected
DEBUG: Eless Command : emacs_Q_view_mode emacs-stdin-rob.xLsUAB7
--tmpdir                          -nw                          --eval '(progn
                                   (set-visited-file-name nil)
                                   (rename-buffer "*Stdin*" :unique))'
DEBUG: Args passed to emacs_Q_view_mode : emacs-stdin-rob.xLsUAB7
 rob  ~/b/eless   master ±  ls
--tmpdir                         build                            emacs-stdin-rob.xLsUAB7
CONTRIBUTING.org                 doc                              emacs-stdin-rob.xLsUAB7?--tmpdir
LICENSE.md                       eless
README.org                       eless.org
 rob  ~/b/eless   master ± 
@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Feb 13, 2018

Thanks for the followup.

I would recommend listing the needed version of grep in the requirements.

Of course, I will do that now. You are probably the first macOS user without GNU grep who tried this.. that's all :)

While I'm not getting the grep errors anymore, the empty GUI emacs opens again.

Alright.. so let's debug this.. Let me think more about it and get back to you.

@mobyte0

This comment has been minimized.

mobyte0 commented Feb 13, 2018

Yeah, the base is BSD grep 2.5.1, so perhaps this could effect many BSD users?

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Feb 13, 2018

Looks like we have a different variant of mktemp as well..

Compare the mktemp file debug output I get:

DEBUG: Temp File : /tmp/emacs-stdin-kmodi.1XWY7yt

vs yours:

DEBUG: Temp File : emacs-stdin-rob.xLsUAB7
--tmpdir

So one thing is obvious.. the --tmpdir arg was not respected on your system. I am using that arg to specifically tell mktemp to create the temp-file in /tmp.

But looks like, on your system, it literally created emacs-stdin-rob.xLsUAB7 and --tmpdir. Sorry about that.

Let me google the right way to do this on mac OS.

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Feb 13, 2018

@mobyte0 What is your mktemp version (mktemp --version)? I once again have the GNU version:

mktemp (GNU coreutils) 8.28

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Feb 13, 2018

Does this work on your system?

mktemp -t emacs-stdin-"$USER".XXXXXXX

@kaushalmodi kaushalmodi added the bug label Feb 13, 2018

kaushalmodi added a commit that referenced this issue Feb 13, 2018

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Feb 13, 2018

@mobyte0 Do you want to update to the latest master and try again?

@mobyte0

This comment has been minimized.

mobyte0 commented Feb 13, 2018

Alright, it's working. I pulled your new commit and by using GNU coreutils in place of the stock BSD utils (I followed the guidance here: https://apple.stackexchange.com/a/69332. However, people using shells other than bash may need to configure their paths in the way the shell requires), the pipe echo into eless is now working.

Thank you so much for your help!

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Feb 13, 2018

However, people using shells other than bash may need to configure their paths in the way the shell requires

eless should work as long as bash is in user's $PATH.. the user doesn't necessarily need to run eless inside bash. I have to use tcsh at work.. my default shell is unfortunately that, but eless works fine.

@mobyte0

This comment has been minimized.

mobyte0 commented Feb 13, 2018

fish has an odd way of dealing with search paths and variables if you are unfamiliar with it. It uses something called set which is explained more here: https://fishshell.com/docs/current/commands.html#set. As far as I know, if you don't set it universally, I think it holds a different path for some reason.

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Feb 13, 2018

Hmm.. haven't used fish.. but can you come up with a brief description of what fish users need to do.. something that I can add to the Requirements section?

@mobyte0

This comment has been minimized.

mobyte0 commented Feb 13, 2018

Well, technically, as long as eless is put somewhere in your standard search path (whether it's a symlink or whatnot), all is good. I just decided to put it in my home search path as a symlink, so maybe I'm just overthinking it.

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Feb 13, 2018

Great! I'll anyways update Requirements to mention that bash needs to be in PATH. That section can grow as per feedback from other users.

Thanks for sticking through the debug.

@mobyte0

This comment has been minimized.

mobyte0 commented Feb 13, 2018

However, when using fish, the example you listed of PAGER=eless man grep will not work and instead has to be set with something along the lines of set -U PAGER eless (I think, I'm still researching this). When doing that, opening something such as man ls will show text saying This script is not supposed to sent output to a pipe. Perhaps this should go into another issue?

Also, thanks for your quick help, I'm glad this could be resolved in a short amount of time.

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Feb 13, 2018

When doing that, opening something such as man ls will show text saying This script is not supposed to sent output to a pipe. Perhaps this should go into another issue?

Yes, please.. with the -D output too.

Can you also try setting PAGER env var permanently to eless (has worked well for me for the last 10 months or so.. since the first release of eless)? Do you still get that problem? We can continue this in the new issue you open.

@sshaw

This comment has been minimized.

sshaw commented Feb 13, 2018

If adaptation is a goal, I would not require GNU grep and would use an alternate approach.
It seems as though you're using -P just for regex lookahead.

There are alternatives (untested 😄):

grep -o '^([A-Za-z-_]+\([0-9]+\))(?=\s+.*?\1$)' 

Can be:

grep '^\([A-Za-z_-]+([0-9]+)\) \+.*\1$'  | grep -o '^[A-Za-z_-]\+([0-9]\+)'

Or instead of using Perl regexes (-P), just use perl:

perl -ne'/^([A-Za-z-_]+\([0-9]+\))(?=\s+.*?\1$)/ and print'

It's likely already installed and I'm pretty sure it's installed by default more than GNU grep.

Also if you use egrep then you don't have to escape any of ()+.

sed -r and the regex option I are GNU specific as well. And in this case you can achieve the same thing with Bash variable expansion:

some_var=${some_var/bash_builtins/builtins}
@sshaw

This comment has been minimized.

sshaw commented Feb 13, 2018

I have to use tcsh at work.

Interesting. Can you elaborate?

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Feb 13, 2018

If adaptation is a goal, I would not require GNU grep and would use an alternate approach.

Continuing this here: #19

Interesting. Can you elaborate?

We use a lot of 3rd party vendor tools that are tested to work well with env setup for tcsh.. and legacy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment