3

When entering the grep command in an eshell in spacemacs, a separate window and buffer are created to list the grep output results. However, I would prefer for the output to be listed in the eshell buffer like how a stand-alone terminal application would normally behave. How can this be achieved?

  • Are you typing your grep command line directly into the eshell buffer at the command prompt; or, are you instead executing a function that launches the buit-in grep search using the compliation-mode/grep-mode generated buffer? – lawlist Apr 10 at 18:16
  • I am entering the grep command directly into the command prompt of the eshell buffer. Most other commands entered into the eshell command prompt like this just output onto the eshell buffer as expected and do not open new windows like grep does. – TPog Apr 10 at 19:28
3

eshell has several built-in commands (grep among them) and it prefers to use the built-in version:

~ $ which grep
eshell/grep is a compiled Lisp function in ‘em-unix.el’.

As the manual that I linked to above says:

If you want to discard a given built-in command, you could declare an alias (see Aliases). Example:

     ~ $ which sudo
     eshell/sudo is a compiled Lisp function in `em-tramp.el'.
     ~ $ alias sudo '*sudo $*'
     ~ $ which sudo
     sudo is an alias, defined as "*sudo $*"

So you could do the following to get the external grep command:

~ $ alias grep '*grep $*'
~ $ which grep
grep is an alias, defined as "*grep $*"
~ $ grep foo *
*scratch*~:     "foo")
*scratch*~:(cancel-timer[nil 23357 43792 121024 30 message ("foo") nil 748000])
/usr/bin/grep: Audiobooks/: Is a directory
/usr/bin/grep: Desktop/: Is a directory
...

And as @TPog (the OP) points out in a comment, you can go back to the built-in meaning of grep, by removing the alias:

~ $ alias grep
~ $ which grep
eshell/grep is a compiled Lisp function in ‘em-unix.el’.
~ $
| improve this answer | |
  • 1
    Thanks, also FYI for anyone wanting to reset it back to using the built-in Lisp grep function, you can do this by entering alias grep into the eshell command prompt as explained here – TPog Apr 10 at 21:26
  • 1
    Thanks! I incorporated this information into the answer as well. – NickD Apr 11 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.