View previous topic :: View next topic |
Author |
Message |
Leffe Tux's lil' helper
Joined: 07 Apr 2004 Posts: 145 Location: Sweden
|
Posted: Wed Nov 24, 2004 8:13 pm Post subject: Various GNU Screen tweaks and hacks. |
|
|
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: | 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: | 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: | 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 |
|
Back to top |
|
|
Leffe Tux's lil' helper
Joined: 07 Apr 2004 Posts: 145 Location: Sweden
|
Posted: Mon Dec 13, 2004 11:44 am Post subject: |
|
|
age for quite a lot of new content. |
|
Back to top |
|
|
Wormo Retired Dev
Joined: 29 Nov 2004 Posts: 526 Location: SB County California
|
Posted: Tue Dec 14, 2004 11:19 pm Post subject: Re: Various GNU Screen tweaks and hacks. |
|
|
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!
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
Then after the paste is done, you can get back any fancy indenting settings with |
|
Back to top |
|
|
Leffe Tux's lil' helper
Joined: 07 Apr 2004 Posts: 145 Location: Sweden
|
Posted: Wed Dec 15, 2004 12:14 pm Post subject: |
|
|
Thanks a lot! Added it to the article. |
|
Back to top |
|
|
adsmith Veteran
Joined: 26 Sep 2004 Posts: 1386 Location: NC, USA
|
Posted: Wed Dec 15, 2004 1:42 pm Post subject: |
|
|
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: | 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 |
|
Back to top |
|
|
adsmith Veteran
Joined: 26 Sep 2004 Posts: 1386 Location: NC, USA
|
Posted: Wed Dec 15, 2004 1:44 pm Post subject: |
|
|
By the way, here that file is in Code: | /usr/lib/portage/pym/output.py |
Note the /pym/ |
|
Back to top |
|
|
Leffe Tux's lil' helper
Joined: 07 Apr 2004 Posts: 145 Location: Sweden
|
Posted: Wed Dec 15, 2004 3:01 pm Post subject: |
|
|
adsmith wrote: | By the way, here that file is in Code: | /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. |
|
Back to top |
|
|
Wormo Retired Dev
Joined: 29 Nov 2004 Posts: 526 Location: SB County California
|
Posted: Thu Dec 16, 2004 7:20 am Post subject: |
|
|
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:
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 command in vim (which I find extremely useful). Default keybinding for regions includes to split the window, to delete current region, and to switch focus between regions (assuming you didn't re-bind tab). |
|
Back to top |
|
|
Xk2c Apprentice
Joined: 17 Jul 2004 Posts: 240
|
Posted: Thu Dec 16, 2004 4:44 pm Post subject: |
|
|
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: | 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:
https://forums.gentoo.org/viewtopic.php?p=1886655#1886655 _________________ useful Xterm, Aterm and RXVT-Unicode features |
|
Back to top |
|
|
Wi1d Apprentice
Joined: 15 Mar 2004 Posts: 282 Location: USA, Iowa
|
Posted: Thu Sep 08, 2005 7:31 am Post subject: My simple, yet semi-thorough, tutorial on using gnu-screen |
|
|
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
[img:e9c898c66f]http://xs45.xs.to/pics/05364/example.jpg.xs.jpg[/img:e9c898c66f]
A split screen session
[img:e9c898c66f]http://xs45.xs.to/pics/05364/exampleSplit.jpg.xs.jpg[/img:e9c898c66f]
Putting screen in action
First thing first. Install screen:
Code: | # 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: | 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: | 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: | 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: | 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: | */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: | #!/bin/sh
while :
do
cat /tmp/temperature
sleep 16m
done |
And then add a "backtick" into your screenrc kind of like this:
Code: | backtick 52 0 0 watch-weather |
Now where every you put "%52`" in the "hardstatus line" your current weather will be displayed. example:
Code: | 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. |
|
Back to top |
|
|
lucapost Veteran
Joined: 24 Nov 2005 Posts: 1419 Location: <ud|me|ts> - Italy
|
Posted: Sat Apr 19, 2008 10:12 am Post subject: |
|
|
I have a problem to set background/foreground color via hexadecimal syntax in ~/.screenrc .
Can you help me?
This is my caption:
Code: | caption always '%{wb}%?%-Lw%?[%n*%f%t%?(%u)%?]%?%+Lw%?%? %-= @%H' |
What can I change this in hex ???
Code: | %{wb} >>> %{ ???????? } |
_________________ LP |
|
Back to top |
|
|
eccerr0r Watchman
Joined: 01 Jul 2004 Posts: 9826 Location: almost Mile High in the USA
|
Posted: Sat Sep 15, 2018 2:00 pm Post subject: |
|
|
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.] _________________ Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Last edited by eccerr0r on Mon Sep 17, 2018 12:24 am; edited 1 time in total |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|