Skip to content

Instantly share code, notes, and snippets.

@PRO-2684
Last active August 26, 2026 07:01
Show Gist options
  • Select an option

  • Save PRO-2684/64085fc86af5f684ebf1db5cb8a926ba to your computer and use it in GitHub Desktop.

Select an option

Save PRO-2684/64085fc86af5f684ebf1db5cb8a926ba to your computer and use it in GitHub Desktop.
`speek` - peek into a live screen session

speek

Peek at the current contents of a GNU Screen session without attaching to it.

Usage

speek SESSION

SESSION may be a session name, PID, or full PID.name - same as you'd expect for native screen commands. Bash completion delegates to Screen's own session completion behavior.

Installation

  1. Put speek.sh somewhere in your PATH, for example:

    mv speek.sh ~/bin/speek
    # or
    mv speek.sh ~/.local/bin/speek
  2. Make it executable:

    chmod +x ~/bin/speek
  3. If you use Bash and have bash-completion installed, install the completion script:

    mkdir -p ~/.local/share/bash-completion/completions
    mv speek-completion.sh ~/.local/share/bash-completion/completions/speek
  4. Enjoy!

_speek()
{
local cmd=${COMP_WORDS[0]}
local delegate='screen -x'
local -a orig_words=("${COMP_WORDS[@]}")
local orig_cword=$COMP_CWORD
local orig_line=$COMP_LINE
local orig_point=$COMP_POINT
local -a COMP_WORDS=(screen -x "${orig_words[@]:1}")
local COMP_CWORD=$((orig_cword + 1))
local COMP_LINE="$delegate${orig_line#"$cmd"}"
local COMP_POINT=$((orig_point - ${#cmd} + ${#delegate}))
# https://github.com/cykerway/complete-alias/blob/7f2555c2fe7a1f248ed2d4301e46c8eebcbbc4e2/complete_alias#L834-L840
if declare -F _comp_command_offset >/dev/null; then
_comp_command_offset 0
else
_command_offset 0
fi
}
complete -F _speek speek
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -ne 1 ]]; then
echo "Usage: speek SESSION" >&2
exit 2
fi
tmp=$(mktemp)
trap 'rm -f "$tmp"' EXIT
screen -S "$1" -X hardcopy "$tmp"
cat "$tmp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment