tty.js icon indicating copy to clipboard operation
tty.js copied to clipboard

Looking for a way to execute a command upon new Terminal creation

Open showwayer opened this issue 12 years ago • 7 comments

Hi,

I wanted to execute a specific command (say ls -a) every time when I open new terminal? I looked into the codebase today but don't know how to modify it to accomplish this. Do you guys have any idea how to do that?

Thanks! Cai

showwayer avatar Feb 23 '13 01:02 showwayer

On Fri, Feb 22, 2013 at 8:55 PM, showwayer [email protected] wrote:

I wanted to execute a specific command (say ls -a) every time when I open new terminal? I looked into the codebase today but don't know how to modify it to accomplish this. Do you guys have any idea how to do that?

Have you looked at adding this to .bash_profile or .bashrc on the server side?

d1rewolf avatar Feb 23 '13 02:02 d1rewolf

Thanks @jbwiv, for following up. Yes, .bashrc did do the job. But I am looking for a solution in the Terminal level, not in the shell (Bash) level. There are small differences between them. ttj.js is the javascript implementation of xterm so it should have "-e program" option to run the command when xterm is launched (see http://www.xfree86.org/current/xterm.1.html). I wondered how I can parse this option in ttj.js for this purpose.

showwayer avatar Feb 23 '13 06:02 showwayer

On Sat, Feb 23, 2013 at 1:49 AM, showwayer [email protected] wrote:

Thanks @jbwiv https://github.com/jbwiv, for following up. Yes, .bashrc did do the job. But I am looking for a solution in the Terminal level, not in the shell (Bash) level. There are small differences between them. Since ttj.js is the javascript implementation of xterm. For xterm, there is a "-e program" option to run the command when xterm is launched (see http://www.xfree86.org/current/xterm.1.html). I wondered how I can parse this option in ttj.js for this purpose.

In your config.json file, you can specify a "shell" option. This can be an arbitrary shell script. For example, I made a bash script which uses "su -c 'command'" to prompt a user for their password and execute a particular command:

#!/bin/bash echo "$HOSTNAME" echo -n "login: " read USER exec su -l -c 'top' $USER

I dropped this in /bin/topsh, and then put this in my config.json:

"shell": "/bin/topsh"

Hope this helps.

John

d1rewolf avatar Feb 23 '13 13:02 d1rewolf

Thank you so much John. This is exactly what I wanted. Originally I ran into an issue, but after I changed the permission to the bash script (forked process needs permission to it), it works pretty well. Thanks again!

showwayer avatar Feb 23 '13 23:02 showwayer

@showwayer : I set the permission for sh file but tty.js window is closed after open. Can you tell me how to do ?

bachvtuan avatar Nov 15 '13 01:11 bachvtuan

can you elaborate on this? trying to do the same but as soon as I add "shell": "/bin/topsh", the terminal closes as soon as it opens.

thatkookooguy avatar Jul 13 '15 13:07 thatkookooguy

You need to add /bin/bash after your script and the terminal will remain open and waiting for a new command

davicompu avatar Feb 11 '16 20:02 davicompu