Providing additional init cmds via command line

Providing additional init cmds via command line

Post by Robert Lates » Tue, 27 Jun 2006 22:11:28



Hello,

I'm wondering if it was possible to make an interactive bash shell
execute initial commands through command-line switches. Such as if those
commands had been appended to $(HOME)/.bash_profile.

Reason:
It turns out that on my 4x4 fvwm desktop I always use the same layout
with about 12 open shells, some of which are cd'ed to various
directories and some are ssh'ed to other hosts. Rather than having to
manually cd/ssh each shell to where I want it on each login, I'd like to
have that setup done automatically.

Thanks,
robert

 
 
 

Providing additional init cmds via command line

Post by j.. » Tue, 27 Jun 2006 23:30:56



> I'm wondering if it was possible to make an interactive bash shell
> execute initial commands through command-line switches. Such as if
> those commands had been appended to $(HOME)/.bash_profile.

> Reason:
> It turns out that on my 4x4 fvwm desktop I always use the same
> layout with about 12 open shells, some of which are cd'ed to various
> directories and some are ssh'ed to other hosts. Rather than having
> to manually cd/ssh each shell to where I want it on each login, I'd
> like to have that setup done automatically.

You mean when you login you want this to happen? Or you want to
manually start a shell using some command line arguments?

I'm guessing the former. If so, just put the code in your
.bash_profile and have it check to see if it's already been run once
(check for the existence of the windows you want or something).

For the ssh sessions, setup your .Xsession script to run ssh-agent as
described in http://www.snailbook.com/faq/no-passphrase.auto.html.
Then you can script the ssh session startup in .bash_profile.

 
 
 

Providing additional init cmds via command line

Post by Robert Lates » Wed, 28 Jun 2006 01:44:49


On 26 Jun 2006 09:30:56 -0500,


Quote:> You mean when you login you want this to happen? Or you want to
> manually start a shell using some command line arguments?

> I'm guessing the former. If so, just put the code in your
> .bash_profile and have it check to see if it's already been run once
> (check for the existence of the windows you want or something).

Not quite right - when I log into X (with fvwm) I automatically have a
bunch of xterms (actually mrxvts) pop up with an interactive bash in
each one. Of course all these shells are running initially in my home
directory, but I want them to be at different locations in the source
tree of an app I'm developing. So when I start working in one of these
shells, I first have to cd into the respective directory.

Also in a couple of these shells I always ssh into another host.

What I want is a way to specify varying initial commands -- such as "cd

Hmmm, before opening each xterm I could do a

cp .bash_profile tmp_rc && echo cd foo >> tmp_rc && bash -f tmp_rc

Maybe I'll try that.

robert

 
 
 

Providing additional init cmds via command line

Post by j.. » Wed, 28 Jun 2006 01:57:37



> On 26 Jun 2006 09:30:56 -0500,


> > You mean when you login you want this to happen? Or you want to
> > manually start a shell using some command line arguments?

> > I'm guessing the former. If so, just put the code in your
> > .bash_profile and have it check to see if it's already been run once
> > (check for the existence of the windows you want or something).

> Not quite right - when I log into X (with fvwm) I automatically have
> a bunch of xterms (actually mrxvts) pop up with an interactive bash
> in each one.

How does the "automatically" part work? Are these started up by fvwm
using some saved configuration?

> Of course all these shells are running initially in my home
> directory, but I want them to be at different locations in the
> source tree of an app I'm developing. So when I start working in one
> of these shells, I first have to cd into the respective directory.

> Also in a couple of these shells I always ssh into another host.

> What I want is a way to specify varying initial commands -- such as "cd

> Hmmm, before opening each xterm I could do a

> cp .bash_profile tmp_rc && echo cd foo >> tmp_rc && bash -f tmp_rc

How are the windows being opened? Where would you put those changes?

For the ssh stuff you probably still want to use ssh-agent.

 
 
 

Providing additional init cmds via command line

Post by Steve Alla » Wed, 28 Jun 2006 04:38:53



>On 26 Jun 2006 09:30:56 -0500,


>> You mean when you login you want this to happen? Or you want to
>> manually start a shell using some command line arguments?

>> I'm guessing the former. If so, just put the code in your
>> .bash_profile and have it check to see if it's already been run once
>> (check for the existence of the windows you want or something).

>Not quite right - when I log into X (with fvwm) I automatically have a
>bunch of xterms (actually mrxvts) pop up with an interactive bash in
>each one. Of course all these shells are running initially in my home
>directory, but I want them to be at different locations in the source
>tree of an app I'm developing. So when I start working in one of these
>shells, I first have to cd into the respective directory.

