A Tcl module to access the XDG Base Directory Specification
Tcl
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
tests
.gitignore
CHANGELOG.md
LICENCE.md
README.md
xdgbasedir-0.3.tm

README.md

xdgbasedir_tcl

A Tcl module to simplify access to the XDG Base Directory Specification

The XDG Base Directory Specification aims to tidy up the files related to an application and standardize their location.

Requirements

  • Tcl 8.5+

Installation

To install the module you can use the installmodule.tcl script or if you want to manually copy the file xdgbasedir-*.tm to a specific location that tcl expects to find modules. This would typically be something like:

/usr/share/tcltk/tcl8.5/tcl8/

To find out what directories are searched for modules, start tclsh and enter:

foreach dir [split [::tcl::tm::path list]] {puts $dir}

or from the command line:

$ echo "foreach dir [split [::tcl::tm::path list]] {puts \$dir}" | tclsh

Module Usage

To access the XDG directories you would typically specify the subdirectory that these directories will be relative to. The subdirectory is normally the name of the application:

package require xdgbasedir

puts "XDG_DATA_HOME: [XDG::DATA_HOME myapp]"
puts "XDG_CACHE_HOME: [XDG::CACHE_HOME myapp]"
puts "XDG_CONFIG_HOME: [XDG::CONFIG_HOME myapp]"

puts "XDG_RUNTIME_DIR: [XDG::RUNTIME_DIR myapp]"
puts "XDG_DATA_DIRS: [XDG::DATA_DIRS myapp]"
puts "XDG_CONFIG_DIRS: [XDG::CONFIG_DIRS myapp]"

The XDG procs ending in _DIRS return a list of directories in order of preference.

Testing

There is a testsuite in tests/. To run it:

$ tclsh tests/xdgbasedir.test.tcl

Contributions

If you want to improve this module make a pull request to the repo on github. Please put any pull requests in a separate branch to ease integration and add a test to prove that it works.

Licence

Copyright (C) 2013, Lawrence Woodman

This software is licensed under an MIT Licence. Please see the file, LICENCE.md, for details.