Friday, April 20, 2007

Feisty Fawn customization

Here are the things I did after I installed Feisty Fawn Ubuntu 7.04 off of the alternate install CD on my Compaq X1000 laptop/other systems.

If on an AMD64 processor system
  • Follow these instructions (and run the script) to get mplayer, flash and java support for firefox. Update all launchers and shortcuts to launch firefox32 instead of firefox
  • Skip the remaining instructions that are italicized

Install add-on packages (by the way, all except the first can be done in one command... just append all the packages you want to install after "install")

  • Edit /etc/apt/sources.list following these instructions to add extra repositories
  • Install full Vim support (without this, no help, syntax highlighting, etc.) sudo aptitude install vim-full
  • Install Flash sudo aptitude install flashplugin-nonfree
  • Install media codecs sudo aptitude install gstreamer0.10-ffmpeg gstreamer0.10-gl gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-bad gstreamer0.10-plugins-bad-multiverse gstreamer0.10-plugins-ugly gstreamer0.10-plugins-ugly-multiverse w32codecs
  • Install Amarok sudo aptitude install amarok
  • Install Java sudo aptitude install sun-java6-jre sun-java6-plugin sun-java6-fonts
  • Install Azureus sudo aptitude install azureus (or, alternatively, ktorrent)
  • Enable DVD support
  • Possible user programs: xmms, xchat, mplayer plugin, vlc, skype, picasa, eclipse, google earth, beagle, clipboard manager
  • Security programs: sudo aptitude install nmap kismet wireshark airsnort aircrack-ng john
  • Install Beryl (nVidia) (I also find it convinient to add a sessions entry for beryl-manager so the stone shows up in the tray)
Trick out Firefox
Trick out the Terminal (and partners in crime)
  • Either create a new profile or edit the current profile
  • Disable General->Show menubar by default in new terminals
  • Set Colors to aesthetically pleasing values
  • Set Effects->Transparent background and set the bar about 2/3 of the way to Maximum
  • Set Scrolling->Scrollback to 2000 lines
  • Edit ~/.bashrc
  • Edit ~/.vimrc
  • Put the line set editing-mode vi in ~/.inputrc (the configuration file for readline... this also makes the set -o vi in the .bashrc redundant)
