FANDOM


Mbm329 04:39, March 12, 2012 (UTC)

WARNING: THIS DOCUMENT IS HERE FOR LEGACY PURPOSES ONLY. IF YOU CURRENTLY USE GNU SCREEN, MORE POWER TO YOU. I DECIDED TO SWITCH TO TMUX AS IT COULD DO EVERYTHING THAT SCREEN COULD DO FOR ME AND MORE WITH LESS OVERHEAD AND NO NEED OF A SPECIAL CLIENT. PLEASE REFERENCE MY SIMILAR DOC FOR TMUX RENUMBERING CONFIGURATION.

Occassionally your windows will become larger than 9 and when you remove some windows in the middle like windows 2 or 5 or the like, you might want to re-number them. Here's a small script I call "screnum". By running it from any window in your session, it will renumber all the windows from 0 in the current session.

It works by...

  1. creating a new session
  2. attaching with "-x" (multi-user mode)
  3. firing up the windowlist
  4. dumping a hardcopy
  5. parsing it
  6. looping through the window numbers

Thanks to Gerald Young for inspiration.

#!/bin/sh

tmpfile=/tmp/screnum.tmp

parent=$(ps -p ${PPID} -o ppid --noheaders | sed 's/\ //g')
session=$(screen -ls | egrep "^[[:blank:]]${parent}\." | awk '{print $1}' | cut -d. -f2-)

screen -D -m -S screnum &
sleep 10 && screen -S screnum -p 0 -X height 60
screen -S screnum -p 0 -X stuff "screen -x ${session} -p =
"
sleep 1 && screen -S screnum -p 0 -X hardcopy ${tmpfile}
screen -S screnum -p 0 -X kill

windowlist=$(awk '/^\ +[0-9]+\ / {print $1}' ${tmpfile})

if [ "${session}" = '' ] ;then
  echo "Can't get session name"
  exit
fi

sleep 1

inum=0
for window in ${windowlist} ;do
  if [ ${window} -gt ${inum} ] ;then
    screen -S ${session} -p ${window} -X number ${inum}
  fi
  inum=$((${inum}+1))
done

rm ${tmpfile}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.