Screen: Difference between revisions

From Halfface
Jump to navigation Jump to search
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Start program in screen.=
screen -d -m
=Split=
CTRL + a -> S
=Help=
CTRL + a -> ?
=Move between split screen=
CTRL + a -> tab
=Show window list=
CTRL + a -> "
=Copy/History mode(Search via ? and /)=
CTRL + a -> ESC
=Show only this window=
CTRL + a -> Q
=Paste=
CTRL + a -> [
=Name a window=
CTRL + a -> A
=Move or swap window position/number=
:number is literary as it stands here. (:number). 2 is where you want to move window.
CTRL + a -> :number 2
=detatch screen inside screen=
CTRL + a -> a -> d
=Rename screen session.=
CTRL + a -> :sessionname new-session-name
=Wrap=
CTRL + a -> r
=Wrap no=
CTRL + a -> CTRL + r
=Visual bell=
CTRL + a -> CTRL + g
=Move tab in split screen=
CTRL + a -> CTRL + i
=Close split screen=
CTRL + a -> X
=Cannot open your terminal '/dev/pts/0' - please check=
sudo su - user causes problems...
script /dev/null
=external links=
=external links=
http://www.gnu.org/software/screen/manual/screen.html
http://www.gnu.org/software/screen/manual/screen.html
=functions=
=functions=
<pre><nowiki>
<pre><nowiki>
# Setup a screen session for an environment.
screen_site(){
  local SITE SAVEIFS NUMBER MACHINE TITLE
  SITE=${1}
  SCREENSESSION=$(screen -ls | grep .${SITE})
  if [ "${SCREENSESSION}" ]
  then
    echo "Screen ${SITE} exists. Conncting to:"
    echo "${SCREENSESSION}"
    sleep 2
    screen -rx ${SITE}
    return
  else
    SAVEIFS=${IFS}
    NUMBER="0"
    IFS=$(echo -en "\n\b")
    screen -S ${SITE} -d -m
    for ROW in $(echo -e "${!SITE}")
    do
      MACHINE=$(echo ${ROW} | awk '{print $1}')
      TITLE=$(echo ${ROW} | awk '{print $2}')
      screen_ssh ${SITE} ${NUMBER} ${MACHINE} ${TITLE}
      NUMBER=$((NUMBER +1))
    done
    IFS=${SAVEIFS}
    screen -r ${SITE}
  fi
}
# Create new window and give it a title and connect to machine.
screen_ssh(){
    local SITE NUMBER MACHINE TITLE
    SITE="${1}"
    NUMBER="${2}"
    MACHINE="${3}"
    TITLE="${4}"
    if [ "${NUMBER}" -ne 0 ]
    then
      screen -S ${SITE} -X screen ${NUMBER}
    fi
    screen -S ${SITE} -X -p ${NUMBER} select ${NUMBER}
    screen -S ${SITE} -X -p ${NUMBER} title "${SITE}_${TITLE}"
    screen -S ${SITE} -X -p ${NUMBER} exec ssh -Y "${MACHINE}"
    screen -S ${SITE} -X -p ${NUMBER} wall "Connected to ${MACHINE} ${TITLE}"
}
# Group of machines machines needed by screen_site.
T1="10.1.93.10 RAPPO
10.1.21.10 NAPS1
10.1.21.11 NAPS2
10.1.21.12 NAPS3
10.1.21.13 NAPS4
10.1.21.14 NAPS5
10.1.21.15 NAPS6
10.1.21.16 NAPS6
10.1.21.40 NAPSGH1
10.1.21.50 NAPS-HELP
10.1.21.150 PLS1
10.1.21.151 PLS2"
# Run a command in a group of windows.
# Run a command in a group of windows.
screen_cluster(){
screen_cluster(){
Line 79: Line 60:
     for SCREEN in ${SCREENS}
     for SCREEN in ${SCREENS}
     do
     do
       screen -S ${SESSIONNAME} -p ${SCREEN} -X stuff "${COMMAND}
       screen -S ${SESSIONNAME} -p ${SCREEN} -X stuff "^A#
${COMMAND}
"
"
       if [ $? -ne 0 ]
       if [ $? -ne 0 ]
Line 116: Line 98:
   fi
   fi
}
}


</nowiki></pre>
</nowiki></pre>

Latest revision as of 15:36, 18 November 2020

Start program in screen.

screen -d -m

Split

CTRL + a -> S

Help

CTRL + a -> ?

Move between split screen

CTRL + a -> tab

Show window list

CTRL + a -> "

Copy/History mode(Search via ? and /)

CTRL + a -> ESC

Show only this window

CTRL + a -> Q

Paste

CTRL + a -> [

Name a window

CTRL + a -> A

Move or swap window position/number

number is literary as it stands here. (:number). 2 is where you want to move window.
CTRL + a -> :number 2

detatch screen inside screen

CTRL + a -> a -> d

Rename screen session.

CTRL + a -> :sessionname new-session-name

Wrap

CTRL + a -> r

Wrap no

CTRL + a -> CTRL + r

Visual bell

CTRL + a -> CTRL + g

Move tab in split screen

CTRL + a -> CTRL + i

Close split screen

CTRL + a -> X

Cannot open your terminal '/dev/pts/0' - please check

sudo su - user causes problems...

script /dev/null

external links

http://www.gnu.org/software/screen/manual/screen.html

functions

# Run a command in a group of windows.
screen_cluster(){
  if [ $# -lt 3 ]
  then
    echo "You wrote: ${FUNCNAME} ${@}"
    echo "${FUNCNAME} SESSIONNAME 'command' SCREENS"
    SESSIONNAMES=$(screen -ls | grep -E '[[:blank:]][0-9]{2,}' | awk '{print $1}' | sed 's/^[0-9.]*//g')
    echo "SESSIONNAME available are:"
    echo "${SESSIONNAMES}"
  else
    SESSIONNAME=${1}
    COMMAND=${2}
    shift 2
    SCREENS="${@}"
    for SCREEN in ${SCREENS}
    do
      screen -S ${SESSIONNAME} -p ${SCREEN} -X stuff "^A#
${COMMAND}
"
      if [ $? -ne 0 ]
      then
        screen_cluster
        return 1
      fi
    done
  fi
}

# Split screen in regions with wanted windows.
screen_split(){
  if [ $# -lt 2 ]
  then
    echo "Splits screen in regions and show chosen windows."
    echo "${FUNCNAME} SESSIONNAME SCREENS"
  else
    SCREENSESSION="${1}"
    shift
    WINDOWSTART="${1}"
    NUMBERSCREEN="${#}"
    shift
    WINDOWSOPEN="${@}"
    screen -S ${SCREENSESSION} -p ${WINDOWSTART} -X select ${WINDOWSTART}
    screen -S ${SCREENSESSION} -p ${WINDOWSTART} -X only
    sleep 0.2
    for WINDOWOPEN in ${WINDOWSOPEN}
    do
      sleep 0.2
      screen -S ${SCREENSESSION} -p ${WINDOWSTART} -X split
      screen -S ${SCREENSESSION} -p ${WINDOWSTART} -X focus
      screen -S ${SCREENSESSION} -p ${WINDOWOPEN} -X select ${WINDOWOPEN}
    done
    screen -S ${SCREENSESSION} -p ${WINDOWSTART} -X wall "Opened ${NUMBERSCREEN} screen windows"
  fi
}