0

I am looking for a way when I don't have to type:

emacs abc.txt >/tmp/emacs.log 2>&1 &

Instead just emacs command works like above.

All commands should be treated this way by default. Is there a way to convert bash to behave this way? Or is there a shell that does this by default?

Champ
  • 1,291
  • 4
  • 16
  • 32
  • 1
    Making all commands behave this way would be terrible. All output redirected to file. Then you want to view that file, I suppose using `cat` or `tail`? Nope, their output also goes to that same file. You see the problem? Maybe your plan is to open a different shell that doesn't have this redirection and view file contents from there? – TCvD Dec 18 '20 at 19:18
  • Your 'may be...' assumption is correct. – Champ Dec 19 '20 at 02:00

1 Answers1

4

I would create a file wtfmode containing:

realpath="$PATH"
PATH="/"
command_not_found_handle() (
    cmd=${1##*/}
    PATH=$realpath
    "$@" > "/tmp/$cmd.log" 2>&1 &
)

Then source wtfmode manually to enable it, since putting it in .bashrc would could things very awkward.

Here's an example:

$ source wtfmode
$ ls
$ whoami
$ vim wtfmode
$ asdfasdfasdfsasdfasdf
$ ^C
$ ^C
that other guy
  • 116,971
  • 11
  • 170
  • 194