Wednesday, April 24, 2024
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 8815  / 2 Years ago, wed, january 19, 2022, 12:28:40

I am running Ubuntu 21.04 and I want to create a script, that would do the following:



  1. Run:


    cd && cd path/to/repo && git pull && npm i && code . && npm run dev


  2. Then open a new GNOME Terminal tab using:


    gnome-terminal --tab


  3. Then switch to this tab and run:


    cd && cd path/to/repo && git reset --hard && git pull -f && npm i && npm run dev



So basically I want one terminal with 2 tabs running 2 development servers.


I tried with xdotool and xte, but it never worked (keys aren't even pressed).


Is it even possible to do what I want?


As suggested below I tried, it gave me failed to run cd so I googled and came up with the following:


gnome-terminal --tab -- /bin/bash -e -c "cd path/to/repo && ls && git pull && npm i && code . && npm run dev" --tab -- /bin/bash -e -c "cd path/to/repo && git reset --hard && git pull -f && npm i && npm run dev"


But the problem is that npm run dev is not supposed to ever stop, and so the second terminal tab is not ever opened.
And I need to run them together...


More From » command-line

 Answers
7

Although gnome-terminal indicates that the -e option is deprecated, it still works in 3.40.3.


# Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
# Use “-- ” to terminate the options and put the command line to execute after it.

Developers seem to forget that this is the only way to do what you want, i.e., automatically set up different working environments in tabs. The "new" syntax, that adds commands to run at the end of the options after -- does not allow to do that. Once the -e option is removed, you will need to move to another terminal emulator for something like this.


So this, for example, still works thus far:


gnome-terminal --tab -e "htop" --tab -e "top"

Replace commands htop and top by your custom scripts.


[#1123] Wednesday, January 19, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sigtestim

Total Points: 298
Total Questions: 108
Total Answers: 106

Location: Bermuda
Member since Thu, Apr 20, 2023
1 Year ago
;