>Also in a couple of these shells I always ssh into another host.

>What I want is a way to specify varying initial commands -- such as "cd


You can run ssh as a shell command when you call xterm in your
.xinitrc file.  For example


When you exit the ssh session, the terminal will also exit since it's
just waiting for that command to end.

For cd'ing to various project directories, setting CDPATH will at least
make that easier, if not automatic.

--
-- Steve

 
 
 

Providing additional init cmds via command line

Post by John DuBo » Wed, 28 Jun 2006 06:39:44




Quote:>Hello,

>I'm wondering if it was possible to make an interactive bash shell
>execute initial commands through command-line switches. Such as if those
>commands had been appended to $(HOME)/.bash_profile.

>Reason:
>It turns out that on my 4x4 fvwm desktop I always use the same layout
>with about 12 open shells, some of which are cd'ed to various
>directories and some are ssh'ed to other hosts. Rather than having to
>manually cd/ssh each shell to where I want it on each login, I'd like to
>have that setup done automatically.

It sounds like you're automatically starting up terminals at specific
locations.  Does fvwm give the your terminal emulator any indication of what
workspace it's been started in?  If so, you could put code in your
.bash_profile for each of the workspaces that does whatever you want.

I don't know how fvwm works, but the window manager I use (pmwm) makes each
window have X coordinates relative to its offset from the currently active
panner workspace.  So, if you have a 4x4 workspace and the "top left" workspace
is active, the top left of that window will have X coordinates (0,0), the top
left of the "top right" workspace will have coordinates of (screen-width,0),
etc.

I want to give my shells knowledge of which workspace they are started in.
To accomplish that, I start with the WINDOWID environment variable set by the
terminal emulator I use (xterm does this too).  I use xwininfo with the
WINDOWID to get its X coordinates.  I use xdpyinfo to get the screen
dimensions.  Trivial math then gives the workspace that this is being run in.
It's only useful at startup, when the active workspace is 0,0 and (until the
workspace is changed) each shell will be running in a window that has X
coordinates that reflect the location of that shell within the panner space.

So, in my .profile I run a program that gathers this information, and code in
.profile stores it for later use, both in a shell variable and in a file (named
by pty) that can be read by other utilities.  One such utility shows me a
ps-like listing of what interesting jobs I'm running, with the workspace each
job is running in (and what key-combination I'd use to go directly to that
workspace :).

The "report what workspace this is" utility is at
ftp://ftp.armory.com/pub/scripts/workspace

        John
--

 
 
 

Providing additional init cmds via command line

Post by Jeremiah DeWitt Weine » Fri, 30 Jun 2006 00:13:41



> It turns out that on my 4x4 fvwm desktop I always use the same layout
> with about 12 open shells, some of which are cd'ed to various
> directories and some are ssh'ed to other hosts. Rather than having to
> manually cd/ssh each shell to where I want it on each login, I'd like to
> have that setup done automatically.

        What about just doing something like this?

#!/bin/bash
( cd /my/first/dir && xterm ) &
( cd /my/second/dir && xterm ) &
xterm -e ssh otherhost1 &
xterm -e ssh otherhost2 &

        Save that as "goodmorning.sh" or whatever, then run that.

--
Oh to have a lodge in some vast wilderness.  Where rumors of oppression
and deceit, of unsuccessful and successful wars may never reach me
anymore.  
        -- William Cowper

 
 
 

Providing additional init cmds via command line

Post by Herbert Popha » Fri, 30 Jun 2006 04:24:10




>>It turns out that on my 4x4 fvwm desktop I always use the same layout
>>with about 12 open shells, some of which are cd'ed to various
>>directories and some are ssh'ed to other hosts. Rather than having to
>>manually cd/ssh each shell to where I want it on each login, I'd like to
>>have that setup done automatically.

>    What about just doing something like this?

> #!/bin/bash
> ( cd /my/first/dir && xterm ) &
> ( cd /my/second/dir && xterm ) &
> xterm -e ssh otherhost1 &
> xterm -e ssh otherhost2 &

>    Save that as "goodmorning.sh" or whatever, then run that.

Insert it into your .xsession, if you have one. If not, create it, and
donm't forget to start your fvwm as well.

Or insert it into fvwm's InitFunction.

You may well use constructs like

xterm -e sh -c 'cd /to/my/place; exec /bin/bash'

my 2 cents
Herbert