Here's a script that should work for you.
#!/bin/bash
function chooser {
echo
echo "I found the following screen sessions: "
echo
pcount=0
#
# find the session dir
#
sessdir=$( screen -ls | egrep 'Socket' | awk '{print $NF}' | sed -e 's/\.$//' )
#
# enumerate existing sessions, and add them to the plist() array.
#
for screen in $( find $sessdir -type p ); do
pcount=$((pcount+1))
pname=$( basename $screen )
pdate=$( ls -latr $screen | awk '{print "( "$6" "$7" "$8" )"}')
plist[$pcount]=${pname}
echo " [$pcount] $pname $pdate"
done
echo
echo -n "Please select a session to reconnect to: "
read choice
#
# if the selected choice doesn't exist, recycle the chooser.
#
if [ -z ${plist[$choice]} ]; then
echo
echo "Your choice [$choice] is invalid. Please try again."
echo
sleep 1
chooser
else
screen -r -d ${plist[$choice]}
fi
}
#
# the chooser function does all the work
#
chooser
I didn't distinguish between sessions that are currently attached or detached, so you may have to do that yourself if it matters to you.
I had the same issue when running:
git clone https://github.com/jwiegley/git-scripts.git
cd git-scripts
perl git-forest
I used this as my test. Basically, you should get nice lines is you have utf8 set properly. If not you will get ugly boxes or characters.
The solution is that you need to set LC_ALL
to en_US.UTF-8
BEFORE you start a new screen session. I tired doing it after creating the screen session and had no luck.
Here are the step i followed to get this going:
1) Run locale
to view the current setup. I got this (which explains why i was having issues:
LANG=en_US.UTF-8
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=C
2) Before creating a new screen session, you need to redefine LC_ALL
to en_US.UTF-8
if you are using csh
shell
setenv LC_ALL en_US.UTF-8
if you are using bash
shell
export LC_ALL="en_US.UTF-8"
3) Verify LC_ALL
was set properly, by running locale
again:
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
4) Now run a new screen session and run the git-forest
test and you should see nice lines
Best Answer
From the screen manpage:
As mentioned for the options
-D -RR
, unless you know the status of your session(s), you should check it withscreen -list
.