Running bash commands on startup

已查看 73 次
跳至第一个未读帖子

Eric Arnold

未读,
2018年5月1日 14:23:132018/5/1
收件人 ConEmu ML
Forgive me if this is covered somewhere already, I looked and couldn't find an answer to what I want to do.

Is there any way to send a delayed command to a specific terminal window?

I'm running the Windows Linux Subsystem and I'm trying to have a 4-way split window configuration where each quad runs a specific command each time I load it.  I followed the directions from:

and tried this:
-new_console:d:C:\file\path %windir%\system32\bash.exe -cur_console:pm:/mnt --rcfile <(git fetch && git pull)

When I created an instance of the console, it just sat there for a good 10 seconds, then spit back this error message:
"Already: command not found"

I don't know where that is coming from, I've never seen that when I run 'git fetch && git pull' before.  

It also does not appear to source my ~/.bash_alias or ~/.bashrc files as I don't have access to my aliases.

Thanks

Maximus

未读,
2018年5月1日 14:43:202018/5/1
收件人 cone...@googlegroups.com
First of all, running [BashOnWindows in ConEmu](http://conemu.github.io/en/BashOnWindows.html) directly by bash.exe is rather bad choice (at the moment at least). Use default task with connector.

I doubt redirection may work with bash.exe at all, because of its nature.

I believe method with environment variable will work. Just pass it to wsl.

set TO_RUN="git fetch && git pull" & set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl -eTO_RUN -cur_console:pnm:/mnt -t bash -l

--
You received this message because you are subscribed to the Google Groups "ConEmu ML" group.
To unsubscribe from this group and stop receiving emails from it, send an email to conemu_ml+...@googlegroups.com.
To post to this group, send email to cone...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/conemu_ml/c015f2d5-64b0-4b73-898a-507502c5c457%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Arnold

未读,
2018年5月1日 16:22:042018/5/1
收件人 ConEmu ML
Thanks for the quick reply and info about the updated way to run bash.  I updated to 180429 and tried running this command as a task:

set TO_RUN="git fetch && git pull" & set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl -eTO_RUN -cur_console:pnm:/mnt -t bash -l

It does open a new tab, but it doesn't run the git commands once it is loaded.  I also installed the latest Cygwin, but got the same results after that too.

Maximus

未读,
2018年5月2日 10:32:122018/5/2
收件人 cone...@googlegroups.com
Of course it doesn't do that magically.
You have to add few lines to your bashrc, an example in docs.

Eric Arnold

未读,
2018年5月4日 13:56:532018/5/4
收件人 ConEmu ML
Wanted to follow up with the final solution in case anyone else is looking to do something similar.

This this is what my task looks like.  There are 4 bash windows, 2 local and 2 inside a docker container.

set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl -e STARTUP_CMD -e DOCKER_STARTUP_CMD -cur_console:pnm:/mnt -t bash -l -new_console:d:C:\file\path
set "STARTUP_CMD=docker_start_dev" & set "DOCKER_STARTUP_CMD=fms-astart" & set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl -e STARTUP_CMD -e DOCKER_STARTUP_CMD -new_console:s -t bash -l -new_console:d:C:\file\path
set "STARTUP_CMD=sleep 30; queues_monitor" & set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl -e STARTUP_CMD -e DOCKER_STARTUP_CMD -new_console:s1T25V -t bash -l -new_console:d:C:\file\path
set "STARTUP_CMD=docker_start_bash" & set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl -e STARTUP_CMD -e DOCKER_STARTUP_CMD -new_console:s2T33V -t bash -l -new_console:d:C:\file\path

Important bits:
- setting env vars needs to be in the exact format of: set "ENV_VAR_NAME=value1; value2;...".  The quotes go around the var name and the value(s).
- make sure to add "-e ENV_VAR_NAME" for each var you want passed through
- I use 'sleep 30' in one terminal to allow the other commands time to spin up before trying to execute the monitor command
- you need to add code to ~/.profile (or similar script that automatically runs on login) that will check for the env var and execute the command.

Here is the bit I added to handle it:

if [[ -n "${STARTUP_CMD}" ]]; then
  alias auto=${STARTUP_CMD}
  eval ${STARTUP_CMD}
  unset STARTUP_CMD
fi

This will execute the command once, but also gives me a local alias for the same command.  That way, if I need to kill the command in any terminal, I can easily spin it back up again.  The DOCKER_STARTUP_CMD is passed through to 'docker run' with the -e option, and similar code within the container to look for a specific env var and execute the command.  Hope others find this helpful.
回复全部
回复作者
转发
0 个新帖子