Open sbrl opened 8 years ago
Perhaps also having an option from dtach
outputing the current session name from within a session?
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.
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.
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)
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.
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
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
}
alias dtl="ls -1t ~/.dtach/*" #dtl: detach session list
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: ")'
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:
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?