well-known user folders, a proposal

Alexander Larsson alexl at redhat.com
Thu Feb 22 07:51:45 PST 2007


On Thu, 2007-02-22 at 09:32 -0500, Dan Winship wrote:
> On Thu, 2007-02-22 at 12:11 +0100, Alexander Larsson wrote:
> > In order to make it really easy for scripts to use this we store the
> > user settings in a form that is compatible with /bin/sh. This means
> > you can use them as simple as:
> > source ~/.config/user-dirs.dirs
> > echo $XDG_DOWNLOAD_DIR
> 
> That works for scripts that are part of the distro, but apps that need
> to work on either pre- or post- xdg-user-dirs-compliant systems would
> need something like
> 
>         test -f ~/.config/user-dirs.dirs && source ~/.config/user-dirs.dirs
>         echo ${XDG_DOWNLOAD_DIR:-~}
> 
> (And shouldn't "~/.config" be "${XDG_CONFIG_HOME:-~/.config}"?)
> 
> Probably best to provide a simple shell function people can copy+paste
> into their script, and then just do
> 
>         echo `xdg-user-dir DOWNLOAD`

This seems to work:

#!/bin/sh
test -f ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs && source
${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs
if [ "x$1" == "xDESKTOP" ]; then
  eval echo \${XDG_${1}_DIR:-$HOME/Desktop}
else
  eval echo \${XDG_${1}_DIR:-$HOME}
fi

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl at redhat.com    alla at lysator.liu.se 
He's a globe-trotting albino sorceror on the wrong side of the law. She's an 
artistic goth mercenary in the witness protection program. They fight crime! 




More information about the xdg mailing list