Advanced GNU Screen Customization: Window Management, Scroll Shortcuts, and Status Bar Configuration


3 views

GNU Screen's window numbering can become messy after prolonged use. Here's how to regain control:

# Rename current window
Ctrl+A, :title "New Window Name"

# Create new window at specific number
Ctrl+A, :screen -t "Window9" 9 your_command

# Reorder windows (in .screenrc)
bind c screen -t "Window4" 4
bind 4 select 4

For moving existing windows between numbers, use this sequence:

1. Ctrl+A, :number 4   # Move current window to position 4
2. Ctrl+A, :windowlist # Verify the new order
3. Ctrl+A, :reset      # Reset window numbers sequentially

Modify your ~/.screenrc to implement better scrolling:

# Enable copy mode with F5
bindkey -k k5 copy

# Map PgUp/PgDn for scrolling
bindkey -k kP eval "copy" "stuff ^u"
bindkey -k kN eval "copy" "stuff ^d"

# Alternative: Use vi-style keys in copy mode
bindkey -m "^B" stuff ^b
bindkey -m "^F" stuff ^f

For comprehensive status bar information, use this configuration:

# In .screenrc
caption always "%{= kw}%-w%{=bw}%n %t%{-}%+w %=%d %M %0c %{g}%H%{-}"

# To include log file info
hardstatus alwayslastline "%{= kw}%H %{=bw}%l %{= kw}%c %{=bw}%D %d/%m/%Y %{= kw}%L%{-}"

For dynamic logging status display:

# Add this shell escape to your caption
shelltitle '$ | echo "[logging: $STYLOG]"'
defshell -bash

Here's a complete .screenrc snippet combining these features:

# Window management
escape ^Aa
startup_message off
autodetach on

# Scroll settings
bindkey -k k5 copy
bindkey -k kP eval "copy" "stuff ^u"
bindkey -k kN eval "copy" "stuff ^d"

# Status bar with logging info
hardstatus alwayslastline "%{= kw}%H %{=bw}[%n %t] %{= kw}Log:%{=bw}%L %{= kw}%l %c"
caption always "%?%F%{.R.}%?%3n %t%?%F%{.g.}%?%F%{-}%?%+w %=%<%="

# Logging control
bind L log
bind C logfile screenlog.%n

Remember to reload your configuration after changes:

Ctrl+A, :source ~/.screenrc

GNU Screen's window numbering can become fragmented over time. Here's how to manage window ordering:

# Create new window at specific number
screen -S session_name -X screen -t "Window9" 9

# Move window 6 to position 4 (requires closing and reopening)
C-a :number 6 4

# Alternative method using windowlist
C-a " (windowlist) then navigate to window and press r to renumber

Modify your .screenrc to implement better scroll controls:

# Map F5 to enter copy mode
bindkey -k k5 copy

# Map PgUp/PgDn for scrolling in copy mode
bindkey -m "^[O" stuff ^u  # PgUp
bindkey -m "^[O" stuff ^d  # PgDn

# Alternative solution using less common keys
bind -m '^[[5~' stuff ^u  # PgUp
bind -m '^[[6~' stuff ^d  # PgDn

To display logging information in your caption bar, add this to .screenrc:

caption always "%{= kw}%-w%{= BW}%n %t%{-}%+w %=%d %M %0c %{g}%(logfile: %{y}%`basename %l`%{g} [%{y}%L%{g}])%{-}"

Breakdown of the format string:

  • %l: Full path to logfile
  • %L: Logging status (ON/OFF)
  • %`basename %l`: Shows just the filename without path

For complex window reordering, use this script approach:

#!/bin/bash
# Save current window setup
screen -S mysession -p 2 -X stuff "exit^M"
screen -S mysession -p 3 -X stuff "exit^M"
screen -S mysession -X screen -t "new2" 2
screen -S mysession -X screen -t "new3" 3

If key bindings don't work as expected, test key codes first:

# In screen, type Ctrl-a then :
exec echo -n "Key code: " > keytest; cat >> keytest

# Then press your target key combination
# View keytest file to see the actual code sequence