Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

Various GNU Screen tweaks and hacks.

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
12 posts • Page 1 of 1
Author
Message
Leffe
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 145
Joined: Wed Apr 07, 2004 12:51 pm
Location: Sweden
Contact:
Contact Leffe
Website

Various GNU Screen tweaks and hacks.

  • Quote

Post by Leffe » Wed Nov 24, 2004 8:13 pm

Portage titles in GNU Screen

Requirements
  • Having GNU Screen installed.
  • Preferably running in console mode.
  • A text editor.
  • Perhaps some Python experience.
  • Some general hacking experience is never bad either.
Intended target audience

Screen users and X dislikers.

Contents
  • Screen titles when using emerge
  • Titles when using bash
  • Nicer titlebar
  • Copying and pasting
  • Links
Screen titles when using emerge

First of all, open up /usr/lib/portage/pym/output.py in your editor of choice.

Scroll down to xtermTitle on line 36.

Just add this piece of code after the line myt=os.environ["TERM"]:

Code: Select all

    if myt.startswith("screen"):
        sys.stderr.write("\x1bk"+str(mystr)+"\x1b\\")
        sys.stderr.flush()
Save the file and emerge something, emerge moo perhaps. You will see that the title briefly changes during the emerge. Try emerging several real packages and see how useful this is :)

If you have no titlebar, either split the window with C-a S or do a C-a : and enter caption always.

Possible problems

You might have to remove the output.pyc and or output.pyo from the directory where output.py is stored, I doubt it though.

Titles when using bash

Ah, nevermind, newer versions of baselayout's (?) /etc/skel/.bashrc already does this.

In case you do not have the newer version, here it is:

Code: Select all

case $TERM in
    xterm*|rxvt|Eterm|eterm)
        PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
        ;;
    screen*)
        PROMPT_COMMAND='echo -ne "\033k${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
        ;;
esac
Note that mine is different from the official version, if the official version does not work (which it really should not, but somehow it did once for me) try mine instead, I just added a * to screen and replaced an _ with a k.

Nicer titlebar

The default Screen titlebar doesn't look that good, this is what I use, it looks a bit better in my opinion:

Code: Select all

caption string "%?%F%{= Bk}%? %C%A %D %d-%m-%Y %{= kB} %t%= %?%F%{= Bk}%:%{= wk}%? %n "
Put it in your ~/.screenrc or enter it with C-a :. I can't remember how to source a config file from inside Screen right now :(

Copying and pasting

This is one of my favorite features of Screen, the ability to copy any text you see and paste it anywhere you can enter text. I can't say I've mastered it yet, but I know enough to use it.

To copy, press C-a [, then move around with the arrow keys or vi-style keys until you get to the place where you would like to start copying, press enter there and move to the end of your text, press enter there and the text will be copied. Something you'll want to do often is select to the end of a line, use $ for that.

To paste the text you have copied, go to where you want it, in an editor perhaps, and press C-a ], the text will be entered. If you are doing this in vim the autoindentation might play some tricks on you, it can be disabled though using :set paste.

Screen Links

GNU Screen homepage
A Screen FAQ
GNU Screen: an introduction and beginner's tutorial
man 1 screen
Last edited by Leffe on Wed Dec 15, 2004 2:59 pm, edited 7 times in total.
Top
Leffe
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 145
Joined: Wed Apr 07, 2004 12:51 pm
Location: Sweden
Contact:
Contact Leffe
Website

  • Quote

Post by Leffe » Mon Dec 13, 2004 11:44 am

age for quite a lot of new content.
Top
Wormo
Retired Dev
Retired Dev
Posts: 526
Joined: Mon Nov 29, 2004 12:53 am
Location: SB County California

Re: Various GNU Screen tweaks and hacks.

  • Quote

Post by Wormo » Tue Dec 14, 2004 11:19 pm

Leffe wrote:Portage titles in GNU Screen

Copying and pasting

This is one of my favorite features of Screen, the ability to copy any text you see and paste it anywhere you can enter text. I can't say I've mastered it yet, but I know enough to use it. Knowing how to select to the end of a line would really help.

To copy, press C-a [, then move around with the arrow keys or something until you get to the place where you would like to start copying, press enter there and move to the end of your text, press enter there and the text will be copied.

To paste the text you have copied, go to where you want it, in an editor perhaps, and press C-a ], the text will be entered. If you are doing this in vim the autoindentation might play some tricks on you... it can be disabled though.
The default cursor movements in screen copy/paste mode are vi-like. Moving to the end of line is done by '$', jumping to the next word is 'w', and so on. Very powerful! :D

