0

I want to run Emacs after logging into bash as user. But also I want to be able to jump back into the bash prompt if I press CTRL-Z.

I have tried a couple of settings of .bashrc and .profile:

emacs

eval 'emacs'

bash -c emacs

exec emacs -nw

The problem is that all of this variants make CTRL-Z drop me not to bash prompt , but to empty stdin, like bash prompt was not loaded yet. Any ideas? Thanks.

Алр
  • 11
  • 3
  • I cannot help you on your topic. But you should not do that. Messing around with the result of an login prozess (eg. using ksh instead of bash or something like that) will result in problems. I learned this a couple of times. :-) but someone using emacs by default on a shell gives me back the faith in humanity – mbieren Jul 13 '17 at 10:50
  • thanks for your answer. You should see the device I use for it (I call it "pocket emacs", and "pocket debugger"). Its Sony Vaio VGN-P31ZRK. Most of the "special buttons" are used in binding)) https://pp.userapi.com/c626117/v626117672/31b16/slek7sMxMbk.jpg – Алр Jul 14 '17 at 14:20
  • Related: [Ask a running bash (interactive) to run a command from outside](https://stackoverflow.com/questions/7370538/ask-a-running-bash-interactive-to-run-a-command-from-outside) and [Unable to fake terminal input with termios.TIOCSTI](https://stackoverflow.com/questions/29614264/unable-to-fake-terminal-input-with-termios-tiocsti) . At the very end of `.profile`, you can have a perl or python or c program send `emacs\r` to your tty, which will make your shell run it as it you had typed it. – Mark Plotnick Jul 14 '17 at 19:52
  • Thanks a lot, it worked fine for me! Also one cool thing is that sometimes I turn on gnome: "/etc/init.d/gdm3 start" to write this comment for example, and when I turn on terminal in gnome shell, it doesn't run .profile, so it doesn't turn on emacs. – Алр Jul 16 '17 at 20:16

1 Answers1

0

Thanks to Mark Plotnick, who answered below in comments. Using ioctl you can write to own tty. c program:

#include "unistd.h"
#include "stdlib.h"
#include "stdio.h"
#include "sys/stat.h"
#include "sys/types.h"
#include "fcntl.h"
#include "termios.h"
#include "sys/ioctl.h"

int main(int argc, char ** argv)
{
  if (argc >= 3)
    {
      int fd = open (argv[1], O_RDWR);

      if (fd)
    {
      char * cmd = argv[2];
      while(*cmd)
        ioctl(fd, TIOCSTI, cmd++);

      if (argc >= 4)
        ioctl(fd, TIOCSTI, "\r");

      return 0;
    }
      else
    printf("could'n open file\n");

    }
  else
    printf("wrong args\n");
  return -1;
}

compile: gcc my_ioctl.c -o my_ioctl

very end of .profile:

~/my_ioctl $(tty) emacs rr

(my c program does not care about what 3rd arg's actually is).

Алр
  • 11
  • 3