crigler / dtach

A simple program that emulates the detach feature of screen
GNU General Public License v2.0
488 stars 50 forks source link

Suggestion: Have an option that lists all the current sockets #2

Open sbrl opened 8 years ago

sbrl commented 8 years ago

As a user, I'm likely to forget what I called my socket when I created it. I'm also likely to forget that I created one, too. An option to list the currently opened sockets, as well as highlighting the current session, would be really handy. Then I could look up the name of my socket if I forgot its name, and I could check to see if I was connected to a socket currently too.

Here's what I would imagine the output would look like:

Currently open sockets:
    socketname1 - /bin/bash (username1, joe, henry)
    vegetables - /usr/bin/carrot
    *browser - /usr/bin/elinks (sbrl)
    logs - tail -f /var/log/kern.log (logsrus)

The format I chose above was socketname - command[ (connectedusernames). The asterisk (*) in the above example denotes the current session. Perhaps the current session could be made bold, too?

Jiehong commented 8 years ago

Perhaps also having an option from dtach outputing the current session name from within a session?

domo141 commented 8 years ago

dtach does not keep centralized list of sockets all dtach processes uses -- adding such a feature would be quite nontrivial.

On linux one can do

lsof -U | grep dtach

to find all dtach sockets.

sbrl commented 8 years ago

Ah cool. That solves one problem then. Is there also a way to tell which session I'm currently in too?

Then I can do the next best thing and create an alias for each.

domo141 commented 8 years ago

perhaps this & some scripting; compare these:

1) one dtach(1)ed irc session, none attached:

lsof -U | grep dtach

dtach   13084  too    3u  unix 0xffff8800b6e0f440      0t0  858875 tmp/dtach-ircn

2) attaced to that "session"

lsof -U | grep dtach

dtach   13084  too    3u  unix 0xffff8800b6e0f440      0t0  858875 tmp/dtach-ircn
dtach   13084  too    5u  unix 0xffff88003f67fbc0      0t0 1737066 tmp/dtach-ircn
dtach   24279  too    3u  unix 0xffff88003f67f080      0t0 1737065 socket

The first socket is the "server socket" dtach is listening. second is the accepted socket by the daemonized dtach process (same pid) and 3rd is the socket of the connected dtach process.

Now, one can look e.g. more than one same pid on output listing -- or easier might be checking the socket names (or, maybe that '5u' indicates it is socket got by accept(2); found similar output in 2 systems but could not verify from lsof(1) namual page)

oxwivi commented 5 years ago

I'd like to add, besides dtach listing sockets, automatically create new sockets if there are no unattached available, with a command similar to less to sneak peek at current socket state.

ChandrashekarMC commented 11 months ago

As a user, I'm likely to forget what I called my socket when I created it. I'm also likely to forget that I created one, too. An option to list the currently opened sockets, as well as highlighting the current session, would be really handy. Then I could look up the name of my socket if I forgot its name, and I could check to see if I was connected to a socket currently too.

Here's what I would imagine the output would look like:

Currently open sockets:
    socketname1 - /bin/bash (username1, joe, henry)
    vegetables - /usr/bin/carrot
    *browser - /usr/bin/elinks (sbrl)
    logs - tail -f /var/log/kern.log (logsrus)

The format I chose above was socketname - command[ (connectedusernames). The asterisk (*) in the above example denotes the current session. Perhaps the current session could be made bold, too?

I have a workaround to all the suggestions you have made

  1. How to list down all the active dtach sessions? Solution: First I plan to create all the dtach sockets in my home directory, Eg: /home/username/.dtach/dtach_session Now, if I create 4 such sessions in /home/username/.dtach directory, "ls ~/.dtach/*" will list out all the sessions Here is the actual bash function to create
    dtc( ) {                                   #Usage:  dtc <session_name>
    if [ $# != 1 ] ; then                          
      echo "Usage:  dtc  <new dtach session name>"
    fi                                             
    dtach -n ~/.dtach/$1 -r winch  /bin/bash        #Just creates and dtaches a session
    echo "export DTSESS=$1" | dtach -p ~/.dtach/$1  # Sets DTSESS environment variable inside the new session
    echo "dvtm -m ^X -M"    | dtach -p ~/.dtach/$1   # Starts dvtm window manager inside the new session
    dtach -A ~/.dtach/$1 -r winch /bin/bash        # Get into newly created session
    }
  2. How do I list all the existing dtach sessions? Use the below alias alias dtl="ls -1t ~/.dtach/*" #dtl: detach session list
  3. I have some more commands to make life easy.
    a) how to select and open one among the many existing dtach sessions?
    Note: You may need to install fzf command alias dts='dtach -a $(ls -1t ~/.dtach/* | fzf --tac --height=20% --info=inline --prompt "Select: ") -r winch' b) how to select a session for deleting? alias dtd='rm -f $(ls -1t ~/.dtach/* | fzf --tac --height=20% --info=inline --prompt "Select: ")'