Sunday, September 25, 2011

Console based system

… or everything in CLI
For a long time now I have been trying to get the “perfect” working environment on my desktop (in this case, Ubuntu). My requirements for this are simple:
  • Everything (well, almost everything) should be grep-able (documents, presentations, tasks, mails, chats)
  • A tiling window manager – as screens on desktops tend to be large and wide, I find no reason for having windows stacked
  • Multiple desktop support in the window manager (each one customized for a specialized task)
  • The ability to start all my applications after login and to place each of them on predefined desktop
  • Have unitary settings between home desktop, work desktop, laptops, etc
After some tinkering and time spent on getting there, I finally got to check most of the requirements. The tools of trade are the following:
  1. Dropbox for sync-ing configurations, logs, to-do lists and the sorts
  2. The awesome window manager
  3. Emacs as text editor
  4. Org-mode in Emacs for tasks, to-do lists and presentations (yes, I write all my slides in org-mode)
  5. Auctex mode in Emacs LaTeX for documents
  6. Urxvt as terminal
  7. Finch for communication (Pidgin tends to be ugly to manage in a tiling window manager, and really – I just want to write text in my messages – why all the useless UI?)
  8. Elinks for command line browsing (yes, you can open GMail in elinks without any problem)

1. Dropbox

Every script, config file or to-do list goes in here. It runs on linux, windows, mac os, iphone, android – basically anywhere you have internet you’ll get it!
Just go to their web site, download the .deb file say to ~/kits/ and install it:
sudo dpkg --install nautilus-dropbox_0.6.3_amd64.deb
Create a new account (or use your existing one) and point it to a folder of your choice – say ~/Dropbox/, and create a Configs folder in there to hold all your configurations and a Logs file for sync-ing all your communications.
mkdir -p ~/Dropbox/Configs/
mkdir -p ~/Dropbox/Logs/

2. The awesome window manager

Well – it really is awesome! Just install it:
sudo apt-get install awesome
And then set it up by creating the configuration file you want (in lua). You can start from the default configuration:
mkdir -p ~/.config/awesome/
cp /etc/xdg/awesome/rc.lua ~/Dropbox/Configs/
ln -s ~/Dropbox/Configs/rc.lua ~/.configs/awesome/
$EDITOR ~/.config/awesome/rc.lua
Or alternatively you can take a look at the one that I’m using rc.lua (note that I also use this runonce.lua script that should also be in your config).
Final let’s make awesome start when you login:
touch ~/Dropbox/Configs/.xinitrc
ln -s ~/Dropbox/Configs/.xinitrc ~/
$EDITOR ~/.xinitrc
A very simple version of it should look like this (it will just start awesome):
#!/bin/sh
exec awesome
We’ll later add some more stuff here, but it’s fine for the time being!

3. Emacs all over the place

Both in “-snapshot-gtk” and console mode. Give it a spin – it’s one command away:
sudo apt-get install emacs-snapshot-gtk
Once you have it installed, you might want to update the ~/.xinitrc in order to fire up Emacs server so that you can you emacs client.
#!/bin/sh
/usr/bin/emacs-snapshot --daemon &
exec awesome

4. org-mode for getting things done and presentations, Auctex for LaTeX in Emacs

A simple intro to what org-mode can do can be seen on Youtube as a Google TechTalk. It will cover most of the “getting things done” scenarios.
For using it as a presentation creation tool, I have managed to intertwine it with the beamer package which creates .pdf presentations out of LaTeX markup.
If you love LaTeX and Emacs, Auctex is just the normal way to do things. If you’ve read so far you probably see why I like Emacs and LaTeX!
Get everything you need for this step (LaTeX via texlive, latex-beamer, R, auctex and org-mode)
sudo apt-get install texlive latex-beamer r-base ess auctex org-mode

4.1. Setup Auctex

Place the following in your .emacs.el file (code based on www-users.math.umd.edu/~halbert/getcontent.cgi?code+emacs)
;; AUCTeX
(setq TeX-auto-save t)
(setq TeX-parse-self t)
;set up AUCTeX to deal with multiple file documents.
(setq-default TeX-master nil)
;turn on pdf-mode.  AUCTeX will call pdflatex to compile instead of latex.
(add-hook 'LaTeX-mode-hook 'TeX-PDF-mode)
;turn on flyspell mode - this will automatically spell check the document in LaTex-mode
(add-hook 'LaTeX-mode-hook 'flyspell-mode)

4.2. Setting up org-mode

(require 'org-install)

4.3. The skeleton to get the beamer working in org-mode

First we need to inform org-mode about handling beamer class (the code is based on emacs-fu.blogspot.com/2009/10/writing-presentations-with-org-mode-and.html).
; allow for export=>beamer by placing
;; #+LaTeX_CLASS: beamer in org files
(unless (boundp 'org-export-latex-classes)
(setq org-export-latex-classes nil))
(add-to-list 'org-export-latex-classes
;; beamer class, for presentations
'("beamer"
  "\\documentclass[11pt]{beamer}\n
  \\mode<{{{beamermode}}}>\n
  \\usetheme{{{{beamertheme}}}}\n
  \\usecolortheme{{{{beamercolortheme}}}}\n
  \\beamertemplateballitem\n
  \\setbeameroption{show notes}
  \\usepackage[utf8]{inputenc}\n
  \\usepackage[T1]{fontenc}\n
  \\usepackage{hyperref}\n
  \\usepackage{color}
  \\usepackage{listings}
  \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
  frame=single,
  basicstyle=\\small,
  showspaces=false,showstringspaces=false,
  showtabs=false,
  keywordstyle=\\color{blue}\\bfseries,
  commentstyle=\\color{red},
  }\n
  \\usepackage{verbatim}\n
  \\institute{{{{beamerinstitute}}}}\n
  \\subject{{{{beamersubject}}}}\n"
  org-beamer-sectioning
  ("\\section{%s}" . "\\section*{%s}")
  ("\\begin{frame}[fragile]\\frametitle{%s}"
  "\\end{frame}"
  "\\begin{frame}[fragile]\\frametitle{%s}"
  "\\end{frame}")
))
Next it’s cool to have a template for the presentations in the menu:
;; Set up skeletons (see below) in a menu in ORG MODE mode
(defvar org-org-menu)
(add-hook 'org-mode-hook
(lambda () (easy-menu-add-item org-org-menu nil ["Skeletons" nil t])
(easy-menu-add-item org-org-menu '("Skeletons") ["Beamer Theme" orgmode-beamer-my-skeleton t])))
(define-skeleton orgmode-beamer-my-skeleton
  "inserts a simple orgmode-beamer template skeleton - use C-c C-e d to build the pdf"
  nil
  "#+LaTeX_CLASS: beamer\n"
  "#+MACRO: BEAMERMODE presentation\n"
  "#+MACRO: BEAMERCOLORTHEME dove\n"
  "#+MACRO: BEAMERSUBJECT RMRF\n"
  "#+BEAMER_FRAME_LEVEL: 2\n"
  "#+COLUMNS: %35ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)\n"
  "#+OPTIONS: tags:nil\n"
  "#+MACRO: BEAMERINSTITUTE My Affiliation\n"
  "#+AUTHOR: Tudor-Ioan Salomie\n"
  "\n"
  "#+TITLE: Presentation title\n"
  "\n"
  "\n"
  "* My Section\n"
  "\n"
  "** Frame 1 \\\\ with a subtitle\n"
  "\n"
  "*** Idea\n"
  "\n"
  "#+begin_LaTeX\n"
  "\n"
  "#+end_LaTeX\n"
  "\n\n\n"
)
4.4. Using R for graphs
First we need to load the required .el-s for using org-R mode. For this modify your .emacs.el to include:
(load "ess-site.el")
(load "org-R.el")
Now we can have a simple .org file like the following one below (the sample presented is based on orgmode.org/worg/org-tutorials/org-R/org-R.php).
To create the plot from the data in the org-mode table called continuous-data, press C-c C-c on a line that starts with #+R (you can use #+RR to pass in more R commands that do not generate plots – just to setup your environment in R).
To create the final .pdf file, do C-c C-e d.
The same things can be used in the beamer mode skeleton based org-mode files above.
* My plots
#+R: action:hist columns:1 colour:hotpink
#+R: intable:continuous-data outfile:"out.pdf" title:"My Plot"

* Some sample data :noexport:
#+TBLNAME:continuous-data
|            values |
|-------------------|
| -2.48627002467785 |
|  -4.0196287273144 |
| -3.43471960580471 |
| -5.21985294534255 |
| -3.84201126431028 |
| -1.72912705369668 |
| -2.86703950990613 |
| -2.82292622464752 |
| -4.43246430621368 |
| -1.03188727658288 |
| 0.882823532068805 |
|  3.28641606039499 |
|  3.56029698321959 |
|  2.91946660223152 |
|  2.32506089804876 |
|   3.3606298511366 |
|  5.19883523425104 |
|  4.86141359164329 |
|  2.90073505260204 |
|  4.21163939487907 |
Update: As promised here is a screen shot. It shows in awesome wm, my emacs in org-mode with the “source code” of a sample presentation and the output in acrobat reader.
The presentation is all self-contained in one file (except for the beamer theme): structure, images, data for plots and plots.
orgmode presentation
Org-Mode for presentations

5. urxvt terminal

Well – I guess I have a sweet-spot for this terminal. It’s very easy to configure, it runs in a client-server mode and it does its job!
Install it:
sudo apt-get install rxvt-unicode
Configure it via the ~/.Xdefaults file:
touch ~/Dropbox/Configs/.Xdefaults
ln -s ~/Dropbox/Configs/.Xdefaults ~/
$EDITOR ~/.Xdefaults
And now you can have the following settings:
URxvt.buffered:         true
URxvt.background:       black
URxvt.foreground:       white
URxvt.cursorColor:      green
URxvt.underlineColor:   yellow
URxvt.perl-ext-common:  default,tabbed,matcher,clipboard
URxvt.title:            My Console
URxvt*saveLines: 32767
URxvt.urlLauncher:      ~/Dropbox/Configs/open_link.sh
URxvt.matcher.button:   1
Where the the ~/Dropbox/Configs/open_link.sh file uses google-chrome to open a link when you click it in the terminal:
#!/bin/sh
/usr/bin/google-chrome "$@"
You can always choose another browser instead of google-chrome (like elinks).
Finally you might also want to start the urxvt daemon on login, using the ~/.xinitrc file (the window manager goes last always and the rest should be pushed to the background using &):
#!/bin/sh
/usr/bin/emacs-snapshot --daemon &
/usr/bin/urxvtd -q &
exec awesome

6. Finch

Yes, like Pidgin, Finch bears the name of a bird too. The cool thing is that you can get two birds with one stone! Both Pidgin and Finch rely on libpurple which makes them share the same settings, configurations, accounts, etc. They are just two different UIs for the same thing. Switching from one to the other is just starting launching the one that you want!
Install it (the libnotify-bin gives us the notify-send tool to show pop-us)
sudo apt-get install finch pidgin libnotify-bin
Relink the logs (if you have the ~/.purple/logs/ folder, move it first to ~/Dropbox/Logs/)
ln -s ~/Dropbox/Logs/logs ~/.purple/
Add a notification plugin, that will use the awesome notification system to pop-up a red box when you get a message (*)
mkdir -p ~/.purple/plugins/
touch ~/.purple/plugins/knotifications.pl
$EDITOR ~/.purple/plugins/knotifications.pl
And place in it the code from my version of knotifications.pl (customize as you want).
The changes that I did to the script are simple, I have re-routed the notification calls in received_im_msg_handler and received_chat_msg_handler functions from show_popup to show_my_popup. All other notifications were disabled in the code (commented out).
*Note: the plugin is based on code I found here code.google.com/p/pidgin-knotifications/
Update: And here is a screenshot of Finch!
Awesome WM and Finch (all in urxvt)
Awesome WM and Finch (all in urxvt)

7. elinks

Many times I just want to get to a site fast, no switching to a google-chrome or firefox instance. Just hit a link and have it pop up in a terminal window.
sudo apt-get install elinks

Extra reading

[1] Autostart for Awesome: awesome.naquadah.org/wiki/Autostart

No comments: