Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GNUScreen
- ---------
- Screen is to the console what your window manager is to X. It will allow you to have several
- buffers or windows running at the same time. You can easily switch from one buffer to another,
- copy and paste between them, create new windows and close others, etc. Each new window will
- launch a new process defined by the configuration, typically an interactive shell. But that is
- not all. Probably the better feature is that it runs as a separated process from the X server,
- though, you can get connected to it from a Terminal window running on top of X. We will return
- to this topic later.
- Now we'll going to do a tour though most useful screen features, from basic ones to some cute
- configurations that can make your life easier understanding screen.
- Launching Screen
- ----------------
- This one is easy, from a console type "screen" (without quotes) and press enter. This is a way
- to launch screen, we will see later we can do some cool stuff using the screen command, but for
- now this is the basic way.
- Basic usage
- -----------
- First some conventions, as many Unix manuals, <c-X> stands for a keyboard shortcut using the
- CONTROL key and the "X" key.
- The way to communicate with screen is typing a prefix -<c-a> by default- and then pressing a
- key. The <c-a> combination will tell screen that the next key is a screen command, in this way, we will send orders to screen pressing <c-a> and a key. The default keys are nice, they typically follow a mnemotechnical rule, or they have a privileged position in the keyboard for easy access.
- <c-a> c -> *C*reates a new *C*onsole window
- <c-a> n -> *N*ext tab or window
- <c-a> <space> -> next tab
- <c-a> <Return> -> next tab
- <c-a> p -> *P*revious tab
- <c-a> S -> *S*plit screen
- <c-a> <Tab> -> focus next frame
- <c-a> Q -> make current frame the only one
- <c-a> K -> *K*ill current application
- <c-a> ? -> Shows all commands (really helpful)
- <c-a> w -> Shows a list of current running tabs
- Those are the basics keys used by navigate through the different "tabs" or "windows". They are
- pretty easy to use. Suppose you are downloading something with wget. It is boring to watch the
- download progress, so you want to do something else. Press <c-a> c to create a new terminal and
- launch whatever you want from there. If you want to check the download, just press <c-a> p to go
- to the previous tab, and <c-a> n to back to your funny stuff. You can use this features in TUI
- mode, or in GUI mode from a terminal window as well.
- There are some ways a bit more smart to move to windows:
- <c-a> # (# being a number), goes to # tab
- <c-a> ' will ask for a number, type the number and press enter
- <c-a> " will show a menu with a list of all windows, you can browse with j/k ,
- <c-n>/<c-p> , and arrows
- Probably, your listing when <c-a> " will be a bit unintuitive, like
- 0 bash
- 1 bash
- 2 bash
- you can change the name of a given window with <c-a> A.
- Detaching and reattaching
- --------------------------
- One of greatest screen's feature is the ability to detach itself from the current terminal
- application that's running in (xterm, putty or whatever). We said already Screen runs as a
- separated process from X, this is why that is so great. If you want to restart the X server, or
- some X application makes it to crash, all the programs and processes running on Screen will keep
- going. If you are working over a ssh connection and you suddenly suffer network problems, the
- processes you started from Screen over ssh will keep going too. If you have no problem at all
- but for some reason you want to detach your terminal and reattach it from another place, Screen
- will let you do it.
- We can see an example, the usual work flow when using ssh should be:
- Connect to the remote machine (using ssh, putty,...). Then start a screen session. Open as many
- consoles as you want. If your connection falls, normally you would loose all unsaved changes and
- current processes would be killed in a rude way. Not to talk if you were compiling/executing
- something that would last several hours...So much work lost!
- That's what you could think at first, but screen has a very powerful feature
- called 'detach'. When something goes wrong with your connection, or you click
- that 'X' at the corner window, screen just detaches itself from the containing
- window, but none of your work is lost. It keeps running at the background. you
- can try playing some music with mplayer, and closing the terminal containing it
- and keep listening music.
- When you're on a system without X, and you have no 'x' to click (or nested
- screens), you can detach screen with the next command:
- <c-a> d -> *d*etach screen
- Now if you want to recover (reattach) your screen session you just open a
- terminal and enter the command:
- screen -r
- I personally use screen -DR that forces a reattach and it even detaches it if
- it was active somewhere else.
- If you have more than one screen detached, you have to provide info about
- which screen session you want to recover.
- kidd@raymobil [ ~ ] %screen -ls
- There are screens on:
- 2945.pts-0.raymobil (Attached)
- 1558.pts-8.raymobil (Detached)
- 2 Sockets in /tmp/uscreens/S-kidd.
- Then you can decide which one you want.
- screen -r 29
- will do the job. (unique substring)
- Monitoring
- ----------
- Screen can monitor your consoles for both activity and silence.
- <c-a> M will note you when there's any activity on the current console. Great
- for IM.
- <c-a> _ will monitor for 30 secs of silence in the current console. Great for
- long compilations.
- Copy mode
- ---------
- With screen you can copy and paste text between buffers in the same session.
- It's done only with the keyboard (pretty useful if you have to paste text from
- a terminal to an IRC channel to get help on how to recover your X).
- <c-a> <esc> -> enters 'copy mode'.
- In copy mode, you can move around your window with hjkl (vi movement keys), arrow keys, or
- page-up and page-down. Once in copy mode, press <space> to start the selection. Use the movement
- keys to select the desired text and press <space> again to exit the selection mode. Now you
- have the text copied and ready to be pasted where you want.
- <c-a> ] pastes the copied text onto current buffer.
- screen provides a way so search text in the scroll buffer, guess what? it's the
- vi style ;)
- c-a <esc> ?text<Return>
- Options, binds and beautifying
- ------------------------------
- screen has lots of features that can be activated interactively or through your
- $HOME/.screenrc
- To set options interactively, the command is
- <c-a> :option
- for example:
- <c-a> :select 0 #goes to first console
- my ~/.screenrc looks more or less like that:
- shell /bin/zsh #I want zsh when openning new tabs
- # caption and hardstatus are 'status bars' for screen. I took them somewhere on
- # the web, look at the screen man page for info on meta-characters
- caption always "%{wb}%n%f %t %{wk} %?%-Lw%?%{wb}[%n*%f %t]%?(%u)%?%{wk}%?%+Lw%? %{wk}"
- hardstatus alwayslastline "%{+b kr}host: %{kw}%H%{kg} %c - %D %d.%m.%Y %{kr}(load: %l) %-26=%1`"
- # you can bind keys to actions, even executing external programs.
- bind o only
- bind s split
- Making screen collaborate with other apps
- -----------------------------------------
- If you use zsh as your default shell, you can make zsh and screen communicate to
- each other and make screen set titles tied to zsh title (bash can't change the window/teminal
- title dynamically AFAIK).
- You should paste the next code in your ~/.zshrc . Keep in mind you may have to tweak the code to match your terminal emulator.
- #screen integration to set caption bar dynamically
- function title {
- if [[ $TERM == "screen" || $TERM == "screen.linux" ]]; then
- # Use these two for GNU Screen:
- print -nR $'\033k'$1$'\033'\\\
- print -nR $'\033]0;'$2$'\a'
- elif [[ $TERM == "xterm" || $TERM == "urxvt" ]]; then
- # Use this one instead for XTerms:
- print -nR $'\033]0;'$*$'\a'
- fi
- }
- function precmd {
- title zsh "urxvt $PWD"
- echo -ne '\033[?17;0;127c'
- }
- function preexec {
- emulate -L zsh
- local -a cmd; cmd=(${(z)1})
- if [[ $cmd[1]:t == "ssh" ]]; then
- title "@"$cmd[2] "urxvt $cmd"
- elif [[ $cmd[1]:t == "sudo" ]]; then
- title "#"$cmd[2]:t "urxvt $cmd[3,-1]"
- elif [[ $cmd[1]:t == "for" ]]; then
- title "()"$cmd[7] "urxvt $cmd"
- elif [[ $cmd[1]:t == "svn" ]]; then
- title "$cmd[1,2]" "urxvt $cmd"
- else
- title $cmd[1]:t "urxvt $cmd[2,-1]"
- fi
- }
- Acknowledgements
- ----------------
- Thanks to #screen channel at freenode, people publishing their zshrc, and zsh maillist. If you find your snippets here and you want credit, don't hesitate to add yourself here, or notify it in #vectorlinux @ freenode.
Add Comment
Please, Sign In to add comment