From 35fd332aab6f6b5e3e452c3663c184f22226143e Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Sat, 26 Jul 2025 10:50:31 -0400 Subject: [PATCH] Fixed remaining problems with using xdg structure to store configuration files, e.g. key. --- ttyverse.pl | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/ttyverse.pl b/ttyverse.pl index dcb6dc4..a94aafc 100755 --- a/ttyverse.pl +++ b/ttyverse.pl @@ -22,15 +22,7 @@ require 5.005; use File::Path qw(make_path); -# Use XDG_CONFIG_HOME or default to ~/.config -our $config = ($ENV{'XDG_CONFIG_HOME'} || "$ENV{'HOME'}/.config") . '/ttyverse'; -# Check if the directory exists; if not, create it -unless (-d $config) { - eval { make_path($config) }; - if ($@) { - die "Failed to create directory: $@"; - } -} +# XDG configuration will be set up in the BEGIN block BEGIN { # ONLY STUFF THAT MUST RUN BEFORE INITIALIZATION GOES HERE! @@ -240,10 +232,20 @@ EOF $trendsurl = "${apibase}/trends"; } + # Set up XDG config directory + our $config = ($ENV{'XDG_CONFIG_HOME'} || "$ENV{'HOME'}/.config") . '/ttyverse'; + # Check if the directory exists; if not, create it + unless (-d $config) { + eval { make_path($config) }; + if ($@) { + die "Failed to create directory: $@"; + } + } + # try to find an OAuth keyfile if we haven't specified key+secret # no worries if this fails; we could be Basic Auth, after all $whine = (length($keyf)) ? 1 : 0; - $keyf ||= "$config key"; + $keyf ||= "$config/key"; $attempted_keyf = $keyf; if (!length($oauthkey) && !length($oauthsecret) # set later && !length($tokenkey) @@ -1130,7 +1132,7 @@ you use with TTYverse; only one account token can be stored per keyfile. If you have multiple accounts, use -keyf=... to specify different keyfiles. KEEP THESE FILES SECRET. -** This wizard will overwrite $config/$keyf +** This wizard will overwrite $keyf Press RETURN/ENTER to continue or CTRL-C NOW! to abort. EOF $j = ;