Difference between revisions of "Linux multi window terminal Screen and Tmux"

From Ever changing code
Jump to navigation Jump to search
Line 114: Line 114:
  ~$ screen -c screen-4regions
  ~$ screen -c screen-4regions


Config file example
Example of a config file:
  ~$ cat screen-pm  
  ~$ cat screen-pm  
<span style="color: green"># Region 0</span>
  screen -t mail1-queue    #creates new terminal/prompt
  screen -t mail1-queue    #creates new terminal/prompt
  select 0                   #select window0
  select 0                 #select window0
  stuff "echo Window0^M"   #echo a string between quotes, ^M translates to EOL
  stuff "echo Window0^M"   #echo a string between quotes, ^M translates to EOL
stuff "sshpass -p 'password' ssh -o PubkeyAuthentication=no root@example.com^M"  #ssh interactively
    
    
  split      #split horizontally
  split      #split horizontally
  split -v  #split vertically
  split -v  #split vertically
   
   
<span style="color: green"># Region 1</span>
  select 1
  select 1
  focus     #get focus on a selected window
  focus                   #get focus on a selected region
  screen -t mail2-queue  #create a new terminal/prompt in the focus window
  screen -t mail2-queue  #create a new terminal/prompt in the focus window
  stuff "echo Screen1^M"
  stuff "echo Window1^M"
   
   
<span style="color: green"># Region 2</span>
  select 2
  select 2
  focus
  focus
  screen -t mail1
  screen -t mail1
  stuff "echo Screen2^M"
  stuff "echo Window2^M"
   
   
  split -v
  split -v
   
   
<span style="color: green"># Region 3</span>
  select 3
  select 3
  focus
  focus
  screen -t mail2
  screen -t mail2
  stuff "echo Screen3^M"
  stuff "echo Window3^M"
   
   
  altscreen on                                                                                       
  altscreen on                                                                                       

Revision as of 12:25, 28 August 2016

Screen allows for multi window connection using a single ssh session. It also allows to detach from the session screen while still running a remote session.

Install

sudo apt-get install screen

Useful key bindings

C^a c -create new prompt
C^a tab -move to a next window
C^a | -split vertically
C^a S -split horizontly
C^a \ -kill all windows and exit
Key Action Notes
Ctrl+a c new window
Ctrl+a n next window I bind F12 to this
Ctrl+a p previous window I bind F11 to this
Ctrl+a " select window from list I have window list in the status line
Ctrl+a Ctrl+a previous window viewed
Ctrl+a S split terminal horizontally into regions Ctrl+a c to create new window there
split terminal vertically into regions Requires screen >= 4.1
Ctrl+a :resize resize region
Ctrl+a :fit fit screen size to new terminal size Ctrl+a F is the same. Do after resizing xterm
Ctrl+a :remove remove region Ctrl+a X is the same
Ctrl+a tab Move to next region
Ctrl+a d detach screen from terminal Start screen with -r option to reattach
Ctrl+a A set window title
Ctrl+a x lock session Enter user password to unlock
Ctrl+a [ enter scrollback/copy mode Enter to start and end copy region. Ctrl+a ] to leave this mode
Ctrl+a ] paste buffer Supports pasting between windows
Ctrl+a > write paste buffer to file useful for copying between screens
Ctrl+a < read paste buffer from file useful for pasting between screens
Ctrl+a ? show key bindings/command names Note unbound commands only in man page
Ctrl+a : goto screen command prompt up shows last command entered

Custom configuration

By default the config is kept in ~/.screenrc file but using -c option we can pass a custom config

~$ screen -c screen-4regions

Example of a config file:

~$ cat screen-pm 
# Region 0
screen -t mail1-queue     #creates new terminal/prompt
select 0                  #select window0
stuff "echo Window0^M"    #echo a string between quotes, ^M translates to EOL
stuff "sshpass -p 'password' ssh -o PubkeyAuthentication=no root@example.com^M"  #ssh interactively
 
split      #split horizontally
split -v   #split vertically

# Region 1 
select 1
focus                   #get focus on a selected region
screen -t mail2-queue   #create a new terminal/prompt in the focus window
stuff "echo Window1^M"

# Region 2
select 2
focus
screen -t mail1
stuff "echo Window2^M"

split -v

# Region 3
select 3
focus
screen -t mail2
stuff "echo Window3^M"

altscreen on                                                                                       
term screen-256color                                                                               
bind ',' prev                                                                                      
bind '.' next                                                                                      
#                                                                                                  
#change the hardstatus settings to give an window list at the bottom of the                        
#screen, with the time and date and with the current window highlighted                            
hardstatus alwayslastline                                                                          
#hardstatus string '%{= kG}%-Lw%{= kW}%50> %n%f* %t%{= kG}%+Lw%< %{= kG}%-=%c:%s%{-}'              
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'