Intrepid has asked for the wisdom of the Perl Monks concerning the following question:
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):
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.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
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 $/;
#!/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 UTCA 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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File::XDG on varying platforms
by NERDVANA (Priest) on May 27, 2025 at 14:24 UTC | |
by Intrepid (Curate) on May 27, 2025 at 22:15 UTC | |
by NERDVANA (Priest) on May 28, 2025 at 00:25 UTC | |
by Intrepid (Curate) on May 28, 2025 at 02:45 UTC | |
by NERDVANA (Priest) on May 28, 2025 at 23:10 UTC | |
| |
by jo37 (Curate) on May 28, 2025 at 20:39 UTC | |
|
Re: File::XDG on varying platforms
by stevieb (Canon) on May 27, 2025 at 08:52 UTC |