Saturday, November 13, 2010
6:14 AM

GNU Screen With Byobu

Byobu is manager for GNU Screen hidden within Ubuntu 10.10 Maverick. It's also available through the Debian repos. If you are running Ubuntu 10.10, I'll show you how to unhide it and use it. First right click "Applications" and click "Edit Menus" as shown in the picture.


With "Accessories" selected in the left pane, you will see "Byobu Window Manager" in the left pane. You need to tick (check it) to have it appear in your menu.


Now it should appear in your menu like the picture below.


To make the Terminal better for using it, I suggest creating a new profile based on the default profile and changing it up a bit.


Also I set this new terminal profile to be the one used when launching a new terminal.


Because using Screen with Byobu will display a lot of information that you configure it for at the bottom of the terminal, I suggest changing the default width of the terminal. I changed mine to 132 pixels.


Here you can optionally set a semi-transparent/translucent background.

 

If you followed my previous guide to using Zsh and screen with a .screenrc configuration file, your terminal should appear like this. I did have to make 2 changes to my .screenrc file. I commented out the hardstatus lines because Byobu configures that and that can be further configured through a menu system in ncurses by hitting F9.


I have Byobu configure to show my system uptime, cpu temp, disk and network I/O, IP as well as some other information. To get some default screens you can switch between, you can set this in ~/.screenrc. Here is mine.

#hardstatus alwayslastline
#hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'

# Default screens

chdir ~/
screen -t bash    0 /bin/bash
chdir ~/Coding/CS2213
screen -t zsh    1 # will run zsh by default
chdir ~/Hax0r
screen -t zsh     2
chdir ~/
screen -t zsh     3
chdir ~/
screen -t zsh     4

If you do not have Zsh installed, here is one you can use with bash being your only shell. Only uncomment the hardstatus lines when using GNU Screen without Byobu.

#hardstatus alwayslastline
#hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'

# Default screens

screen -t bash1    0
screen -t bash2    1
screen -t bash3    2
screen -t bash4    3
screen -t bash5    4

To switch between these screen windows in the terminal, there are some commands/key bindings you can use. All of them begin with hitting Control and a followed by another key. I'll give you a few. You can always type Control a then ? for a list of all of them if you forget. Where ever you see "^", that is referring to the Control key. They assume you know to push Control and a (^a) first before using these keybindings. Here are a few commonly used ones.

^a n (Means go to the Next screen window)
^a p (Means go to the Previous screen window)
^a c (Means Create a new screen window)
^a " (Will give you a full list of screen windows to choose from)
^a [ (Will allow you to use the arrow keys to scroll and also if you want, highlight a selection to copy)
^a ] (Will paste whatever you copied to the buffer with the previous command)

Now that you have Screen/Byobu running, open a new terminal window.

Type into the terminal

screen -ls

You should see one screen session running. If that is your only screen session running, then type this next one.

screen -x

That will connect you to that running screen session, so now you see the exact same thing in both terminal windows. Try typing something and see if it appears in both terminals in real time as it's typed. I'll show you how this is useful.

You can leave the screen session running and disconnect from it with "^a d" and then later connect to it again with the screen -x command. This is very useful if you are helping a friend. You can ssh into the friends computer and both be connected to the same screen session, so that you each see the same thing and are both able to type. That requires you to both be logged in as the same user unless you have set the suid bit on the screen excutable and allowed multiuser in the to the screen session, but I will not go into that now for this guide.

You may be bored with that stupid default prompt you get by your distro. Optionally you can change it to what you like. If you are using bash, you can change it by adding the following to the bottom of your ~/.bashrc


export LIGHTCYAN='\e[1;36m'
export LIGHTRED='\e[1;31m'
PS1="\[$LIGHTCYAN\]$(lsb_release -s -c)\[$LIGHTRED\] >> \[$LIGHTCYAN\]"

After doing that, you will need to have the .bashrc re-read. You can do this by opening a new terminal window or typing this command.

source ~/.bashrc 

0 comments:

Post a Comment