Skip to content

Commit 5f06cf8

Browse files
author
Serhiy Barhamon
authored
Merge pull request #10 from Lurk/config_path
proper config path
2 parents 919a60d + 91087d1 commit 5f06cf8

File tree

5 files changed

+45
-13
lines changed

5 files changed

+45
-13
lines changed

Cargo.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clink"
3-
version = "0.4.1"
3+
version = "0.5.0"
44
authors = ["Sergey Bargamon <sergey@bargamon.ru>"]
55
edition = "2018"
66

@@ -14,4 +14,5 @@ rustop = "1.1.1"
1414
rand = "0.8.3"
1515
confy="0.4.0"
1616
serde = { version = "1.0", features = ["derive"] }
17-
chrono = "0.4"
17+
chrono = "0.4"
18+
dirs = "3.0.1"

readme.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,17 @@ It sits quietly in the background, and if you copy a link to the clipboard, Clin
55

66
## Config
77

8-
In 0.4.0, we introduced the toml config. Clink will create a "clink.toml" file in a directory where the executable is located on a first-run. In this file, you will find the default config for Clink.
8+
Path for config file can be altered by -c, --config option.
9+
Default path:
10+
* Mac: /Users/Alice/Library/Application Support\clink\config.toml
11+
* Lin: /home/alice/.config/clink/config.toml
12+
* Win: C:\Users\Alice\AppData\Roaming\clink\config.toml
13+
* fallback: current directory/config.toml
14+
15+
16+
On the first run, clink will create the default config in the path.
17+
18+
Default config:
919

1020
```
1121
# You can find detail description of modes bellow
@@ -28,7 +38,7 @@ params = [
2838
'utm_campaign', # Identifies a specific product promotion or strategic campaign
2939
'utm_medium', # Identifies what type of link was used
3040
'utm_term', # Identifies search terms
31-
'utm_content', Identifies what specifically was clicked to bring the user to the site
41+
'utm_content', # Identifies what specifically was clicked to bring the user to the site
3242
]
3343
```
3444

src/main.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ mod utils;
44

55
use mode::Mode;
66
use params::{create_index, get_default_params};
7-
use utils::find_and_replace;
7+
use utils::{fallback_config_path, find_and_replace};
88

99
use clipboard::{ClipboardContext, ClipboardProvider};
10+
use dirs::config_dir;
1011
use rustop::opts;
1112
use serde::{Deserialize, Serialize};
12-
use std::thread;
1313
use std::time::Duration;
14+
use std::{path::PathBuf, thread};
1415

1516
#[derive(Serialize, Deserialize, Debug)]
1617
pub struct ClinkConfig {
@@ -39,14 +40,11 @@ fn main() -> Result<(), confy::ConfyError> {
3940
synopsis "Clink automatically cleans url in your clipboard";
4041
version env!("CARGO_PKG_VERSION");
4142
opt verbose:bool, desc:"Be verbose.";
43+
opt config:String = fallback_config_path(config_dir()).into_os_string().into_string().unwrap(), desc: "config path";
4244
}
4345
.parse_or_exit();
4446

45-
let config_path = std::env::current_exe()
46-
.unwrap()
47-
.parent()
48-
.unwrap()
49-
.join("clink.toml");
47+
let config_path = PathBuf::from(args.config);
5048
let cfg: ClinkConfig = confy::load_path(&config_path)?;
5149

5250
if !config_path.is_file() {

src/utils.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::ClinkConfig;
44
use chrono::prelude::*;
55
use linkify::{LinkFinder, LinkKind};
66
use rand::Rng;
7-
use std::collections::HashMap;
7+
use std::{collections::HashMap, path::PathBuf};
88
use url::Url;
99

1010
#[cfg(test)]
@@ -323,3 +323,16 @@ fn your_mom(
323323
})
324324
.collect()
325325
}
326+
327+
pub fn fallback_config_path(path: Option<PathBuf>) -> PathBuf {
328+
let p = match path {
329+
Some(p) => p.join("clink"),
330+
None => std::env::current_exe()
331+
.unwrap()
332+
.parent()
333+
.unwrap()
334+
.to_path_buf(),
335+
};
336+
337+
p.join("config.toml")
338+
}

0 commit comments

Comments
 (0)