added -createrc option for a commented settings file.

This commit is contained in:
Storm Dragon
2025-07-26 11:22:20 -04:00
parent cac1c0f3a9
commit 1f62effe0b
+93 -9
View File
@@ -48,6 +48,96 @@ BEGIN {
$my_version_string = ($TTYverse_PATCH_VERSION) ? "${TTYverse_VERSION}.${TTYverse_PATCH_VERSION}" : "${TTYverse_VERSION}";
(warn ("$my_version_string\n"), exit) if ($version);
# Set up XDG config directory early for -create-rc
our $config = ($ENV{'XDG_CONFIG_HOME'} || "$ENV{'HOME'}/.config") . '/ttyverse';
# Check if the directory exists; if not, create it
unless (-d $config) {
eval { require File::Path; File::Path::make_path($config) };
if ($@) {
die "Failed to create directory: $@";
}
}
# Handle -createrc option early
if ($createrc) {
my $rc_path = "$config/ttyverserc";
if (-e $rc_path) {
print STDERR "-- RC file already exists: $rc_path\n";
print STDERR "-- Remove it first or use a different RC filename\n";
exit 0;
}
print STDERR "-- Creating default RC file: $rc_path\n";
open(my $rc_fh, '>', $rc_path) or die "-- Can't create RC file: $!\n";
print $rc_fh <<'EOF';
# TTYverse Configuration File
# Uncomment and modify any option you want to change from the default
# For boolean options, use 1 to enable, 0 to disable
# Lines starting with # are ignored
# === CONNECTION SETTINGS ===
# fediverseserver=mastodon.social # Your fediverse server
# ssl=1 # Use SSL/HTTPS (recommended)
# authtype=oauth2 # Authentication type (oauth2 for fediverse)
# === TIMELINE SETTINGS ===
# pause=auto # Auto-refresh rate (seconds, or 'auto')
# backload=30 # Number of posts to load initially
# wrap=120 # Text wrapping width
# timestamp=0 # Show timestamps on posts
# noreblogs=0 # Hide boost/reblog posts
# === DISPLAY SETTINGS ===
# ansi=1 # Use ANSI colors
# verbose=0 # Show debug information
# silent=0 # Reduce output messages
# readline=1 # Use readline for input (if available)
# === POST SETTINGS ===
# post_visibility=public # Default post visibility (public, unlisted, private, direct)
# linelength=5000 # Maximum post length
# === COLORS ===
# colourprompt=CYAN # Prompt color
# colourme=YELLOW # Your posts color
# colourdm=GREEN # Direct message color
# colourreply=RED # Reply posts color
# colourwarn=MAGENTA # Warning message color
# coloursearch=CYAN # Search result color
# colourlist=OFF # List posts color
# colourdefault=OFF # Default text color
# === ADVANCED SETTINGS ===
# dostream=0 # Enable streaming API (real-time updates)
# synch=0 # Synchronous mode (blocks on requests)
# maxhist=10 # Command history size
# location=0 # Include location in posts
# notimeline=0 # Disable timeline display
# daemon=0 # Run as daemon (background)
# === NOTIFICATION SETTINGS ===
# notifies= # Comma-separated list of notification types
# notifyquiet=0 # Quiet notifications
# === FILTER SETTINGS ===
# track= # Track keywords (comma-separated)
# filter= # Filter out posts containing these terms
# === EXTENSION SETTINGS ===
# Any setting starting with 'extpref_' is for extensions
# extpref_example_setting=value
EOF
close($rc_fh);
print STDERR "-- RC file created successfully!\n";
print STDERR "-- Edit $rc_path to customize your settings\n";
print STDERR "-- Restart TTYverse to use the new settings\n";
exit 0;
}
$space_pad = " " x 1024;
$background_is_ready = 0;
@@ -122,6 +212,7 @@ BEGIN {
simplestart exception_is_maskable oldperl notco
notify_tool_path oauthurl oauthauthurl oauthaccurl oauthbase
signals_use_posix dostream eventbuf streamallreplies
createrc
); %valid = (%opts_can_set, %opts_others);
$rc = (defined($rc) && length($rc)) ? $rc : "";
unless ($norc) {
@@ -232,15 +323,8 @@ 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: $@";
}
}
# XDG config directory already set up earlier
# 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