Is it possible to open and execute commands in new tabs or windows in command-line terminal emulators like ConEmu or Hyper? The ability to manage terminal software windows and tabs as CLI commands would be a grateful feature for programmers if possible.
For example, as an assumed use case, the following scenario can be considered:
hyper --tab --title "Server" --script "cd $HOME/myProject/server && bundle exec rails s" hyper --tab --title "Console" --script "cd $HOME/myProject/server && bundle exec rails c" hyper --tab --title "Specs" --script "cd $HOME/myProject/server && bundle exec guard"@jacquescrocker Selecting a shell on startup in the Hyper terminal emulator
Open a tab in Hyper, wait for .bashrc to execute (or it doesn’t have to be a login shell), and then you can finally execute commands, batch commands, or files.
For example, it’s as inefficient in terms of time consumption for a programmer as having to execute sudo apt update ; sudo apt install package -y separately and wait three times.
In my extreme case, I have several scripts I want to launch at startup, and I was executing them by waiting for terminal and tab launches respectively. Because of that, restarting Windows or swapping SSDs is very reluctant. So, if I can open and execute commands in new tabs, that would be quite good.
However, unfortunately, it seems difficult to do that. Let’s look at an issue posted on Hyper by someone who wants to do exactly that.
Use Hyper CLI to open multiple windows and tabs with configuration · Issue #462 · vercel/hyper
I can tell because the issue is still open, but it seems like the conversation is progressing in the direction that it might be possible to implement. That said, it’s very low activity. I don’t think it will be implemented in 2021.
Guake Terminal has something very similar to this
I found information from this that Guake Terminal has a similar feature, but when it comes to gnome, it’s for Linux machines, right? Ideally cross-platform like Hyper…
So, as I was thinking about various things, I thought “Maybe I can do it with tmux.”
(Installation)
sudo apt update ; sudo apt install tmux -y
(Github)
I wrote an article about tmux before, but I haven’t fully utilized it and don’t really understand what tmux is. I think it’s probably like a terminal emulator emulator.
For example, suppose you have the following function in .bashrc,
and you normally execute web_d in a login shell that has loaded .bashrc.
web_d(){
cd /mnt/c/pg/web/public && http-server -p 8091 &> /dev/null & lt --port 8091 -s hogehoge
}
As mentioned earlier, doing it that way wastes time,
But with tmux, you can do this and it will automatically do the login shell, .bashrc, and command in the background and wait.
tmux new-session -d -s "web_d" 'bash -ic "web_d;"'
When you want to attach, you can do something like tmux attach-session -t web.
There, you can check on demand whether it’s working properly, logging, etc.
For example, the difference between running puppeteer headful or headless could make a difference in CPU usage - that’s also noteworthy.
So, regarding wanting to open and execute commands in new tabs in ConEmu or Hyper, I think there isn’t much difference between physically opening tabs and windows in a terminal emulator to execute commands, and executing in the background and attach-sessioning when you want to check, once you get used to it.
I’m not sure if it’s just my environment being abnormal or WSL1 being slow, but my bash environment takes about 40 seconds to load .bashrc and initialization scripts. (.bashrc is about 35,000 lines)
Because of that, I think this method of executing startup commands using tmux is even more wonderful.