Also, since you brought up vim... a quick way to get vim to behave for pasting (whether gpm, X, or screen) is to first use

Code: Select all

:set paste
Then after the paste is done, you can get back any fancy indenting settings with

Code: Select all

:set nopaste
Top
Leffe
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 145
Joined: Wed Apr 07, 2004 12:51 pm
Location: Sweden
Contact:
Contact Leffe
Website

  • Quote

Post by Leffe » Wed Dec 15, 2004 12:14 pm

Thanks a lot! Added it to the article.
Top
adsmith
Veteran
Veteran
Posts: 1386
Joined: Sun Sep 26, 2004 6:59 pm
Location: NC, USA

  • Quote

Post by adsmith » Wed Dec 15, 2004 1:42 pm

I use screen all the time. A maximaized xterm running screen is my most common window open in X. Fantastic program.

Anyway, one annoying thing is that screen doesn't properly use "Tab" as a key, apparently; I think it just sends a pile of spaces. So, as far as I can tell, there is no way to bind Ctrl-Tab to switch between session windows.... grr...
Has anyone found a way around this?

Also, I like this baseline better

Code: Select all

hardstatus alwayslastline "%{b}[ %{B}%H %{b}][ %{w}%?%-Lw%?%{b}(%{W}%n*%f %t%?(%u)%?%{b})%{w}%?%+Lw%?%?%= %{b}][%{B} %m/%d %{W}%C%a %{b}]"
Last edited by adsmith on Wed Dec 15, 2004 1:48 pm, edited 1 time in total.
Top
adsmith
Veteran
Veteran
Posts: 1386
Joined: Sun Sep 26, 2004 6:59 pm
Location: NC, USA

  • Quote

Post by adsmith » Wed Dec 15, 2004 1:44 pm

By the way, here that file is in

Code: Select all

/usr/lib/portage/pym/output.py
Note the /pym/
Top
Leffe
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 145
Joined: Wed Apr 07, 2004 12:51 pm
Location: Sweden
Contact:
Contact Leffe
Website

  • Quote

Post by Leffe » Wed Dec 15, 2004 3:01 pm

adsmith wrote:By the way, here that file is in

Code: Select all

/usr/lib/portage/pym/output.py
Note the /pym/
That would be a typo :)

I updated the section on the bash title to hopefully make it work. I can't understand how the original code actually worked for me, it's impossible.
Top
Wormo
Retired Dev
Retired Dev
Posts: 526
Joined: Mon Nov 29, 2004 12:53 am
Location: SB County California

  • Quote

Post by Wormo » Thu Dec 16, 2004 7:20 am

adsmith wrote: Anyway, one annoying thing is that screen doesn't properly use "Tab" as a key, apparently; I think it just sends a pile of spaces. So, as far as I can tell, there is no way to bind Ctrl-Tab to switch between session windows.... grr...
Has anyone found a way around this?
Actually, screen has no problem with "Tab" at all. There is a default binding for Ctrl-Tab to switch between "regions" rather than "windows", but I was able to re-bind it to switch between windows just fine:

Code: Select all

:bind ^I next
Speaking of "regions", that is another nifty screen feature that I have recently discovered: ability to split the screen so you can see multiple sessions at once. This is the equivalent to using

Code: Select all

:sp
command in vim (which I find extremely useful). Default keybinding for regions includes

Code: Select all

ctrl-a S
to split the window,

Code: Select all

ctrl-a X
to delete current region, and

Code: Select all

