tty.js
tty.js copied to clipboard
Looking for a way to execute a command upon new Terminal creation
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
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?
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.
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
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 : I set the permission for sh file but tty.js window is closed after open. Can you tell me how to do ?
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.
You need to add /bin/bash after your script and the terminal will remain open and waiting for a new command