Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sbrl opened this issue May 28, 2016 · 6 comments
Open

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

sbrl opened this issue May 28, 2016 · 6 comments

Comments

@sbrl
Copy link

sbrl commented May 28, 2016

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
Copy link

Jiehong commented Jun 23, 2016

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

@domo141
Copy link

domo141 commented Sep 26, 2016

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
Copy link
Author

sbrl commented Sep 27, 2016

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
Copy link

domo141 commented Sep 27, 2016

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
  1. 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
Copy link

oxwivi commented Jan 16, 2019

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
Copy link

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
}
  1. How do I list all the existing dtach sessions? Use the below alias
    alias dtl="ls -1t ~/.dtach/*" #dtl: detach session list
  2. 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: ")'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants