4

I'm trying to write a simple script that starts a terminal and runs the command workon foo. In other words, I just want to do:

mate-terminal -e workon foo

However, that doesn't work because the workon command requires me to first do:

export WORKON_HOME=~/work;
source /usr/local/bin/virtualenvwrapper.sh

Normally those lines are run automatically because they're in my .bashrc, but evidently mate-terminal -e doesn't do a source ~/.bashrc. However, if I try adding those lines to my script:

mate-terminal -e export WORKON_HOME=~/work; source /usr/local/bin/virtualenvwrapper.sh; workon foo

it doesn't work either. MATE tells me:

There was an error creating the child process for this terminal
Failed to execute child process "export" (No such file or directory)

I have the same problem if I skip the export and just do mate-terminal -e source ... or if I try to use . instead of source (mate-terminal -e . ...).

I'm not sure how I can load anything if I can't, export, source, or ., but there must be some way because mate-terminal -e would be almost useless without it.

Does anyone know how I can I setup my environment in a terminal started with mate-terminal -e?

machineghost
  • 1,296

2 Answers2

2

How about you run it in a script?

so create your script:

touch ~/myscript.sh
chmod 700 ~/myscript.sh
vi ~/myscript.sh

then edit it to what you want it to do. In vi use i to insert and be careful of using backspace,use ESC then X to delete. Then do ESC and then !qw to save and exit:

#!/bin/bash
export WORKON_HOME=~/work;
source /usr/local/bin/virtualenvwrapper.sh
mate-terminal -e workon foo

then try and run it:

./myscript.sh
boopzz
  • 56
2

I do not have a version installed of mate-terminal, but if it works similarly to gnome-terminal you can try one of this ways:

  • to write directly something like
    mate-terminal -e bash -c 'WORKON_HOME=$HOME/work; source /usr/local/bin/virtualenvwrapper.sh; workon foo'
    or
    mate-terminal -e "bash -c 'WORKON_HOME=$HOME/work; source /usr/local/bin/virtualenvwrapper.sh; workon foo; read line'"

    (to be honest in gnome-terminal you should use -x instead of -e).

  • To create your executable script (named WorkOnScript.sh, with chmod u+x WorkOnScript.sh)

    #!/bin/bash 
    WORKON_HOME=$HOME/work;
    source /usr/local/bin/virtualenvwrapper.sh
    cd $HOME/work                                          # If needed
    workon foo
    sleep 10s         # to add  a pause before script and terminal end
    read line         # to wait you press return to close the terminal
    

    and to try to execute it with

     mate-terminal -e /path/to/WorkOnScript.sh
    

    or

     mate-terminal -e "/bin/bash -c \"/path/to/WorkOnScript.sh\""
    

Note

It is possible to keep the terminal open adding as last command in the string passed to bash -c or as last line of the script:

  • for some seconds (or hours...) adding sleep 10s (or sleep 10h).
  • until is pressed return adding read line
  • until ctrl+d or exit is pressed adding /bin/bash (it executes a shell).

With some terminal via parameter specification it possible to keep it open after the execution of the commands. With mate-terminal you can try to see what is interesting from mate-terminal --help-all. After that you have created a profile with "Hold the terminal" checked you can invoke the terminal with the option --window-with-profile=PROFILENAME or --tab-with-profile=PROFILENAME

References

Hastur
  • 19,483
  • 9
  • 55
  • 99