I believe the information which session was used last is already present.
There should be no need for a .screen.lastsession file.
Here is a bash script, that looks at the mtime of each socket and
reattaches to the last modified one:

https://gist.github.com/jnweiger/20e54876839fb81e14e50b9eaf9d3915


On Wed, May 7, 2025 at 11:27 AM Vegard Svanberg <veg...@svanberg.no> wrote:

> * Thorsten Glaser <t...@debian.org> [2025-05-05 23:08]:
>
> > how can I find out the last recently used screen, to help a friend…
>
> I don't think screen has the tmux equivalent of hooks...
>
> I haven't thought this through, but two alternatives spring to mind:
>
> A) Add this feature to screen
>
> Shouldn't be too hard I think... just something which writes the session
> name to a (configurable) file somewhere upon creating, attaching and
> detaching.
>
> B) A heartbeat script
>
> Create a new (hidden) screen window and run something like:
>
> while true ; sleep 5 ; echo "$STY" > "$HOME/.screen.lastsession"
>
> Obviously this would still run when the screen is detached, so you'd
> have to add some logic to detect that and pause the update.
>
> You could possible add something in .screenrc to spawn this
> automatically.
>
> Personally, I think I'd patch screen and contribute the code.
>
> Warmly,
>
> Vegard
>
> --
> Vegard Svanberg <veg...@svanberg.no> [*Takapa@IRC (EFnet)]
>
>
>

Reply via email to