Tuesday, August 26, 2008

Display your Arch Linux theme information automatically

Often when you come across a desktop screenshot in the forums/websites a myriad of question flows through your mind. "What theme is that? Lovely icon, if only I knew its name. Wow, but is it openbox or fluxbox or something else?" Now while its possible to mention all the details while posting the picture, its a hassle everytime you post a screenie in the monthly screenshot thread.

Instead, wouldn't it be better if we could somehow automatically include all the details in the screenshot itself? Yes, it would be and its possible just by using these two small scripts.




Edit the path to the logos.pl file here in the info.pl file
require '/home/sujoy/bin/logos.pl';


Now all you have to do is put the two files in the same directory and make the info.pl file readable and executable
$ chmod 500 info.pl

and make the logos.pl file readable
$ chmod 400 logos.pl


You can run the script from inside the directory as
$ ./info.pl


Here is a picture of the script in action


While the logos.pl file given here is for Arch Linux only, you can modify it to suit your distro and use the info.pl script along with it.

note: the scripts are not mine, the name of the author is mentioned in the script itself

Tuesday, August 19, 2008

10+ essential programs for the terminal junkie

The command line in a Linux system is one area that a new user despises and a long time pro seeks to master. While the shell is powerfull in itself, there are still some tasks that requires a separate program, for instance playing music, IMs, browsing the web, etc.

Lets take a look at some command line applications that does the job and does it well.


screen


Simply put, screen is a window manager that allows you to run multiple terminals from a single terminal process. It allows session-sharing, persistence and multiple windows. One can simple detach a session and then later attach it to continue a previous work without starting all over again. Specially usefull without a Xession as it allows more than 6 terminals, by multiplexing.


vim


Vim, though not the most intuitive of all, is a power packed text editor that is ideal for programming as well as for general text editing. Vim is modal in nature and includes no menus or mouse features. All the features are accessible via commands and keybindings. Vim also supports autocompletion for various programming languages via add-on scripts called omnifunc. A built in tutorial vimtutor is included, that helps in getting started. While the age old war between vim and emacs continues, both are well accepted in the Linux community.


Latex


Latex is a proffessional typesetting system designed for technical, scientific, mathematical documentaion. It is however a language that accesses the power of Tex, hence a suitable text editor is needed along with it. Latex, used mostly for desktop publishing and word processing, can also be used to create raster graphics.


elinks


Complete with table and frame rendering,tab support,color support,multiple items download in the background, elinks is a powerpacked web browser. The arrow keys can be used to browse through the links, and by using the "." key, one can also just type in the link number to open it. Great for browsing over ssh or just for a low bandwidth connection.See this list for other text based web-browsers


alpine


Alpine, based on the old pine mail client and licensed under the apache license, is a simple yet efficient text-based mail client. Unlike mutt, it doesn't need any external program to fetch mails and with its context-sensitive help, is very easy to use. Mutt is another viable alternative to alpine.
According to an interview published in Lifehacker, Linus Torvalds himself uses alpine.


irssi


Supports add-on perl scripts, auto logging and can also be themed. It has highly configurable keybindgins that ensures maximum customizeability. Also while irssi is specifically targeted towards IRC, when combined with bitlbee, it adds IM functionality also. One point for bitlbee users though, its better not to use public servers for security reasons. WeeChat is a viable alternative to irssi, you may also want to have a look at it.


ncmpc + mpd


Music Player Daemon (MPD) is based on the client-server architecture. The daemon stays in background and actually plays the tracks while the client(ncmpc) is used to control the playlist, sounds etc. The real advantage of mpd over other console based players like cmus, moc, etc is that it allows remote access, that is, the daemon can run in one computer while the client connects to it from a remote computer to control it. Combined with icecast, mpd can be converted into a audio streaming server. These are the other clients supporting mpd.


mplayer


MPlayer supports a wide range of supported output drivers, Xv,X11,DirectFB,etc. It plays most audio and video file types and can be used with or without a GUI frontend. Enabling framebuffer allows one to watch videos on mplayer without even starting a X session. Also included in the mencoder which is a video filtering, decoding, and encoding tool that works from the command line.


rTorrent


rTorrent, as is obvious from its name, is a bittorrent client with ncurses interface. It can watch a directory for torrent files and automatically download them, and if required move them to a separate directory. It supports session control,DHT along with other features and allows the user to select the files to download if the torrent consists of more than one file. rTorrent can be operated over ssh and thus can be used in a torrent slave. For instructions on setting up rTorrent follow K.Mandla’s article.


midnight commander


Midnight Commander is a two-panel file manager, that can open RPM or other archive packages without extracting, serve as a FTP or FISH client and rename multiple files. It has a ncurses based interfaces and is useful for file manegment in a console or via ssh.

I left out those that are shipped with most distros like nmap, htop, etc. Other console applications that maybe of interest include the fbida project, bandwidth monitor, youtube-dl, MS word reader.

Did I miss your favourite application? Tell me about it.

note: images taken from wikipedia or the application's home page

Monday, August 18, 2008

Moving on with python... get rid of any file

Ok this might look pretty silly,but I feel compelled to delete every Thumbs.db file that I tend to recieve from my friends. The file is generated in windows systems when one views the contents of a directory in "Thumbnail" or "Filmstrip" mode. The idea is to store the settings with regard to thumbnail and filmstrip view, as well as to keep a cache of the thumbnail of image and video files.

Whenever I borrow some pics or movies from my friends' DVDs, etc, these tiny little files also gets copied over. Now these are completely harmless as far as I know, but since they are of no use in Linux, I dont want them in my system.

Now, deleting a particular file inside every directory is a pretty troublesome task. Hence, I wrote myself a neat little python program that searches directories, passed to it as the absolute path, for the file mentioned and prompts for its removal.

Here goes my first ever self-written-useful-program.


#!/usr/bin/env python
import os
import sys

def del_thumbs_db (start_path):
for i in os.listdir (start_path):
if i=="Thumbs.db": # change to whatever file you want to remove
del_file = os.path.join (start_path, i)
print """
FILE : %s
""" % del_file
#comment out next two lines to removing prompting for each file
ch = raw_input("\nDelete the file ? ")
if ch == "y" or ch == "Y":
os.unlink (del_file)
i = os.path.join (start_path, i)
if os.path.isdir (i):
del_thumbs_db (i)

if len (sys.argv) != 2:
print """thumbs needs an argument..!!
Usage: thumbs [absolute path]"""
quit ()
path = os.path.abspath (sys.argv[1])
if os.path.isdir (path):
del_thumbs_db (path)
else:
print "path is not a directory ..."


Usage is pretty simple, save the program in a file (say, delete) and make it executable by
# chmod +x /path/to/delete

then run the program like this,

$ delete /absolute/path/to/directory/

The program starts searching for the file mentioned, from the directory passed as argument and goes on recursively to search in subdirectories.

Now a simple bash script like this one
rm `find /home/user/path -name 'pattern_to_search_for'`

would have been easier and better suitable for this task, however, that way I was never going to really get on with python. Hoping for some python expert to come along and provide some insight on this code.

Your comments are welcome. :)