initial
This commit is contained in:
commit
76f3b6592d
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
7
.vscode/launch.json
vendored
Normal file
7
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": []
|
||||||
|
}
|
||||||
68
Cargo.lock
generated
Normal file
68
Cargo.lock
generated
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glob"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "motd-rust"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"glob",
|
||||||
|
"untildify",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.10.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.4.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "untildify"
|
||||||
|
version = "0.1.1"
|
||||||
|
dependencies = [
|
||||||
|
"regex",
|
||||||
|
]
|
||||||
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "motd-rust"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
glob = "0.3.1"
|
||||||
|
untildify = { path = "../untildify" }
|
||||||
28
src/files.rs
Normal file
28
src/files.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
use crate::structs::*;
|
||||||
|
use glob::glob;
|
||||||
|
use std::{fs, path::PathBuf};
|
||||||
|
use untildify::untildify;
|
||||||
|
|
||||||
|
pub fn load_motds() -> Vec<MOTD> {
|
||||||
|
let mut path: String = untildify("~/.local/motd");
|
||||||
|
path.push_str("/*.motd");
|
||||||
|
|
||||||
|
let mut motds = Vec::<MOTD>::new();
|
||||||
|
|
||||||
|
for entry in glob(&path).unwrap() {
|
||||||
|
match entry {
|
||||||
|
Ok(path) => motds.push(read_motd(path)),
|
||||||
|
Err(e) => {
|
||||||
|
println!("{}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
motds
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_motd(path: PathBuf) -> MOTD {
|
||||||
|
let motd_contents: String = fs::read_to_string(path).unwrap();
|
||||||
|
let motd = MOTD::new(motd_contents);
|
||||||
|
motd
|
||||||
|
}
|
||||||
14
src/main.rs
Normal file
14
src/main.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
mod files;
|
||||||
|
use files::*;
|
||||||
|
|
||||||
|
mod structs;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let motds = load_motds();
|
||||||
|
println!("** Important Notes **");
|
||||||
|
for motd in motds {
|
||||||
|
motd.print();
|
||||||
|
}
|
||||||
|
println!();
|
||||||
|
println!();
|
||||||
|
}
|
||||||
15
src/structs.rs
Normal file
15
src/structs.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
pub struct MOTD {
|
||||||
|
title: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MOTD {
|
||||||
|
pub fn new(motd_title: String) -> MOTD {
|
||||||
|
return MOTD {
|
||||||
|
title: Some(String::from(motd_title)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print(&self) {
|
||||||
|
println!("[*] {}", &self.title.as_ref().unwrap().trim())
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user