Sign In

    Enjoy FOSSwire's content? Have it delivered! Subscribe

    Count Lines of Code with Cloc

    While it might seem a little of a mundane task, counting the lines of code in your programming projects can be a useful thing to do, and provides you with interesting statistics.

    Cloc is a Perl script written to allow you to do just that. Download the script, and then from a command line, you simply pass it a directory of source code, or a single file if you wish.

    $ perl cloc.pl /path/to/code

    Cloc is more than just a tool for counting the number of lines in the file, it is more clever than that. Cloc detects the programming language if it can, and then shows you the number of blank lines, code and comments of each file.

    With a single file, Cloc might give output similar to this:

    Cloc screenshot 1

    As I've mentioned, however, Cloc's real strong point is when you point it at a directory or several directories of source code.

    Cloc screenshot 2

    Quite frankly, I think this is a pretty indispensable tool for any programmer interested in getting statistics on their code, especially when you want an overview of the whole project.

    Cloc can be downloaded from here. The Perl script version should work on any operating system where you have a working installation of Perl. Windows users can download the pre-built exe as well.


    Making KDE dialogue boxes appear from shell scripts

    Providing graphical feedback in the form of dialogue boxes when you're writing a shell script isn't really that easy to do yourself. If you're a KDE user, though, and want to write a shell script that gives you feedback in the form of one of these.

    FOSSwire KDialog

    This could be really useful if you want to set up a script that you want to be able to run graphically, for example, by making a link on your desktop to run it.

    So how does this all work? The secret is a program called KDialog. It should be installed with recent KDE versions, but if not, install the package kdialog from your package manager.

    Making a simple dialogue box appear is pretty simple. To use the example above, I just needed this command:

    $ kdialog --title FOSSwire --msgbox "FOSSwire is awesome"

    And that's it. Note the double quotes around the main message - if you have any spaces or special characters in either the title or the main text, you'll need to quote it to prevent the shell choking on the space and thinking it's another argument.

    As well as msgbox, there are also other types of dialogue you can experiment with creating. For example, you can use a text box to get textual input from the user, which is returned as the application's output. This means you can use it to gather some information from the user and use that later in the script.

    $ kdialog --title FOSSwire --textinputbox "Enter some text"

    Enter text dialogue

    Also available are options for creating yes/no dialogues, error boxes and much more. To find out exactly which type of alert would best suit you, simply run kdialog without any options to see the list of options.

    And have fun GUI-fying your scripts with KDE!


    ffmpegmenu - transcode videos from your file manager

    KDE users, here's a neat application that creates a 'service' in your file manager that allows you to easily convert videos to other formats using ffmpeg.

    ffmpegmenu is what you need. After copying the simple script into the right directory, an action will appear in the sidebar of either Konqueror or Dolphin (your choice), which easily allows you to convert selected video to DVD, MPEG or into iPod format with a couple of clicks.

    The script itself is very simple, such that it's definitely possible to edit it to customise the commands it runs to make your own ffmpeg conversion options. It does require you have ffmpeg and the necessary codecs to convert to DVD, MPEG and iPod already installed, as it is just a loader which calls ffmpeg. But enough of that, how do you actually install the script?

    Well, first of all, download it from KDE-Apps, direct download link here.

    When that file opens, save it as ffmpegmenu.desktop and put it on your desktop. All we now need to do is to copy the file into place.

    You'll probably need to be root to do this, so run su - first (or Ubuntu users, prefix the cp command below with sudo).

    # cd /home/yourusername/Desktop
    # cp ffmpegmenu.desktop /usr/share/apps/konqueror/servicemenus
    # cp ffmpegmenu.desktop /usr/share/apps/d3lphin/servicemenus

    Feel free to omit either the Konqueror or Dolphin command depending on whether you want this installed in one, the other, or both. Once installed, highlighting a .avi file should show the following in the sidebar (this screenshot from Dolphin):

    ffmpegmenu in action

    And it's done!

    If you want to uninstall, simply remove the ffmpegmenu.desktop files as root, like so:

    # rm /usr/share/apps/konqueror/servicemenus
    # rm /usr/share/apps/d3lphin/servicemenus