Compare commits
3 Commits
c608fd2668
...
2fc94ce2b7
Author | SHA1 | Date |
---|---|---|
Moridius | 2fc94ce2b7 | |
Moridius | ecf967e3f5 | |
Moridius | 17086e7da6 |
|
@ -14,7 +14,7 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "blinddate"
|
name = "blinddate"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"enigo",
|
"enigo",
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
[package]
|
[package]
|
||||||
name = "blinddate"
|
name = "blinddate"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
authors = ["Moridius <moridius-github@posteo.hu>"]
|
authors = ["Moridius <moridius-github@posteo.hu>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4.9"
|
chrono = "0.4"
|
||||||
enigo = "0.0.13"
|
enigo = "0.0"
|
||||||
|
|
44
src/main.rs
44
src/main.rs
|
@ -13,18 +13,18 @@ fn command_to_date(command: &str) -> Result<Date<Local>, ()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calc_date(command: &str, today: Date<Local>) -> Result<Date<Local>, ()> {
|
fn calc_date(command: &str, today: Date<Local>) -> Result<Date<Local>, ()> {
|
||||||
let wday = today.weekday().num_days_from_monday() as i64;
|
let offset = if command == "today" {
|
||||||
if command == "today" {
|
Ok(0)
|
||||||
return Ok(today);
|
|
||||||
} else if command == "tomorrow" {
|
} else if command == "tomorrow" {
|
||||||
return Ok(today + Duration::days(1));
|
Ok(1)
|
||||||
} else if command == "yesterday" {
|
} else if command == "yesterday" {
|
||||||
return Ok(today - Duration::days(1));
|
Ok(-1)
|
||||||
} else if command == "daybeforeyesterday" {
|
} else if command == "daybeforeyesterday" {
|
||||||
return Ok(today - Duration::days(2));
|
Ok(-2)
|
||||||
} else if command == "dayaftertomorrow" {
|
} else if command == "dayaftertomorrow" {
|
||||||
return Ok(today + Duration::days(2));
|
Ok(2)
|
||||||
} else if command.starts_with("next") || command.starts_with("last") {
|
} else if command.starts_with("next") || command.starts_with("last") {
|
||||||
|
let wday = today.weekday().num_days_from_monday() as i64;
|
||||||
let target = match &command[4..] {
|
let target = match &command[4..] {
|
||||||
"monday" => Ok(0),
|
"monday" => Ok(0),
|
||||||
"tuesday" => Ok(1),
|
"tuesday" => Ok(1),
|
||||||
|
@ -38,17 +38,24 @@ fn calc_date(command: &str, today: Date<Local>) -> Result<Date<Local>, ()> {
|
||||||
|
|
||||||
if let Ok(target) = target {
|
if let Ok(target) = target {
|
||||||
if command.starts_with("next") {
|
if command.starts_with("next") {
|
||||||
let offset = (target - wday + 7 - 1) % 7 + 1;
|
Ok((target - wday + 7 - 1) % 7 + 1)
|
||||||
return Ok(today + Duration::days(offset));
|
} else {
|
||||||
|
Ok(-((wday - target + 7 - 1) % 7 + 1))
|
||||||
}
|
}
|
||||||
let offset = (wday - target + 7 - 1) % 7 + 1;
|
} else {
|
||||||
return Ok(today - Duration::days(offset));
|
Err(())
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return Err(());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if let Ok(offset) = offset {
|
||||||
|
return Ok(today + Duration::days(offset));
|
||||||
|
}
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_date(date: Date<Local>, alt_tab: bool) {
|
fn type_date(date: Date<Local>, alt_tab: bool, enter: bool) {
|
||||||
let date_str = format!("{}", date.format("%Y-%m-%d"));
|
let date_str = format!("{}", date.format("%Y-%m-%d"));
|
||||||
let mut enigo = Enigo::new();
|
let mut enigo = Enigo::new();
|
||||||
if alt_tab {
|
if alt_tab {
|
||||||
|
@ -57,19 +64,26 @@ fn type_date(date: Date<Local>, alt_tab: bool) {
|
||||||
enigo.key_up(Key::Alt);
|
enigo.key_up(Key::Alt);
|
||||||
thread::sleep(time::Duration::from_millis(100));
|
thread::sleep(time::Duration::from_millis(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
for c in date_str.chars() {
|
for c in date_str.chars() {
|
||||||
enigo.key_click(Key::Layout(c));
|
enigo.key_click(Key::Layout(c));
|
||||||
}
|
}
|
||||||
// enigo.key_click(Key::Return);
|
|
||||||
|
if enter {
|
||||||
|
enigo.key_click(Key::Return);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut command = String::new();
|
let mut command = String::new();
|
||||||
let mut alt_tab = false;
|
let mut alt_tab = false;
|
||||||
|
let mut enter = false;
|
||||||
|
|
||||||
for arg in env::args() {
|
for arg in env::args().skip(1) {
|
||||||
if arg == "--tab" {
|
if arg == "--tab" {
|
||||||
alt_tab = true;
|
alt_tab = true;
|
||||||
|
} else if arg == "--enter" {
|
||||||
|
enter = true;
|
||||||
} else {
|
} else {
|
||||||
command = arg.to_lowercase();
|
command = arg.to_lowercase();
|
||||||
break;
|
break;
|
||||||
|
@ -77,7 +91,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(date) = command_to_date(&command) {
|
if let Ok(date) = command_to_date(&command) {
|
||||||
type_date(date, alt_tab);
|
type_date(date, alt_tab, enter);
|
||||||
} else {
|
} else {
|
||||||
eprintln!("blinddate");
|
eprintln!("blinddate");
|
||||||
eprintln!("Calculates a date and types it. Use with a shell script to enter dates into files rapidly.");
|
eprintln!("Calculates a date and types it. Use with a shell script to enter dates into files rapidly.");
|
||||||
|
|
Loading…
Reference in New Issue