You are not logged in.

#1 2008-10-18 17:39:15

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

dtach bashrc function

i recently discover dtach, i use screen a lot, and someone give me this .bashrc function to make easyer the use of it, so i want to make a similar one for dtach so i can see detached sessions or autoattach it if detached or create them

### Screen Function Mirror in terminal :: scr ###
function scr {
case $TERM in
    xterm*|rxvt*)
    if screen -ls | grep -q Main; then
        screen -xr Main
    else
        screen -S Main
        fi
    ;;
esac
}

i made this one for dtach but not acomplish what i want

### dtach function ###
function detach {
if ls /tmp | grep $1 ;then
    dtach -c /tmp/$1.dtach $1
else
    dtach -a /tmp/$1.dtach
fi
}

but when i use it i get:

[aleyscha@aleyscha 5 ~]$ ls /tmp | grep dtach
mc.dtach=
[aleyscha@aleyscha 6 ~]$ detach mc
mc-aleyscha/
mc.dtach=
dtach: /tmp/mc.dtach: Address already in use
[aleyscha@aleyscha 7 ~]$

Last edited by leo2501 (2008-10-18 17:41:23)


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#2 2008-10-18 18:18:54

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: dtach bashrc function

You mixed up the true and false parts, I think.
If it exists you want to attach to it, not create it.

Anyway using ls is troublesome as you can see by the other results. Try this:

if [ -S /tmp/$1.dtach ]; then
  dtach -a /tmp/$1.dtach
else
  dtach -c /tmp/$1.dtach $1
fi

edit: not -f of course, but -S

Last edited by Procyon (2008-10-18 18:19:47)

Offline

#3 2008-10-18 18:41:19

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Re: dtach bashrc function

Thankyou Procyon! now it works perfect!


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#4 2008-10-19 04:33:28

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: dtach bashrc function

Small warning. I spent a good amount of time making myself a script that extensively used dtach to manage all my terminals - then discovered that I couldn't start up applications in the background when these new dtach-managed terminals were open sad

"app &" worked just fine, but then closing the terminal didn't. "exit" (or in my case, "x") left me with a dead terminal, and after I closed it I had to then figure out which copy of dtach and bash don't have a controlling terminal around them anymore and what their PIDs were, so I could force-kill them too.

-dav7

Last edited by dav7 (2008-10-19 04:35:02)


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#5 2008-10-19 22:45:04

Mashi
Member
Registered: 2007-02-19
Posts: 38

Re: dtach bashrc function

I think dtach has this functionality built in... You're trying to open a process or attach to it if it already exists right?

dtach -A processfile command

Offline

#6 2008-10-19 22:48:03

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Re: dtach bashrc function

Mashi wrote:

I think dtach has this functionality built in... You're trying to open a process or attach to it if it already exists right?

dtach -A processfile command

yes i know, but im lazy and like those great bash functions to do anything with one command smile


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

Board footer

Powered by FluxBB