Trick out GNOME
  • Fix the Right Alt key System->Preferences->Keyboard->Layout Options->Third level choosers->Press Menu Key to Choose 3rd Level
  • Change the Desktop Background by right clicking on it (good backgrounds here (OSX Tiger) and here (fractals) and at DeviantArt)
  • Map the Windows keys to do something cool in System->Preferences->Keyboard Shortcuts (I think "Run a terminal" and "Hide all windows and focus desktop" are good candidates)
  • Enable visual system beep System->Preferences->Sound->System Beep->Flash Window Titlebar
  • Make the panels transparent Right Click on Panel->Properties->Background->Solid Color and adjust the slider appropriately (about halfway looks good)
  • Add the system monitor to the panel Right Click on Panel->Add to Panel->System & Hardware->System Monitor->Add to Panel (I enable all but "Load"... wtf is load?)
  • Disable launching of unnecessary programs at startup (such as Evolution Alarm Notifier) Preferences->Sessions->Startup Programs
  • Save your session in a desireable state: gnome-session-save (don't use the automatic option in Prefs->Sessions... it causes problems!)
  • Put the panels in a desirable place by dragging them across the screen
  • Get 4 workspaces Right Click on Workspaces on Panel->Preferences->Number of Workspaces
  • Disable Rhythmbox launching upon iPod detection (Amarok rulez!) System->Preferences->Removable Drives and Media->Multimedia->Uncheck "Play Music Files when Connected" and also Uncheck Storage->"Browse removable media when inserted"
  • Enable the text-based location bar in Nautilus (in favor of the button-based one) by hitting the notepad button on the top left in a Nautilus window
If on a laptop...
So what's so different about Feisty (as opposed to Edgy)?
  • All the latest stable versions of software in the repos, obviously
  • GNOME network manager manages wireless devices by default (and keyring support to boot)
  • Fool-proof support for installing restricted drivers, media codecs, etc.
  • Nice command line assistance if you try and run software that's not installed (prints a "use this repository and this command to get the software"-type message)
  • Easy enabling of "Desktop Effects"
  • And more

Thursday, April 19, 2007

iPod + Amarok

Using your iPod with Ubuntu is disgustingly easy. As a Linux user, I was almost disappointed... no config files to edit? No dependencies to chase down? No bugs to fix? Nope, Ubuntu and the Amarok music player make everything simple. Here, I will detail how to use Amarok with your iPod on an Ubuntu system. I'm using Ubuntu Feisty Fawn 7.04 (just installed today!), a fourth-generation iPod and Amarok version 1.4.5.

First install Amarok with sudo aptitude install amarok (and with aptitude, not apt-get). If you want Amarok to be useful with most file formats (such as mp3) it would be a good idea to install proprietary codecs as well: sudo aptitude install gstreamer0.10-ffmpeg gstreamer0.10-gl gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-bad gstreamer0.10-plugins-bad-multiverse gstreamer0.10-plugins-ugly gstreamer0.10-plugins-ugly-multiverse libxine-extracodecs w32codecs

Now that those monster installs are finished, you can go ahead and connect your iPod. If it automatically shows up on your desktop as a little iPod icon, great! If not, check out
this thread for more detailed info. When I popped in my iPod, Amarok did me one better and recognized the device, popping up a little dialog asking me what kind of player it was. When this happens, you should select Apple iPod Media Device in the drop-down box. There are a few more options you can set regarding the device -- check out Settings->Configure Amarok->Media Devices in the Amarok toolbar menu. (If this explanation was too complicated for you, there's a guide with nice pictures here describing a slightly different way of going about things.)

To add files to the iPod, go to the Collection tab on the left and highlight whatever you want to transfer to the iPod in the left frame. Right click on it and select Transfer to Media Device. Then go to the Devices tab (with the little iPod logo) and hit Transfer at the top to transfer your files. When you're done transferring files, hit Disconnect at the top. If you're lucky, Amarok will unmount the device for you. If not, you'll have to right click on the desktop icon of the iPod and unmount it that way. I asked in the Amarok IRC channel if it was possible to sync the iPod and apparently it's not... for now, just delete everything off of the iPod and put the new stuff back on, as time consuming as that may be.

There are some other things you can do in Amarok to tweak the settings for the iPod. In the Devices tab under the (usually hidden) iPod menu you can set the model of your iPod. This is used for advanced support such as photo and video copying.

It's annoying that Rhythmbox, the default GNOME music application, launches whenever you connect your iPod. To disable this, go to Preferences->Removable Drives and Media->Multimedia->Portable Music Players and disable Play music files when connected. Just doing this will make a window open up in Nautilus every time you insert a removable drive, including an iPod. To turn this off, go to the Storage tab and uncheck Browse removable media when inserted.


Friday, April 06, 2007

My .exrc file (vi/m) and then some

What follows is my .exrc file for various versions of vi, and some more related stuff. I have yet to look through the vim documentation exhasutively to see if there are any more useful options -- this is just stuff I have gleaned from random places on the Internet and from friends.

Plain vanilla vi (as on Solaris)
set nu " show line numbers
set ts=4 " tabs take up four columns
set sw=4 " set shiftwidth (>> or <<) to 4 columns set showmatch " show matches of ()'s, {}'s, and []'s
set showmode " show what mode (e.g. INSERT) you're in
set autoindent " indent to the extent of the previous line

syntax enable " enables syntax highlighting
set nu " show line numbers
set ts=4 " tabs take up four columns
set sw=4 " set shiftwidth (>> or <<) to 4 columns
set title
" sets title of terminal in menubar to that of file currently being edited
set expandtab " tabs aren't really tabs, but many spaces
set softtabstop=4 " delete four spaces when you delete a "tab"
set ignorecase " perform case-insensitive searches...
set smartcase " ... unless there are capitalized characters in the search pattern
set mousehide " hide the mouse when editing
set exrc " eliminates the possibility of another .exrc getting confused with mine on multi-user systems
set backspace=indent,eol,start "explicitly makes the backspace work when at the beginning of a line
set bg=light "this almost always looks better -- take this out or set it to dark if things look funny
set nohlsearch "no annoying search highlighting

" for common typos
command! Q quit
command! W write
command! Wq wq

Vim Python
set autoindent " indent to the extent of the previous line

Vim C/C++/Java
set cindent " indenting for C-style languages
set showmatch " show matches of ()'s, {}'s, and []'s

For Text (Vim 7.0 only)
setlocal spell spelllang=en_us " English(US) spellcheck on (Vim 7.x only)
set tw=0 wrap linebreak " don't split words between lines, only wrap at end of word
"lots of abbreviations (varies depending on the subject material)
ab STIA Science, Technology and International Affairs

How to produce nicely formatted C code in Vim (From p.221 of Learning the vi editor):
set nocp incsearch
set cinoptions=:0,p0,t0
set cinwords=if,else,while,do,for,switch,case
set formatoptions=tcqr
set cindent
syntax on
source ~/.exrc

Options set when vim 6.4/7 starts on my system (Ubuntu Linux):
helplang=en " language to display help in
ruler " show row and column in bottom right
ttyfast " indicates a fast terminal connection
viminfo='20,"50 " configuration info
history=50 " number of : commands and previous search patters to be remembered
scroll=32 " number of lines to scroll with CRTL-U and CTRL-D commands
ttymouse=xterm2 " mouse codes
backspace=indent,eol,start "explicitly makes the backspace work when at the beginning of a line
fileencodings=ucs-bom,utf-8,latin1 " list of character encodings considered when starting to edit a file
printoptions=paper:letter " controls format and output of printing
runtimepath=~/.vim,/usr/share/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vimcurrent,/usr/share/vim/vimfiles/after,/usr/share/vim/addons/after,~/.vim/after " list of directories which will be searched for runtime files
suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc " Files with these suffixes get a lower priority when multiple files match a wildcard.

Cool stuff that I have seen various places but I didn't find particularly useful (maybe someone else will):
set list "replaces all EOLs and TABs with $ and ^I
"auto-complete of brackets
inoremap [ [] <left>
inoremap ( () <left>
inoremap { {} <left>
inoremap " "" <left>
inoremap ' '' <left>

To see the options vi(m) has enabled, enter :set
To get help with options in Vim, enter :help set or :set all for regular vi
Or just :help for the help contents... Vim has excellent documentation


My .bashrc file

export TERM="xterm-color" # xterm terminal emulation (with color -- be sure to put at top of file on Ubuntu)
export PYTHONSTARTUP="$HOME/" # python startup file
set -o vi # sets vi command-line editing mode
bind -m vi-command -r 'v' # so that every time you hit v in command mode, an editor doesn't launch
ulimit -c unlimited # dump core files, no matter how big they are
export EDITOR="vi" #use vi as the default editor for some commands, like "fc"

alias screen='TERM=screen screen' # workaround for screen backspace bug

alias d="date '+%r -- %A, %D'" # human-readable date output

alias ll="ls -lh" # long listing (with human-readable file sizes)
alias lr="ls -ltrh" # list by reverse modification time
alias la="ls -Ah" # list hidden files (except implied . and ..)

alias <name>="cd <important>" # get to important directories fast
alias <name>="ssh <login>@<important>" # log into oft-used remote machines fast

# prevent myself from doing stupid things with vi
function vi {
if [ ! -e "$1" ]; then
if [ "$1" == "" ]; then
vim "$1"
elif [ -d "$1" ]; then
cd "$1"
elif [[ -c "$1" || -b "$1" || -p "$1" || -S "$1" || ! -r "$1" ]]; then
file "$1"
vim "$1"

The following I only enable on Solaris systems:
export PAGER="less" #uses less to view manpages instead of more


Wednesday, April 04, 2007

Common Bash Tasks

I don't use Bash for much scripting. Usually, if I have to open up a file to write a script, it will be done in Python. However, the less I have to do that for mundane tasks that can be accomplished on the command line with Bash, the better. This entry may not have much in it now, but every time I do something cool/useful/time-saving in Bash from now on, it'll go on here.

Common Tasks

  • Rename *.foo files to *.bar files: for i in *.foo; do mv $i ${}.bar; done (BashFAQ)
  • Rename foo.* files to bar.* files: for i in foo.*; do mv $i bar.${i#foo.}; done (also check out the perl regex-based rename Linux utility)
  • Do something to multiple arguments: for i in arg1 arg2 arg3; do echo $i; done
  • Print 0 through 9 on separate lines: for i in {0..9}; do echo $i; done
  • Flatten output onto one line: <Multi-line output> | xargs (10 habits)

Finding and Killing a Process in GNOME

There are a few different ways to find and kill a process in Linux. Using the GNOME interface, you can call up the System Monitor (similar to the one on Windows XP) under System->Administration->System Monitor. Under the Processes tab, right clicking on a process will give you a variety of options: stop/end/kill/continue the process, change the priority (nice), display a memory map (pmap) and display open files (lsof -p <procID>).

Embedding the system monitor in a desktop panel is useful for constantly monitoring the system and quickly determining if and where there is a problem. Do this with Right Click on Panel->Add to Panel...->System & Hardware->System Monitor->Add. The display provides graphs of Processor, Memory, Network, Swap Space, Hard disk and Load activity (not quite sure what load is, perhaps some metric computed from all the others? I don't use it, personally).

On the command line, list processes with the ps command or ps -e for all users' processes. Pipe that through grep (i.e., ps -e | grep firefox) to find a process ID of the target process (if you know the exact name of the program, you can also use pidof firefox-bin). To kill a process, use the kill <procID> command (with the -9 flag if you want to kill it unconditionally). Alternatively, if the process uses a gui, you can use xkill to merely click on the gui to kill the corresponding process. There is also killall if you want to kill by process table name (i.e. killall firefox-bin).

pgrep and pkill are two very useful utilities, especially for dealing with processes with long command line invocations. pgrep -fl -u danny "ruby.*asdf" will print the process id and name of every process owned by danny whose command line invocation matches the passed in regular expression. The -f argument tells it to match against the full command line invocation instead of just the process name. pkill -fu dannyc "ruby.*asdf" will kill those same processes (for the life of me, I can't seem to coax similar behavior out of killall).

The top command provides an integrated way of finding and killing a process on the command line. If the process-to-be-killed is using a lot of system resources, it will appear towards the top of the display. Hit k and then the process ID to kill the process. Top comes with a lot of other functionality -- hit h for help.

UPDATE: I recommend using htop instead of top, which is top with less suck. It has lots of good features like color, mouse support, a more responsive interface, a tree-based process view, etc.