0

I am trying to execute this custom function stored in my .bashrc

function nvrcreate {
    NVIM_LISTEN_ADDRESS=/tmp/Unity nvim
}

on a new terminal. This command by itself creates a socket for neovim to listen to. If I execute it in a terminal it works great, but I can't get it to work as a single command that opens a new terminal and executes it.

I am using st (suckless / simple terminal) on Manjaro linux. I have tried it using nohup and the -e flag that allows st to execute a command on opening a new terminal, but couldn't manage to have it working.

Also, in most of my attempts, I have gotten some kind of child exited with status 1, and sometimes it simply works for a fraction of a second and then exits.

skink
  • 5,133
  • 6
  • 37
  • 58
  • Functions are local to each shell. You need to source the script that defines the function in the new terminal's shell. – Barmar Aug 08 '20 at 16:56
  • I have it in my .bashrc, so it should be sourced, shouldn't it? – Javier Riera Chirivella Aug 08 '20 at 17:18
  • `.bashrc` is only sourced by bash. If you have `st` run `nvrcreate` *instead of* bash, then obviously it won't work. – that other guy Aug 08 '20 at 18:02
  • In that case, is there any way to do what I ask for? I have seen some people use ```bash -c``` in order to get similar things working, but I simply cannot figure it out. – Javier Riera Chirivella Aug 08 '20 at 18:22
  • This kind of code would be better off in a script than in a function since it doesn't depend on the shell environment, but since you want it as a function, `bash -c 'source ~/.bashrc && nvrcreate'` might be an option. – that other guy Aug 08 '20 at 18:31
  • I ended up doing what you suggested and divided the commands in scripts that are in the PATH, so I don't have to source them or be in a specific folder. Thanks for your help! – Javier Riera Chirivella Aug 09 '20 at 18:11

0 Answers0