Linux Bootstrap

December 14, 2012

It’s the holiday season, and I feel like treating myself with a fresh Arch Linux install on my Thinkpad T530. If you’re wondering what to do next with your new Linux box, allow me to show you the next steps.

Step 1: Clean up

The first thing you might notice is that your distribution provided you with a generous amount of folders in your home directory. You don’t need them.

cd ~
rm -rf Pictures Photos Videos Public

Get DropBox or an external hard drive for that kind of thing. I like to keep my home directory as clean as possible.

Start a habit of keeping your work in one master folder.

mkdir ~/Projects

Step 2: Enhance that Terminal

We’ve been using the terminal the whole time. It will become your permanent home. It empowers you with speed and efficiency.

I notice that every time I change directory, I immediately want to know the files there. The cd and ls commands are tightly coupled:

cd ~/some/directory
ls

So I took the liberty to edit my ~/.bashrc file. This file is run every time you start a terminal. Use it to set up aliases and scripts on start. Put the following lines in your ~/.bashrc file so that whenever you cd, the terminal will always automatically ls afterwards. It’s small things like this that enhance your experience.

cdls() { 
if [ -z "$1" ]; then 
  cd && ls 
else 
  cd "$*" && ls 
fi 
} 
alias cd=cdls

Step 3: Get the Right Tools

Editing that file was painful. Let’s get emacs! Ok, you can download your favorite editor but I’m sticking with mine. If you do choose to get emacs (at least try it out!), then make sure to customize it by creating a ~/.emacs file.

Usually when you close emacs without saving, it asks “are you sure?” and it expects you to type out “yes” or “no.” That’s too much typing for me. In the ~/.emacs config file, add these lines.

 ;; Accept y or n when presented with yes or no. 
(fset 'yes-or-no-p 'y-or-n-p) 

I always use emacs in no-window mode, so I created an alias for it. Place this alias in your ~/.bashrc .

alias en='emacs -nw'

What Linux setup in complete without IRC? One of the best available is irssi. It’s completely terminal based with many powerful features. Use your package manager or head over to their site and get irssi.

Navigating deep through long directories can become a one-way journey. Getting lost is easy. I highly recommend installing cdargs. It’s a bookmark for your directories. Never again will you need to type

 cd ~/Projects/Android/MyApp/src/com/pack/

Instead you can use cdargs and just call it by it’s bookmark

 cv pack

Done. That was beautiful.

Get cdargs. To install it properly, add this to your ~/.bashrc

 source /usr/share/cdargs/cdargs-bash.sh

Below is a quick primer on how to use cdargs, taken from this website.

cv in your shell invokes the cdargs GUI
cv [TAB] gives you TAB-completion for your bookmarks
ca [label] add the current directory to your list of bookmarks optionally using LABEL as the description string.
cpb FILELIST [bookmark] copies a list of files to a directory you choose. Make sure that the optional BOOKMARK is not a directory where you are.
arrow keys in cdargs navigate the list or the directories.
ENTER selects an entry
q,ESC,C-c,C-],C-g quit
H,?,C-h call for help

Step 4: Customize

Now for something really cool.
Go back to your ~/.bashrc and find the line that says PS1= .
Replace it with the text below. If you can’t find it, that’s fine, just add this line.

PS1="\e[0;37m┌──\e[0m[\e[0;33m\u\e[0m@\e[0;34m\h\e[0m]─[\e[2;37m\w\e[0m]\n\e[0;\37m└─\e[0m\$ "

Open a new terminal and see the results!

Here’s a 16-page thread with people sharing their PS1 setups.

I’m on a ThinkPad and I love using the TrackPoint nub. However, my Arch Linux setup did not properly recognize middle-mouse scrolling via the nub. So after searching online, I found this wiki for my Thinkpad. The TrackPoint instructions there fixed my problem completely.

I don’t like grep. I prefer ack-grep, it’s much more code-friendly. It’s perfect for searching though files with many lines of code. Download and install ack. If you’re ever looking for some part of your code among many files, remember to use ack!

Step 5: Create Scripts

Sometimes the best tools are your own. Make a folder ~/bin to store all your scripts. Add that folder to your path by including the following line the your ~/.bashrc

PATH=$PATH:$HOME/bin

Now throw useful scripts in your ~/bin folder as you come across them. For example, here are some of my scripts.

Step 6: Bootstrap

Finally, let’s get git. Install it then configure.

git config --global user.name "Your Name Here"
git config --global user.email "your_email@youremail.com"

Actually, lets use git to keep track of the files we’ve been modifying. First create a .gitignore file.

# Ignore everything 
/*
# But not these files
!/bin/
!.emacs
!/.irssi/
!.bashrc

Initialize a git repo in your home directory.

git init

Now commit your changes.

git add . 
git commit -m "Initial commit"

You should upload this git repo to your GitHub. Next time you hop onto a new Linux machine, just git pull all your preferences from GitHub and bootstrap this process.

Want to see how others have setup their Linux box?

Here’s a goldmine full of home-directories.

Go through them and get inspired!

Comments are closed.