#!/bin/sh
#CREDIT: This code is written by ~jan6 (https://tilde.team/~jan6/donate.html)

# how to use
# To create a session, run: star-dtach-create <username1> <username2> ... <username4>
# minimum two, max 4-5 usernames
# To join a session, run: star-dtach-create

star_dtach_create(){
 dtach -n /tmp/f0813yr08fs ~login/src/starlanes/starlanes||ex="$?"
 printf "\n$#\n$(for i in "$@";do printf "%s" "$i\n";done)"|
 dtach -p /tmp/f0813yr08fs
 chmod g+rw /tmp/f0813yr08fs
 return $ex
}
star_dtach_attach(){ dtach -a /tmp/f0813yr08fs -e '`';}
star_dtach_delete(){ rm /tmp/f0813yr08fs;}

if [ -n "$1" ];then star_dtach_create "$@"||{ star_dtach_delete;star_dtach_create "$@";}
else                star_dtach_attach;fi