ctrl-a TAB
to switch focus between regions (assuming you didn't re-bind tab).
Top
Xk2c
Apprentice
Apprentice
User avatar
Posts: 240
Joined: Sat Jul 17, 2004 3:10 am

  • Quote

Post by Xk2c » Thu Dec 16, 2004 4:44 pm

adsmith wrote:I use screen all the time. A maximaized xterm running screen is my most common window open in X. Fantastic program.

<snip>

Also, I like this baseline better

Code: Select all

hardstatus alwayslastline "%{b}[ %{B}%H %{b}][ %{w}%?%-Lw%?%{b}(%{W}%n*%f %t%?(%u)%?%{b})%{w}%?%+Lw%?%?%= %{b}][%{B} %m/%d %{W}%C%a %{b}]"
In my opionen it is better to use the feature caption always instead of hardstatus.
The advantage of caption always is, that the Xterm Title
still behave like common.

If your interrested here is my ~/.screenrc:
http://forums.gentoo.org/viewtopic.php? ... 55#1886655
useful Xterm, Aterm and RXVT-Unicode features
Top
Wi1d
Apprentice
Apprentice
User avatar
Posts: 282
Joined: Mon Mar 15, 2004 3:46 pm
Location: USA, Iowa
Contact:
Contact Wi1d
Website

My simple, yet semi-thorough, tutorial on using gnu-screen

  • Quote

Post by Wi1d » Thu Sep 08, 2005 7:31 am

Argh. I searched, wrote the howto to, then searched one more time and found this thread. :( No need to start a new post I guess and I don't want to waste the howto. Btw, excellent tips.

My simple, yet semi-thorough, tutorial on using gnu-screen

What is it and what does it do?

Screen is often described as a terminal multiplexer. It can be found on any *nix distro and cygwin even has a port. So what is it useful for?
  • It's great if you like to use many command-line applications. If you have to remote connect a lot it's like you can access your desktop from anywhere.
  • Gives you the ability to disconnect from a "session", log off the machine, and reconnect later on. This is great when your updating a nix box or running any time consuming command.
  • You can customize it's looks and create your own keybindings
  • It eliminates the need to have several terminals opened.
  • It has an edit mode which is damn useful when reading system logs, lots of output, or other big files.
Examples of screen in action

One of my screen sessions
Image

A split screen session
Image

Putting screen in action

First thing first. Install screen:

Code: Select all

# emerge -av screen
Now that it's installed you can simply start a session by typing "screen" from the command prompt. This sucks though because you are letting screen create it's own names for each session and they can be unusual. I usually start a session like "screen -S main", "screen -S update", or name it after whatever commands the session will be executing.

Once you've started you can open a new session inside of screen by typing "ctrl-a, c". Once your ready to disconnect from the session type "ctrl-a, d". When you are ready to reconnect type "screen -r" at the command line or "screen -x" if the session is already attached and you've ssh'd in and want to connect the that particular session.

Here is a short list of other default keybindings:
  • ctrl-a ctrl-a (jumps back and worth between two sessions.)
  • ctrl-a shift-s (splits screen)
  • ctrl-a shift-x (undo split)
  • ctrl-a " (give list of screens)
  • ctrl-a spacebar OR n (move to next screen)
  • ctrl-a backspace OR p (move to previous space)
  • ctrl-a shift-? (help)
Customizing

You can change the way screen looks and behaves by modifying your ~/.screenrc file. One of the first things I do is add some of my own keybindings. Examples:

Code: Select all

bind C screen -t "ncmpc" 0 ncmpc
bind M screen -t "mutt" mutt -y
bind i screen -t "irssi" irssi
bind R screen -t '%{rb} |root' sudo -s -H
bind Q screen -t "qjots" vi ~/.quickjots
bind Y screen -t "yafc" 9 yafc
bind a screen -t "abook"  abook
bind t screen -t "torrent"
bind T screen -t "top" sudo top
bind s screen -t 'mysql' mysql -p
bind D screen -t "dict" w3m -cookie www.freedictionary.org
bind E screen -t "encyc" w3m -cookie en.wikipedia.org/wiki/Main_Page
bind N screen -t "note" note
bind P screen -t "lookup" w3m -cookie http://local.google.com/lochp
bind W screen -t "www" w3m -cookie -B
bind V screen -t 'vim' vim
bind L screen cmatrix -f -s -C blue
bind A screen -t 'mixer' alsamixer
bind m screen -t 'metasploit' ~/tools/exploits/framework-2.4/msfconsole
bind v screen -t 'vpn' sudo ~/vpn.sh
Once thing that gets old really quick if you use screen is having to type "ctrl-a n" and "ctrl-a p" to navigate between your screens. I've changed this in my config file by adding a smoother keybinding like "ctrl-left arrow" and "ctrl-right arrow. Since the keybinding is often different I'll show you how to do in your configuration file.
  • open up in and editor ~/.screenrc. I think this will work with any editor but know it will for sure with vim.
  • Now you want to type something similiar to this:

    Code: Select all

    bindkey "^[Oc" next
    bindkey "^[Od" prev
  • The thing that might be different is the "^[Od" part. To get the right code you need to press "ctrl-v" then keep holding down the ctrl key and press one of the arrow keys.
Another thing you can do is modify the "hardstatus" in your screenrc file. This is how you can add the tabbed menu at the bottom like in my examples above. Here is what my hardstatus line looks like. To get a grasp on how to change the variables and colors read the man page.

Code: Select all

hardstatus alwayslastline "%{dw} \\\\ %{dB}%50`%{dw} \\---\\\\ %{dB}%-w%-u%50>%{Kw}%n-%t%{dB}%+u%+w%<%> %{dB}\\%=%{dw}\\\\%{dB} Time:%{dw}%C %{dB}%D%{dw} \\"
sorendition = wb
You can also execute commands and use the output in the hardstatus by using "backtick". Add somthing like this in your .screenrc:

Code: Select all

backtick 50 0 0 hostname
Now anywhere in the hardstatus like you put "%50`" the output of the command hostname will magically appear there.

Here is another creative example in how to put your outside weather in screen ;).

Add a similiar entry in your crontab:

Code: Select all

  */15    *       *       *       *       curl -s http://weather.noaa.gov/weather/current/ABCD.html | grep 'F (' | head -n 1 | awk {print $3 " " $4}' > /tmp/temperature
Create a similiar script:

Code: Select all

#!/bin/sh 
while :
do
    cat /tmp/temperature
    sleep 16m
done
And then add a "backtick" into your screenrc kind of like this:

Code: Select all

backtick 52 0 0 watch-weather
Now where every you put "%52`" in the "hardstatus line" your current weather will be displayed. example:

Code: Select all

hardstatus alwayslastline "%{dr} %D %C%A %{dd} %{Bw}%-w%{db}%50>%n %t%{dw}%+w%<%>%{dd} %=5%{wB} (%{wr}%52`%{wB})%{wr}   %50` "
Well anyhow that's it for my "simple yet semi-thorough" turorial on using screen. It's just one of those command line applications, like vim for example, that the more you play with it the more you see what it can do.
Top
lucapost
Veteran
Veteran
User avatar
Posts: 1420
Joined: Thu Nov 24, 2005 4:33 pm
Location: <ud|me|ts> - Italy
Contact:
Contact lucapost
Website

  • Quote

Post by lucapost » Sat Apr 19, 2008 10:12 am

I have a problem to set background/foreground color via hexadecimal syntax in ~/.screenrc .
Can you help me?
This is my caption:

Code: Select all

caption always '%{wb}%?%-Lw%?[%n*%f%t%?(%u)%?]%?%+Lw%?%? %-= @%H'

What can I change this in hex ???

Code: Select all

%{wb}   >>> %{ ???????? }   
LP
Top
eccerr0r
Watchman
Watchman
Posts: 10239
Joined: Thu Jul 01, 2004 6:51 pm
Location: almost Mile High in the USA
Contact:
Contact eccerr0r
Website

  • Quote

Post by eccerr0r » Sat Sep 15, 2018 2:00 pm

I don't know how people are dealing with this, but I think I inadvertently found a cute way to deal with world updates that involve gnu-screen.

The problem:

# note that there's a gnu-screen update hidden in the mix of world updates...
screen
emerge -uDN @world
<detach>
logout

<wait until tomorrow>
screen -r

OH NO! I can't connect back to my gnu-screen session because it updated!!! :(

I inadvertently found my current favorite way to prevent this problem by abusing portage's protection:

Simply:
# cd ~root
# rm -f screen-old; ln /usr/bin/screen-* screen-old

This will create a hardlink of the SUID screen binary which is VERY evil. However *You* did it, and you did it explicitly, so that's not a problem. With the link in place, portage will find this hardlinked SUID binary when it tries to unmerge the old version and FAIL -- preserving your old screen binary and you can still use the old version to reattach to your screen session!

Then when your emerge is done, remove the ~root/screen-old and emerge screen by itself outside of gnu-screen... problem averted!

Hope this tip saves some heartaches if you forget to emerge --exclude screen or mask the current version. In fact it's probably safe to just keep that hardlink around, you'll know what the problem is when it breaks your emerge and can --keep-going.

[Edit: Make sure that you link the actual binary and not a symbolic link.]
Last edited by eccerr0r on Mon Sep 17, 2018 12:24 am, edited 1 time in total.
Intel Core i7 2700K/Radeon Firepro W2100/24GB DDR3/800GB SSD
What am I supposed watching?
Top
Post Reply

12 posts • Page 1 of 1

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic