Wednesday, September 02, 2009

KDE Submenu Action For Getting the Public URL of a File in the Dropbox Public Folder

There is yet no equivalent for the nautilus extension for GNOME for KDE, so one can't right click on files in Dropbox's Public folder to get the Public URL. To overcome this limitation, one can use a KDE submenu action. First, create a .desktop file, named dropboxpublic.desktop with the following contents and save it under /usr/share/kde4/services/ServiceMenus or ~/.kde/share/kde4/services/ServiceMenus . The exact location for the parent directory of ServiceMenus is obtained by "kde4-config --path services" output.
[Desktop Action Dropbox Public URL]                                                                                               
Exec=dropbox puburl %u | xclip -selection clipboard                                                                               
Name=Get Public URL

[Desktop Entry]
Actions=Dropbox Public URL;
MimeType=application/octet-stream;
ServiceTypes=KonqPopupMenu/Plugin;
Type=Service
X-KDE-ServiceTypes=KonqPopupMenu/Plugin,
This action requires the xclip program to copy the output of the action to clipboard, so install that using your package manager. Next, when you right click a file in Dropbox/Public folder, and go to Actions-Get Public URL, the URL should be copied to the clipboard. Tip: If you add X-KDE-Priority=TopLevel it will appear in the top level, not under Actions menu.

Saturday, August 22, 2009

Weather Information on Command Line

Weather information can be obtained at command line using a Python script that retrieves the weather information from Yahoo API found here at GitHub.

For Ankara, the location code is TUXX0003 and I aliased it in ~/.bash_profile as:

alias hava='weather.py TUXX0003 -m c -f 2'

Tuesday, August 18, 2009

Compiling Documents via Both LaTeX and XeLaTeX

To compile files that require XeLaTeX-specific options using LaTeX, use the \ifx\XeTeXversion\undefinedcheck.

\documentclass[a4paper,12pt]{report}

\ifx\XeTeXversion\undefined
\usepackage[utf8]{inputenc}
\else
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\setmainfont[Mapping=tex-text]{Gentium}
\fi

\begin{document}


\ifx\XeTeXversion\undefined
Hello World from LaTeX!
\else
Hello World from XeLaTeX!
\fi


\end{document}

Sunday, August 16, 2009

Thursday, July 23, 2009

Setting a Lefty and a Righty Mouse in Linux at the Same Time

If you want to use two mouses in Linux, and want one of them lefty and the other righty: use this:

xinput set-button-map 2 3 2 1
will reverse the buttons of the mouse numbered 2. To get a list of the mouses,
xinput list
or
xsetpointer -l

Combining both, to set the Microsoft mouse as lefty for example, use:

xinput set-button-map `xsetpointer -l|grep Microsoft|cut -c 1` 3 2 1

This is not persistent across sessions.

Tuesday, July 21, 2009

Scroll Lock Mode in Emacs

This is nice for reading a source file, such that the cursor stays always at the right spot.

(global-set-key (quote [Scroll_Lock]) 'scroll-lock-mode)
to map it to the Scroll Lock key.

Also see: Centered Cursor Mode

Saturday, July 18, 2009

Listing Package Contents in Debian

The command

 dpkg -L   
lists the files installed with a package. Ex: dpkg -L iceweasel

Thursday, July 16, 2009

Visualizing the Source Tree of a Project with the Command `tree'

The Unix command `tree' is nice for visualizing a project that spans multiple directories.

I use the following to get the tree structure for a MATLAB project:

tree -P "*.m" > lstree.tex

This creates a file lstree.tex with the tree structure. Then, to give it a XeLaTeX structure, prepend with the following:

 \documentclass[twocolumn]{article}
\usepackage{verbatim}
\usepackage{fullpage}
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\setmainfont[Mapping=tex-text]{Gentium}
\setmonofont[Mapping=tex-text]{Gentium}
\begin{document}
\begin{verbatim}

and append the following:

\end{verbatim}
\end{document}
 

Compile with the command xelatex.
You will need xelatex, tree and gentium packages installed for these to work.

Opening Files from the Command Line via the Default Application

Files can be opened from the command line as if they were double clicked.

  1. On Windows, simply typing the name of the file should work IIRC.
  2. On OS X, there is the open command.
  3. On KDE and Gnome, there are kde-open and gnome-open respectively.

I have created a function in my .bashrc, so that I can open files by the command o. Just add it to ~/.bashrc and source .bashrc or reboot(!)

function o
{
  kde-open "$@" &>/dev/null &             
}

This sends all stdout and stderr to outer space in order to save you an Enter press, so beware.

Bonus: Actually, all this was done so that I can open the files in dired mode in emacs by their default application, pdf, jpg, mp3 files etc.

(define-key dired-mode-map "o" 'dired-launch-command)
(defun dired-launch-command ()
  (interactive)
  (dired-do-shell-command
   (case system-type
     (gnu/linux "kde-open") ;right for gnome (ubuntu), not for other systems
     (darwin "open"))
   nil
   (dired-get-marked-files t current-prefix-arg)))

Now in dired mode, pressing 'o' will open the file in the default application.

See here if that doesn't work.