Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 23 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use-native-certs = ["ureq/native-certs"]
[dependencies]
serde = { version = "1.0.228", default-features = false, features = ["derive"] }
toml = "1.1.0"
dirs-next = "2.0.0"
thiserror = "2.0.18"
getopts = "0.2.24"
ureq = { version = "2.12.1", features = ["json"] }
Expand All @@ -34,6 +33,7 @@ colored = "3.1.1"
url = "2.5.8"
indicatif = "0.18.4"
shellexpand = "3.1.2"
etcetera = "0.11.0"

[profile.release]
opt-level = 3
Expand Down
18 changes: 0 additions & 18 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::args::Args;
use serde::{Deserialize, Serialize};
use std::fs;
#[cfg(target_os = "macos")]
use std::{env, path::PathBuf};

/// Configuration values.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
Expand Down Expand Up @@ -96,22 +94,6 @@ impl Config {
};
};
}

/// Find a special config path on macOS.
///
/// The `dirs-next` crate ignores the `XDG_CONFIG_HOME` env var on macOS and only considers
/// `Library/Application Support` as the config dir, which is primarily used by GUI apps.
///
/// This function determines the config path and honors the `XDG_CONFIG_HOME` env var.
/// If it is not set, it will fall back to `~/.config`
#[cfg(target_os = "macos")]
pub(crate) fn retrieve_xdg_config_on_macos(&self) -> PathBuf {
let config_dir = env::var("XDG_CONFIG_HOME").map_or_else(
|_| dirs_next::home_dir().unwrap_or_default().join(".config"),
PathBuf::from,
);
config_dir.join("rustypaste")
}
}

#[cfg(test)]
Expand Down
21 changes: 17 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::config::Config;
use crate::error::{Error, Result};
use crate::upload::Uploader;
use colored::Colorize;
use etcetera::BaseStrategy;
use std::fs;
use std::io::IsTerminal;
use std::io::{self, Read};
Expand All @@ -30,14 +31,26 @@ pub fn run(args: Args) -> Result<()> {
if let Some(ref config_path) = args.config {
config = toml::from_str(&fs::read_to_string(config_path)?)?
} else {
// cannot panic - see https://github.com/lunacookies/etcetera/issues/42
let strategy = etcetera::choose_base_strategy()
.expect("cannot determine current OS's default strategy (layout)");
for path in [
dirs_next::home_dir().map(|p| p.join(".rustypaste").join(CONFIG_FILE)),
strategy.config_dir().join("rustypaste").join(CONFIG_FILE),
// paths for backwards compatibility
#[cfg(target_family = "unix")]
strategy
.home_dir()
.to_path_buf()
.join(".rustypaste")
.join(CONFIG_FILE),
#[cfg(target_os = "macos")]
Some(config.retrieve_xdg_config_on_macos().join(CONFIG_FILE)),
dirs_next::config_dir().map(|p| p.join("rustypaste").join(CONFIG_FILE)),
strategy
.home_dir()
.to_path_buf()
.join("Library/Application Support/rustypaste")
.join(CONFIG_FILE),
]
.iter()
.filter_map(|v| v.as_ref())
{
if path.exists() {
config = toml::from_str(&fs::read_to_string(path)?)?;
Expand Down
Loading