This is going to seem like a very esoteric line of inquiry, I suspect, but I will put it out here for the fine monks and nuns to give me feedback.

I use a computer with Windows 10 and with Cygwin installed (as I often mention on PMo). I have this computer and 5 other computers to configure for file locations under my home dir for the vim editor, meaning places to keep backup files and to keep swap files. All those 5 systems run Debian or some derivative distro of Debian Gnu/Linux. So things as they stand will be relatively predictable when I get around to configuring them. Yes, I could do this "by hand" on each system, but automating such a repetitive chore is exactly one of the compelling reasons Perl exists.

Here are the outputs of my script using File::XDG at this stage of writing it (see the code below):

According to File::XDG on Cygwin, the following directories would be used for "vim":

Config for app vim is   C:/Users/somia/config/vim
Data for app   vim is   C:/Users/somia/AppData/share/vim
Cache for app  vim is   C:/Users/somia/cache/vim

According to File::XDG on MSWin32, the following directories would be used for "vim":

Config for app vim is   C:/Users/somia/AppData/Local/.config/vim
Data for app   vim is   C:/Users/somia/AppData/Local/.local/share/vim
Cache for app  vim is   C:/Users/somia/AppData/Local/.cache/vim

According to File::XDG on Linux, the following directories would be used for "vim":

Config for app vim is   /home/somian/.config/vim
Data for app   vim is   /home/somian/.local/share/vim
Cache for app  vim is   /home/somian/.cache/vim
Pretty unpredictable, huh! Note in particular the distinction between the Cygwin results and the MSWin results. I could use CygwinPerl for this, or Strawberry. In the end, maybe it's basically an esthetic choice. Which looks better to you? I'm leaning towards the choice made by Strawberry (Win32) perl.

The Code

EDIT

The original code I posted - unfinished, placed in READMORE tags:

#!/usr/bin/env perl use strict; use v5.18; use utf8; use warnings; =head1 SYNOPSIS perl Emplace-XDG-dirs =cut use Carp qw(carp croak); use Try::Tiny; use File::XDG 1.00; use File::Path qw(mkpath); use File::Basename; my ($appName, $XDGUser, $XDGData, $XDGCache); $appName = 'vim'; my $xdgEmp = File::XDG->new( name => $appName , api => 1 ); $XDGUser = $xdgEmp->config_home; $XDGData = $xdgEmp->data_home; $XDGCache = $xdgEmp->cache_home; say <<EOFILE; According to File::XDG the following directories would be used for "vi +m": EOFILE say sprintf "Config for app $appName is\t%s", $XDGUser; say sprintf "Data for app $appName is\t%s", $XDGData; say sprintf "Cache for app $appName is\t%s", $XDGCache; print q[-] x 88; print $/;

The (probably) final code

#!/usr/bin/env perl # Last modified: Tue May 27 2025 03:02:52 PM -04:00 [EDT] use strict; use v5.18; use utf8; use warnings; =head1 SYNOPSIS perl Emplace-XDG-dirs =cut use File::XDG 1.00; use File::Spec; use File::Path qw(mkpath rmtree); use subs qw/tellMe/; my ($XDGUser, $XDGData, $XDGCache); my $appName = 'vim'; my $xdgEmp = File::XDG->new( name => $appName , api => 1 ); $XDGUser = $xdgEmp->config_home; $XDGData = $xdgEmp->data_home; $XDGCache = $xdgEmp->cache_home; my @branches = (File::Spec->catdir($XDGData => 'backups'), File::Spec->catdir($XDGData => 'swapfiles')); say "We could make these dirs for you:"; say join qq[\n]=>@branches, ''; if (tellMe("making those dirs for $appName")) { mkpath (@branches, {verbose => 'true', mode => 0775}); } else { say "No? OK, aborting now"; } =head2 Vim settings Put in our .vimrc config file: set backup set backupcopy=auto set backupdir= ... (dir created by script) set directory= ... (dir created by script) =cut sub tellMe { my $gummy = $_[0]; my $ans = "Y"; printf "Do you want proceed with: %s? [Y/n]\n", $gummy; chomp ($ans = <STDIN>); if ($ans =~/Y|y/) { return 1; } elsif ($ans eq '') { return 1; } else { return 0; } } # vim: ft=perl et sw=4 ts=4 :

Thanks for your interest!

May 27, 2025 at 19:04 UTC

A just machine to make big decisions
Programmed by fellows (and gals) with compassion and vision
We'll be clean when their work is done
We'll be eternally free yes, and eternally young
Donald Fagen —> I.G.Y.
(Slightly modified for inclusiveness)


In reply to File::XDG on varying platforms by Intrepid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.