Friday, December 2, 2011

How to Set Ubuntu Terminal Default Size

Open gconf-editor

Go to desktop => gnome => terminal

Set "exec" to "gnome-terminal --geometry ??x??", where ??x?? is the default size you want.

Update: In Ubuntu 12.04, you can set gnome-terminal's default size in "profile preference => general" without hacking gconf-editor.

Wednesday, August 31, 2011

Fixing the Tab-Complete Issue in Ubuntu 11.04

Simply reinstall package bash-completion

sudo apt-get purge bash-completion
sudo mv /etc/bash_completion.d /etc/bash_completion.d.bak
sudo apt-get install bash-completion

Saturday, March 19, 2011

Customize the Titles of iTerm Windows or Tabs

Add the following line in your .bash_profile:

export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}: ${PWD/#$HOME/~}\007"'

You could also remove the stupid "Default" by modifying net.sourceforge.iTerm.plist. Simply set Root/Bookmarks/Entries/0/Data/Name as empty.

256-color Terminal Vim in Mac OSX

The default terminal in Mac OSX does not support 256 colors, therefore I use iTerm in order to enable some pretty Vim themes.

Setup iTerm
  1. Download iTerm from http://iterm.sourceforge.net/.
  2. iTerm's configuration interface is not very friendly. The traditional "Cmd + ," only gives you limited control. "Cmd + I" shows you some limited settings of the current session and allows you to "push" these settings to the default settings. "Option + Cmd + B" shows you all profiles, and allows you to change them. Although they appear powerful, I am unable to perform some very common tasks such as changing my default display profile to the preset "Dark background" instead of "Light background".
  3. Fortunately, iTerm puts all its configurations in ~/Library/Prefernces/net.sourceforge.iTerm.plist. Therefore, we can use any plist editor to change it in a low-level way. For example, in order to change the default display profile to the preset "Dark background", change Root/Bokmarks/Entries/0/Data/Display Profile to be "Dark Background".
  4. To make iTerm to work with 256 colors, change the terminal type in the default terminal profile to be "xterm-256color". Note: I haven't tried other types, but this one just works.
Setup Vim themes:
  1. Please refer to Color Sampler Pack. Basically, it installs Vim scripts in the .vim directory, each of which represents a Vim theme. You could also change these scripts to make it suitable for your own use.





Friday, January 7, 2011

Internet Sharing via VPN

Setup the VPN server (Ubuntu 10.04):
  1. sudo apt-get install pptpd
  2. In /etc/pptpd.conf, uncomment the two lines starting with "localip" and "remoteip" respectively, e.g.

    localip 192.168.0.1
    remoteip 192.168.0.234-238,192.168.0.245

    When a VPN connection is established, the system will create a virtual network interface. Its IP address will be one of those specified by "remoteip", and its gateway will be "localip".
  3. Add accounts in /etc/ppp/chap-secrets, e.g.

    # client server secret IP addresses
    jingyue pptpd password *

  4. Run "/etc/init.d/pptpd restart" to restart the VPN server and apply the changes.
  5. Now we should be able to connect to the VPN server via a VPN client using the above account. After the connection is established, we should be able to ping the server using "ping 192.168.0.1". However, we need more steps to share the server's internet connection.
  6. Enable IP forwarding: Uncomment the line "net.ipv4.ip_forwarding=1" in /etc/sysctl.conf.
  7. Configure IP tables: e.g.

    iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    iptables -I FORWARD -p tcp --syn -i ppp+ -j TCPMSS --set-mss 1460

    The first line setups the NAT using IP masquerading, so that a client connecting to our server is able to go beyond the intra network. The second line sets the maximum segment size (MSS) of TCP SYN packets that the firewall sees. If the client is behind a firewall that blocks ICMP fragmentation packets, without doing this may cause some weird problems such as being able to view small webpages but not large ones. See this for more details.

  8. Restart the server.
Run the VPN client (Mac OS 10.6):
  1. System Preferences => Network.
  2. Create a new connection. Choose VPN as the interface, and PPTP as the VPN type.
  3. Enter the server's IP address and the account.
  4. Click "Authentication Settings" to enter the password.
  5. Click "Advanced" and select "Send all traffic over VPN connection".
  6. Once connected, we should be able to connect to the internet using the VPN connection.