4

I'm asking this question because I tried a lot of solutions I found and they all didn't work:

  • gnome-terminal --save-config=... results in an error that this option is no more possible

  • gnome-terminal --tab -- 'vim ~/Files/file.txt' for creating a shell script results in an error, my system is in German but it seems to be like

    There was an error creating the child process for this terminal
    Failed to execute child process "vim ~/Files/file.txt" (No such file or directory)
    

    and does nothing but using just vim without a file to open works

  • using a session manager just opens the Terminal automatically but without any tabs

  • and gnome-terminal --tab -- 'cd ~/Files/' doesn't work either (error like the one above)

The version is # GNOME Terminal 3.28.2 using VTE 0.52.2 +GNUTLS -PCRE2. Maybe there are mistakes in my ways of solving it or you know another (a better) alternative?

Thank you for helping me!

Zanna
  • 69,223
  • 56
  • 216
  • 327
TravelTrader
  • 253
  • 1
  • 10
  • Does [Opening multiple tabs with gnome-terminal](https://askubuntu.com/q/277543/507051) help? – dessert Jan 20 '19 at 09:02
  • 1
    Thank you for the link. I hope I understand it right but setting the variable in `.bashrc` and typing `gnome-terminal --tab -- 'bash -c "export BASH_POST_RC=\"vim todo.txt\"; exec bash"'` doesn't work, too. – TravelTrader Jan 20 '19 at 09:24
  • No, I think you should add the line `eval "$BASH_POST_RC"` (literally!) to the end of your `~/.bashrc` and run e.g.: `gnome-terminal --tab -e 'bash -c "export BASH_POST_RC=\"vim todo.txt\"; exec bash"' --working-directory="$HOME/Files" --tab -e 'exec bash'` I’m not sure about the last ` -e 'exec bash'`, try with and without it. – dessert Jan 20 '19 at 11:49
  • With the last phrase it opens 2 tabs, one with the working-directory and one with the error I had before. And without the last phrase only one tab with the directory. – TravelTrader Jan 20 '19 at 12:14
  • Will something like this do? [Spawn new Terminator tabs from Bash script](//askubuntu.com/a/869846) Also see [How to open terminal, split to 9 terminals and switch between them using one script?](//unix.stackexchange.com/a/168445) – terdon Jan 20 '19 at 13:47
  • Thank you. I'll read about Terminator. Good hint. An other version of `gnome-terminal` isn't a possibility for solving my wish? – TravelTrader Jan 20 '19 at 15:20

2 Answers2

1

The closest I can find that would do this involves creating multiple scripts. gnome-terminal has changed over the years and the -x and --command options have been heavily deprecated. Your best bet is to create profiles for each of the tabs you want to run and use:

gnome-terminal --tab-with-profile=Something1 --tab-with-profile=Something2

If you're using stuff like ~ or * inside your commands it's likely those won't be evaluated since that's actually the job of the shell (bash) whereas gnome-terminal, so it might help to create an actual script somewhere and tell gnome-terminal to use that.

Kristopher Ives
  • 5,419
  • 2
  • 27
  • 36
  • Using `/home/username/` instead of `~/` and it works. Thank you. Maybe there is a more flexible solution because of having to use lots of profiles for different Terminal layouts. – TravelTrader Jan 20 '19 at 09:30
0

The script open new tabs:

  1. saves in pathtabs.list a list of (foo-test) paths to new terminal tabs;
  2. creates a new script autotab.sh to xdotool-FORMAT any list of paths adding controlshiftt shortcuts and cds to commands;
  3. autotab.sh is useful to xdotool format <any-list-of-paths>;
  4. usage: autotab.sh <any-list-of-paths>;
  5. creates foo_* test dirs for the pathtabs.list;
  6. runs ./autotab.sh pathtabs.list and saves output to new script maketabs.sh
  7. maketabs.sh is useful to open the same set of tabs/paths from the original pathtabs.list;

...and runs commands:

  1. saves in pathncommtabs.list a list of (foo-test) paths and commands to run in new terminal tabs;
  2. creates a new script autopctab.sh to xdotool-FORMAT any list of paths and commands adding controlshiftt shortcuts, ; and cds to commands;
  3. autopctab.sh is useful to xdotool format <list-of-paths-and-commands> (see pathncommtabs.list);
  4. usage: autopctab.sh <list-of-paths-and-commands>; (see pathncommtabs.list)
  5. runs ./autopctab.sh pathncommtabs.list and saves the command list to new script makepctabs.sh
  6. makepctabs.sh is useful to open the same set of tabs/paths/commands from the original pathncommtabs.list;
#open-several-tabs-with-xdotool-slowly-and-easily
#!/bin/bash
#pathtabs.list
if [ ! -f ~/pathtabs.list ]; then
echo ~/foo_00 > pathtabs.list
echo ~/foo_00/foo_00_1 >> pathtabs.list
echo ~/foo_00/foo_00_2 >> pathtabs.list
echo ~/foo_00/foo_00_2/foo_00_2_1 >> pathtabs.list
fi
echo 'pathtabs.list: has a list of paths for the new tabs'

#mkdirs
if [ ! -d ~/foo_00/ ]; then
mkdir foo_00
mkdir foo_00/foo_00_1
mkdir foo_00/foo_00_2
mkdir foo_00/foo_00_2/foo_00_2_1
fi
echo 'mkdirs: testing foo_*' 

##commtabs.list
if [ ! -f ~/commtabs.list ]; then
echo nano newfile1.txt > commtabs.list
echo nano newfile2.txt >> commtabs.list
echo nano newfile3.txt >> commtabs.list
echo nano newfile4.txt >> commtabs.list
fi
echo 'commtabs.list: has a list of commands to run on the new tabs'

#pathtabs.list+commtabs.list+options
if [ ! -f ~/pathncommtabs.list ]; then
cat pathtabs.list |sed 's/.*/cd &;/'|sed '1s/^/c+s+t;/'|\
paste - commtabs.list|tr -d '\t' |sed '$!s/$/;c+s+t/' > pathncommtabs.list
fi
echo 'pathncommtabs.list: integrates pathtabs.list+commtabs.list+cd+;+(new-tab-tokens)'

#autopctab.sh <anypathncommtabs.list>
if [ ! -f ~/autopctab.sh ]; then
echo '#!/bin/bash' > autopctab.sh
echo 'cat $1| sed '\''s/ /#/g'\''| sed '\''s/\(.\)/\1 /g'\''|sed '\''s/#/space/g'\''|\
    sed '\''s/~/asciitilde/g'\''|sed '\''s/_/underscore/g'\''|sed '\''s/c + s + t/control+shift+t/g'\''|\
    sed '\''s/\//slash/g'\''|sed '\''s/\./period/g'\''|sed '\''s/;/Return/g'\''|\
    sed '\''s/.*/xdotool key --delay 18  & Return/'\''' >> autopctab.sh
chmod u+x autopctab.sh
fi
echo 'autopctab.sh: xdotool-format paths+commands+(xdotool-commands)'

#run autopctab.sh <pathncommtabs.list>
#makepctabs.sh
if [ ! -f ~/makepctabs.sh ]; then
echo '#!/bin/bash' > makepctabs.sh
./autopctab.sh pathncommtabs.list >> makepctabs.sh
chmod u+x makepctabs.sh
fi
echo 'makepctabs.sh: run xdotool command lines to OPEN new tabs AND RUN commands with pathncommtabs.list'

#autotab.sh <anytabs.list>
if [ ! -f ~/autotab.sh ]; then
echo '#!/bin/bash' > autotab.sh
echo 'cat $1|sed '\''s/.*/cd &/'\''|sed '\''s/ /#/g'\''|\
    sed '\''s/\(.\)/\1 /g'\''|sed '\''s/#/space/g'\''|\
    sed '\''s/~/asciitilde/g'\''|sed '\''s/_/underscore/g'\''|\
    sed '\''s/\//slash/g'\''|sed '\''s/\./period/g'\''|\
    sed '\''s/.*/xdotool key --delay 18 control+shift+t space c d space asciitilde Return & Return c l e a r Return/'\'''  >> autotab.sh
chmod u+x autotab.sh
fi
echo 'autotab.sh: xdotool-format ONLY paths+(xdotool-commands)'

#run autotab.sh <pathtabs.list>
#maketabs.sh
if [ ! -f ~/maketabs.sh ]; then
echo '#!/bin/bash' > maketabs.sh
./autotab.sh pathtabs.list >> maketabs.sh
chmod u+x maketabs.sh
fi
echo 'maketabs.sh: run xdotool command lines ONLY to open new tabs with pathtabs.list'

#run-maketabs?
#./maketabs.sh

#remove-maketabs.sh?

#remove-autotab.sh?
#rm autotab.sh

#remove-pathtabs.list?
#rm pathtabs.list

#run-makepctabs?
#./makepctabs.sh

#remove-makepctabs.sh?
#rm makepctabs.sh

#remove-autopctab.sh?
#rm autopctab.sh

#remove-pathncommtabs.list?
#rm pathncommtabs.list

#remove-dirs?
#rm -r foo_0?

#echo See also 'https://askubuntu.com/a/380320'
#echo '        https://www.semicomplete.com/projects/xdotool/'
#echo '        https://github.com/jordansissel/xdotool'