aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ts/tskm/src/interface/neorg
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/ts/tskm/src/interface/neorg')
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/neorg/handle.rs45
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/neorg/mod.rs21
2 files changed, 46 insertions, 20 deletions
diff --git a/pkgs/by-name/ts/tskm/src/interface/neorg/handle.rs b/pkgs/by-name/ts/tskm/src/interface/neorg/handle.rs
index 577de02c..12a0180d 100644
--- a/pkgs/by-name/ts/tskm/src/interface/neorg/handle.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/neorg/handle.rs
@@ -1,3 +1,13 @@
+// nixos-config - My current NixOS configuration
+//
+// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// This file is part of my nixos-config.
+//
+// You should have received a copy of the License along with this program.
+// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+
use std::{
env,
fs::{self, read_to_string, File, OpenOptions},
@@ -9,14 +19,14 @@ use anyhow::{bail, Context, Result};
use crate::{cli::NeorgCommand, state::State};
-pub fn handle(command: NeorgCommand, state: &mut State) -> Result<()> {
+pub async fn handle(command: NeorgCommand, state: &mut State) -> Result<()> {
match command {
- NeorgCommand::Task { id } => {
- let project = id.project(state)?;
- let path = dirs::data_local_dir()
+ NeorgCommand::Task { task } => {
+ let project = task.project(state).await?;
+ let base = dirs::data_local_dir()
.expect("This should exists")
- .join("tskm/notes")
- .join(project.get_neorg_path()?);
+ .join("tskm/notes");
+ let path = base.join(project.get_neorg_path()?);
fs::create_dir_all(path.parent().expect("This should exist"))?;
@@ -30,15 +40,18 @@ pub fn handle(command: NeorgCommand, state: &mut State) -> Result<()> {
String::new()
};
- if !contents.contains(format!("% {}", id.uuid()).as_str()) {
+ if !contents.contains(format!("% {}", task.uuid()).as_str()) {
let mut options = OpenOptions::new();
options.append(true).create(false);
let mut file = options.open(&path)?;
- file.write_all(format!("* TITLE (% {})", id.uuid()).as_bytes())
- .with_context(|| {
- format!("Failed to write task uuid to file: '{}'", path.display())
- })?;
+ file.write_all(
+ format!("* {} (% {})", task.description(state).await?, task.uuid())
+ .as_bytes(),
+ )
+ .with_context(|| {
+ format!("Failed to write task uuid to file: '{}'", path.display())
+ })?;
file.flush()
.with_context(|| format!("Failed to flush file: '{}'", path.display()))?;
}
@@ -49,7 +62,7 @@ pub fn handle(command: NeorgCommand, state: &mut State) -> Result<()> {
.args([
path.to_str().expect("Should be a utf-8 str"),
"-c",
- format!("/% {}", id.uuid()).as_str(),
+ format!("/% {}", task.uuid()).as_str(),
])
.status()?;
if !status.success() {
@@ -69,11 +82,7 @@ pub fn handle(command: NeorgCommand, state: &mut State) -> Result<()> {
.args([
"commit",
"--message",
- format!(
- "chore({}): Update",
- path.parent().expect("Should have a parent").display()
- )
- .as_str(),
+ format!("chore({}): Update", project.get_neorg_path()?.display()).as_str(),
"--no-gpg-sign",
])
.current_dir(path.parent().expect("Will exist"))
@@ -84,7 +93,7 @@ pub fn handle(command: NeorgCommand, state: &mut State) -> Result<()> {
}
{
- id.mark_neorg_data(state)?;
+ task.mark_neorg_data(state).await?;
}
}
}
diff --git a/pkgs/by-name/ts/tskm/src/interface/neorg/mod.rs b/pkgs/by-name/ts/tskm/src/interface/neorg/mod.rs
index dc5cdf19..6bed1e39 100644
--- a/pkgs/by-name/ts/tskm/src/interface/neorg/mod.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/neorg/mod.rs
@@ -1,18 +1,35 @@
+// nixos-config - My current NixOS configuration
+//
+// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// This file is part of my nixos-config.
+//
+// You should have received a copy of the License along with this program.
+// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+
use std::path::PathBuf;
use anyhow::Result;
-use crate::task::{run_task, Project};
+use crate::task::{Project, run_task};
pub mod handle;
pub use handle::handle;
impl Project {
+ /// Return the stored neorg path of this project.
+ /// The returned path will never start with a slash (/).
pub(super) fn get_neorg_path(&self) -> Result<PathBuf> {
let project_path = run_task(&[
"_get",
format!("rc.context.{}.rc.neorg_path", self.to_context_display()).as_str(),
])?;
- Ok(PathBuf::from(project_path.as_str()))
+
+ let final_path = project_path
+ .strip_prefix('/')
+ .unwrap_or(project_path.as_str());
+
+ Ok(PathBuf::from(final_path))
}
}