Skip to content

Commit ccd9f04

Browse files
authored
Merge pull request #168 from GlowingScrewdriver/tilde-expansion
2 parents 60286d8 + aeb57b1 commit ccd9f04

File tree

5 files changed

+43
-9
lines changed

5 files changed

+43
-9
lines changed

Cargo.lock

Lines changed: 29 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ serde_json = "1.0"
3030
ron = "0.7.0"
3131
notify = "4.0.17"
3232
bitflags = "1.2"
33+
home-dir = "0.1.0"

src/main.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::{
1414
fs::File,
1515
fs::OpenOptions,
1616
io::Write,
17+
path::PathBuf,
1718
time::{Duration, Instant},
1819
};
1920

@@ -27,6 +28,7 @@ use winit::{
2728
use bus::dbus::{Message, Notification, Timeout};
2829
use cli::ShouldRun;
2930
use config::Config;
31+
use home_dir::HomeDirExt;
3032
use manager::NotifyWindowManager;
3133

3234
fn try_print_to_file(notification: &Notification, file: &mut File) {
@@ -46,11 +48,19 @@ fn try_print_to_file(notification: &Notification, file: &mut File) {
4648

4749
fn open_print_file() -> Option<File> {
4850
if let Some(filename) = Config::get().print_to_file.as_ref() {
51+
let maybe_path = PathBuf::from(filename).expand_home();
52+
let expanded_filename = match maybe_path {
53+
Ok(f) => f,
54+
Err(e) => {
55+
eprintln!("Failed tilde expansion: {}", e);
56+
return None;
57+
}
58+
};
4959
let maybe_file = OpenOptions::new()
5060
.write(true)
5161
.create(true)
5262
.truncate(true)
53-
.open(filename);
63+
.open(expanded_filename);
5464
match maybe_file {
5565
Ok(f) => return Some(f),
5666
Err(e) => {

wired.ron

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
// Default: Mouse
7171
//focus_follows: Mouse,
7272

73-
// Enable printing notification data to a file.
73+
// Enable printing notification data to a file. Tilde expansion is supported.
7474
// Useful for scripting purposes.
7575
// The data is written as JSON.
7676
// Default: None

wired_multilayout.ron

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
// Default: Mouse
4949
//focus_follows: Mouse,
5050

51-
// Enable printing notification data to a file.
51+
// Enable printing notification data to a file. Tilde expansion is supported.
5252
// Useful for scripting purposes.
5353
// The data is written as JSON.
5454
// Default: None

0 commit comments

Comments
 (0)