Linux::DesktopFiles - Get and parse the Linux .desktop files.
use Linux::DesktopFiles; my $obj = Linux::DesktopFiles->new( terminalize => 1 ); print join "\n", $obj->get_desktop_files; my $hash_ref = $obj->parse_desktop_files;
The Linux::DesktopFiles is a very simple module to parse .desktop files.
Linux::DesktopFiles
The following constructor methods are available:
This method constructs a new Linux::DesktopFiles object and returns it. Key/value pair arguments may be provided to set up the initial state. The following options correspond to attribute methods described below:
KEY DEFAULT ----------- -------------------- with_icons 0 full_icon_paths 0 skip_svg_icons 0 icon_db_filename undef icon_dirs_first undef icon_dirs_second undef icon_dirs_last undef categories_case_sensitive 0 keep_empty_categories 0 use_only_my_icon_dirs 0 terminalize 0 terminal $ENV{TERM} home_dir $ENV{HOME} gtk_rc_filename "~/.gtkrc-2.0" true_value ['true', 'True', '1'] skip_file_name_re undef skip_app_name_re undef skip_app_command_re undef skip_file_content_re undef clean_command_name_re undef desktop_files_paths ['/usr/share/applications'] keys_to_keep ["Name", "Exec"] categories [qw( utility development education game graphics audiovideo network office settings system ) ]
Set directories where to find the .desktop files (default: /usr/share/applications)
Any of the valid keys from .desktop files. This keys will be stored in the retured hash reference when calling $obj->parse_desktop_files.
$obj->parse_desktop_files
Any of the valid categories from the .desktop files. Any category not listed, will be ignored.
If a category is empty, keep it in the returned hash reference when parse_desktop_files is called.
Make categories case sensitive. By default, they are case insensitive in a way that "X-XFCE4" is equivalent to "x_xfce4".
When Terminal is true, modify the Exec value to something like: terminal -e 'command'
This terminal will be used when terminalize is set to a true value.
Set the home directory. This value is used to locate icons in the ~/.local/share/icons.
This file is used to get the icon theme name from it. (default: ~/.gtkrc-2.0) NOTE: It works with Gtk3 as well.
This values are used to test for true some values from the .desktop files.
Require icons. Unless full_icon_paths is set to a true value, this option will return icon names without the extension. If an Icon value is an absolute path to an icon in the system, it will be returned as it is.
Full icon paths for Icon values.
GDBM database name used to store icon names as keys and icon paths as values for a faster lookup (used with GDBM_File). NOTE: Works in combination with full_icon_paths and with_icons
Ignore .svg icons when looking for full icon paths.
When looking for full icon paths, look in this directories first, before looking in the directories of the current icon theme.
When looking for full icon paths, look in this directories as a second icon theme. (Before /usr/share/pixmaps)
Look in this directories at the very last, after looked in /usr/share/pixmaps, /usr/share/icons/hicolor and some other directories.
Be very strict and use only the directories specified by you in either one of icon_dirs_first, icon_dirs_second and/or icon_dirs_last
Skip .desktop files if their file names will match the regex. NOTE: File names are from the last slash to the end.
Skip .desktop files based on the value of Name.
Skip .desktop files based on the value of Exec.
Skip .desktop files if the regex matches anywhere in the [Desktop Entry] section.
Anything matched by this regex in the values of Exec will be replaced with nothing.
Iterate over desktop files, one file at a time.
Get all desktop files. In list context it returns a list, but in scalar context, it returns an array reference containing the full names of the desktop files.
Returns the icon theme name, if any, otherwise it returns an empty string.
If full_icon_paths is set to a true value, it returns the absolute path of a icon name located in the system. If it can't found the icon name, it returns an empty string. If full_icon_paths is set to a false value, it strips the extension name of the icon (if any), and returns the icon name. If the icon name is undefined, it returns an empty string.
It returns a HASH reference which contains the keys_to_keep and the values from the desktop file specified as an argument.
It returns a HASH reference which categories names as keys, and ARRAY references as values which contains HASH references with the keys specified in the keys_to_keep option, and values from the .desktop files.
The returned HASH reference might look something like this:
{ utility => [ {Exec => "...", Name => "..."}, {Exec => "...", Name => "..."} ], network => [ {Exec => "...", Name => "..."}, {Exec => "...", Name => "..."} ], }
Trizen, <trizenx@gmail.com>
Copyright (C) 2012 by Trizen
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.
File::DesktopEntry and X11::FreeDesktop::DesktopEntry
To install Linux::DesktopFiles, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Linux::DesktopFiles
CPAN shell
perl -MCPAN -e shell install Linux::DesktopFiles
For more information on module installation, please visit the detailed CPAN module installation guide.