Monday, May 14, 2012

Better Console Font (in Arch)

In order to use Terminus as my console (tty) font, I simply installed the package terminus-font with pacman (includes both console and X11 versions). Then I edited the CONSOLEFONT variable in rc.conf to have the value ter-216b.

I haven't been able to enable 256 colors in console and use my monitor's native 1920x1080 resolution (the best mode hwinfo reports is 1280x720 and for some reason it doesn't seem to work either).

Saturday, May 5, 2012

Switching from GNU Screen to tmux

GNU Screen is a fantastic program. It is, however, more or less abandoned. tmux promises to be a more full-featured alternative, with cleaner source code and easier configuration. This is the .tmux.conf file I'm currently using.

# change tmux key-bindings to screen key-bindings (with ^O as prefix)

# Set the prefix to ^O
unbind C-b
set -g prefix ^O
bind a send-prefix

# Bind appropriate commands similar to screen.
# lockscreen ^X x 
unbind ^X
bind ^X lock-server
unbind x
bind x lock-server

# screen ^C c 
unbind ^C
bind ^C new-window
unbind c
bind c new-window

# detach ^D d
unbind ^D
bind ^D detach

# displays * 
unbind *
bind * list-clients

# next ^@ ^N sp n 
unbind ^@
bind ^@ next-window
unbind ^N
bind ^N next-window
unbind " "
bind " " next-window
unbind n
bind n next-window

# title A
unbind A
bind A command-prompt "rename-window %%"

# other ^O
unbind ^A
bind ^O last-window

# prev ^H ^P p ^? 
unbind ^H
bind ^H previous-window
unbind ^P
bind ^P previous-window
unbind p
bind p previous-window
unbind BSpace
bind BSpace previous-window

# windows ^W w 
unbind ^W
bind ^W list-windows
unbind w
bind w list-windows

# quit \ 
#unbind \
#bind \ confirm-before "kill-server"

# kill K k 
unbind K
bind K confirm-before "kill-window"
unbind k
bind k confirm-before "kill-window"

# redisplay ^L l 
unbind ^L
bind ^L refresh-client
unbind l
bind l refresh-client

# split -v |
unbind |
bind | split-window

# :kB: focus up
unbind Tab
bind Tab select-pane -t:.+
unbind BTab
bind BTab select-pane -t:.-

# " windowlist -b
unbind '"'
bind '"' choose-window

# Q break-pane (close all other panes)
unbind !
bind Q break-pane

#####################################################################

# enable 256 color support
set -g default-terminal "screen-256color"

# make prefix+S toggle status line visibility
bind S set -g status

# more or less screen style split
# prefix+H: split horizontally by grabbing the previous window into the new pane
# prefix+V: split vertically by grabbing the previous window into the new pane
bind H join-pane -ht :-1
bind V join-pane -vt :-1

The bulk of the code is for making tmux key-bindings like those of GNU Screen (up until the seprator line). Most of that code is copied from the sample config file that came with the Arch package (in /usr/share/tmux/screen-keys.conf). The rest adds these functionalities:
  • Enable 256 color support.
  • Add a key-binding for toggling status line visibility.
  • Add a pair of key-bindings for screen style splitting. In screen, when you split a window, two windows are created and each can be rotated so that it contains one of the previously created windows. In tmux, splitting results in creating two "panes". A window can contain several panes. This is usually desirable (with this config, accessible through the use of prefix+| and prefix+% shortcuts). However, sometimes you might want to split the window so that the new pane contains one of the previously created windows. The last two lines add the prefix+H and prefix+V key-bindings that make this possible (one for splitting vertically, the other horizontally). The new pane will contain the window before the current one.
I also added this to my .stumpwmrc to make switchig to the emacs inside tmux easier (again, this is not exactly correct, but it works most of the time for me).

(defcommand emacs-in-tmux () ()                                                                                                                                                                
  "attempts to switch to an emacs instance run in a tmux window                                                                                                                          
called 'emacs', itself inside a urxvt instance."                                                                                                                                               
  (let ((ret                                                                                                                                                                                   
         (run-shell-command "tmux select-window -t emacs ; echo $?" t)))                                                                                                                       
    (if (eql (elt ret 0) #\0)                                                                                                                                                                  
        (run-or-raise "urxvt" '(:class "URxvt"))                                                                                                                                               
        (message "no screen session found."))))                                                                                                                                                
(define-key *root-map* (kbd "C-e") "emacs-in-tmux")

My latest urxvt configuration

The latest changes include turning off the scrollbar (who needs a scrollbar anyway), turning off the tabs (screen and tmux do the job better) and also stopping urxvt from jumping forward when a program is producing output and I'm looking previously generated output (the last three lines).
! to match gnome-terminal "Linux console" scheme                                                                                                                                               
! foreground/background                                                                                                                                                                        
URxvt*background: #000000                                                                                                                                                                      
URxvt*foreground: #00ff00                                                                                                                                                                      
! black                                                                                                                                                                                        
URxvt.color0  : #000000                                                                                                                                                                        
URxvt.color8  : #555555                                                                                                                                                                        
! red                                                                                                                                                                                          
URxvt.color1  : #AA0000                                                                                                                                                                        
URxvt.color9  : #FF5555                                                                                                                                                                        
! green                                                                                                                                                                                        
URxvt.color2  : #00AA00                                                                                                                                                                        
URxvt.color10 : #55FF55                                                                                                                                                                        
! yellow                                                                                                                                                                                       
URxvt.color3  : #AA5500                                                                                                                                                                        
URxvt.color11 : #FFFF55                                                                                                                                                                        
! blue                                                                                                                                                                                         
URxvt.color4  : #0000AA                                                                                                                                                                        
URxvt.color12 : #5555FF                                                                                                                                                                        
! magenta                                                                                                                                                                                      
URxvt.color5  : #AA00AA                                                                                                                                                                        
URxvt.color13 : #FF55FF                                                                                                                                                                        
! cyan                                                                                                                                                                                         
URxvt.color6  : #00AAAA                                                                                                                                                                        
URxvt.color14 : #55FFFF                                                                                                                                                                        
! white                                                                                                                                                                                        
URxvt.color7  : #AAAAAA                                                                                                                                                                        
URxvt.color15 : #FFFFFF                                                                                                                                                                        
                                                                                                                                                                                               
URxvt*font: xft:Monospace:pixelsize=18                                                                                                                                                         
                                                                                                                                                                                               
URxvt*letterSpace: -1                                                                                                                                                                          
                                                                                                                                                                                               
URxvt.perl-ext-common : default,matcher                                                                                                                                                        
URxvt.urlLauncher     : firefox                                                                                                                                                                
URxvt.matcher.button  : 1                                                                                                                                                                      
                                                                                                                                                                                               
! scrollbar style - rxvt (default), plain (most compact), next, or xterm                                                                                                                       
URxvt.scrollstyle: plain                                                                                                                                                                       
URxvt.scrollBar: false     ! turn off the scroll bar                                                                                                                                           
                                                                                                                                                                                               
URxvt*secondaryWheel  : true                                                                                                                                                                   
URxvt*secondaryScreen : true                                                                                                                                                                   
                                                                                                                                                                                               
URxvt*scrollTtyOutput   : false                                                                                                                                                                
URxvt*scrollWithBuffer  : true                                                                                                                                                                 
URxvt*scrollTtyKeypress : true

My GNU Screen Configuration

First an update on my latest setup. I switched to Arch Linux a while back and I'm rather happy with it so I'm not thinking of going back to Ubuntu at the moment despite the fact that I'm hearing it's in a good condition.

Second I've started using screen a lot more than before. Specifically, I began running my emacs session inside screen a while back, so that I can connect to my home computer from other places and attach to my screen session and use the running emacs instance. More recently, I've switched to using tmux instead of screen but for the sake of keeping history, I'm posting the code and configuration I used to use here. tmux will be the subject of another post.

This is the .screenrc I used:

escape ^Oo                                                                                                                                                                                     
vbell off                                                                                                                                                                                      
                                                                                                                                                                                               
# Scrollback buffer size in lines                                                                                                                                                              
defscrollback 5000                                                                                                                                                                             
                                                                                                                                                                                               
startup_message off                                                                                                                                                                            
                                                                                                                                                                                               
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}]'                                                       
                                                                                                                                                                                               
# enable support for 256 colors                                                                                                                                                                
term screen-256color                                                                                                                                                                           
terminfo rxvt-unicode 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'                                                                                                                                   
                                                                                                                                                                                               
# fix for residual editor text. sometimes when you run an editor and                                                                                                                           
# close it, some of its text may stay visible. this fixes that                                                                                                                                 
# problem.                                                                                                                                                                                     
altscreen on                                                                                                                                                                                   
                                                                                                                                                                                               
screen -t  emacs       0        emacs -nw                                                                                                                                                      
screen -t  shell0
It changes the screen prefix to ^O so that it doesn't clash with the emacs shortcut. It turns off the visual bell, enlarges to scrollback buffer, turns off the welcome screen, adds a status line, enables 256 color support inside screen, enables alternate screen (so that residual text from some editors will not stay visible after closing them), and finally starts a shell and an emacs instance.

I also added this code to my .stumpwmrc so that I can switch to emacs in the usual way (by pressing C-t C-e):
(defcommand emacs-in-screen () ()                                                                                                                                                              
  "attempts to switch to an emacs instance run in a gnu screen window                                                                                                                          
called 'emacs', itself inside a urxvt instance."                                                                                                                                               
  (let ((ret                                                                                                                                                                                   
         (run-shell-command "screen -X select emacs > /dev/null ; echo $?" t)))                                                                                                                
    (if (eql (elt ret 0) #\0)                                                                                                                                                                  
        (run-or-raise "urxvt" '(:class "URxvt"))                                                                                                                                               
        (message "no screen session found."))))                                                                                                                                                
(define-key *root-map* (kbd "C-e") "emacs-in-screen")
For some reason this sometimes fails to switch to emacs properly, but it usually does!

And one last thing. The GNU Screen version shipped with Arch lacks vertical split support. This AUR package contains the patch for vertical splitting. Unfortunately, it lacks another patch that stops screen from complaining about long $TERM values, so I made a new AUR package that applies this other patch, too. I found that the process of creating Arch packages is surprisingly easy. In this case, I just downloaded the other package, updated its PKGFILE, and made the source tarball using makepkg --source.

Friday, May 4, 2012

Stop urxvt scrolling

Say some program is continueously spitting output and your want to scroll back in the history and check something. By default, you can't. urxvt will jump down when something is added to the output. You can do one of these things:
  • Press Ctrl-s. This will pause the program. When you're done, press Ctrl-q to continue.
  • Add these lines to your .Xdefaults (or wherever you put your X resources):

    URxvt*scrollTtyOutput:      false                                                                                                                                                             
    URxvt*scrollWithBuffer:     true                                                                                                                                                              
    URxvt*scrollTtyKeypress:    true
    

Sunday, March 25, 2012

LightDM: Switch user from the command line

Say you're on Ubuntu 11.10 or later, or any other distribution that uses LightDM. What would you do to go back to the greeter window where you can choose another user without logging out? In most other shells, there is a graphical option for it. In StumpWM you can use the dm-tool utility:
dm-tool switch-to-greeter

Friday, March 23, 2012

PPTP from Command Line

Although this blog is supposed to be about StumpWM, there are things unrelated to the window manager that one needs to do in order to make the transition easier. Since the network manager applet is not available in StumpWM (unless you use a systray program like trayer), you need to know how to do certain tasks without it.

I'm comfortable configuring my network from command line. There was one thing though that I had always done using Network Manager applet; setting up pptp. I googled for it and quickly found this which explains how I can use pptp from the command line.

First you create a file in /etc/ppp/peers. Name the file whatever you want, like myvpn. Put this inside that file:

remotename myvpn
linkname myvpn
ipparam myvpn
pty "pptp <host> --nolaunchpppd "
name <username>
usepeerdns
require-mppe
refuse-eap
noauth

# adopt defaults from the pptp-linux package
file /etc/ppp/options.pptp
Fix the host name and the user name accordingly. Then add a line like this to /etc/ppp/chap-secrets:

<username> myvpn <password> *

Again obviously you need to put your own username and password plus the correct connection name.

I have also created two scripts in /etc/ppp/ip-up.d/ and /etc/ppp/ip-down.d/ to set up the default gateway properly. These scripts are tailored for my own system and you might need to adapt them. the one in ip-up.d/ removes the current default gateway and adds a new one. The other one reverses this.

/etc/ppp/ip-up.d/myvpn:
#!/bin/bash

if [[ $PPP_LOCAL = 192.168.2.* ]]; then
    route del default gw 192.168.1.1
    route add default gw 192.168.2.100
fi
/etc/ppp/ip-down.d/myvpn:
#!/bin/bash

if [[ $PPP_LOCAL = 192.168.2.* ]]; then
    route add default gw 192.168.1.1
    route del default gw 192.168.2.100
fi
Don't forget to make the scripts executable. Also notice that ip-up.d/ and ip-down.d/ are only available in Debian and its derivatives (to learn more about the arguments passed to them and the available environment variables, see the Debian /etc/ppp/ip-up and /etc/ppp/ip-down scripts). Other distros use slightly different paths.

Better Console Font (in Arch)

In order to use Terminus as my console (tty) font, I simply installed the package terminus-font with pacman (includes both console and X11 ...