aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ts/tskm/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--pkgs/by-name/ts/tskm/src/browser/mod.rs217
-rw-r--r--pkgs/by-name/ts/tskm/src/cli.rs295
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/input/handle.rs131
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/input/mod.rs189
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/mod.rs10
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/neorg/handle.rs66
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/neorg/mod.rs21
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/open/handle.rs293
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/open/mod.rs240
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/project/handle.rs22
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/project/mod.rs10
-rw-r--r--pkgs/by-name/ts/tskm/src/main.rs68
-rw-r--r--pkgs/by-name/ts/tskm/src/rofi/mod.rs10
-rw-r--r--pkgs/by-name/ts/tskm/src/state.rs53
-rw-r--r--pkgs/by-name/ts/tskm/src/task/mod.rs209
15 files changed, 1310 insertions, 524 deletions
diff --git a/pkgs/by-name/ts/tskm/src/browser/mod.rs b/pkgs/by-name/ts/tskm/src/browser/mod.rs
new file mode 100644
index 00000000..fd90b820
--- /dev/null
+++ b/pkgs/by-name/ts/tskm/src/browser/mod.rs
@@ -0,0 +1,217 @@
+use std::{
+ env, fs,
+ io::Write,
+ os::unix::net::UnixStream,
+ path::PathBuf,
+ process::{self, ExitStatus},
+};
+
+use anyhow::{Context, Result};
+use log::{error, info};
+use serde_json::json;
+use url::Url;
+
+use crate::{state::State, task};
+
+#[allow(clippy::too_many_lines)]
+pub async fn open_in_browser<U>(
+ selected_project: &task::Project,
+ state: &mut State,
+ urls: Option<Vec<U>>,
+) -> Result<()>
+where
+ U: Into<Url>,
+{
+ let old_project: Option<task::Project> =
+ task::Project::get_current().context("Failed to get currently active project")?;
+ let old_task: Option<task::Task> = task::Task::get_current(state)
+ .await
+ .context("Failed to get currently active task")?;
+
+ selected_project.activate().with_context(|| {
+ format!(
+ "Failed to active project: '{}'",
+ selected_project.to_project_display()
+ )
+ })?;
+
+ let tracking_task = {
+ let all_tasks = selected_project.get_tasks(state).await.with_context(|| {
+ format!(
+ "Failed to get assoctiated tasks for project: '{}'",
+ selected_project.to_project_display()
+ )
+ })?;
+
+ let tracking_task = {
+ let mut output = None;
+
+ for t in all_tasks {
+ let maybe_desc = t.description(state).await;
+ let found = if let Ok(desc) = maybe_desc {
+ desc == "tracking"
+ } else {
+ error!(
+ "Getting task description returned error: {}",
+ maybe_desc.expect_err("We already check for Ok")
+ );
+ false
+ };
+
+ if found {
+ output = Some(t);
+ break;
+ }
+ }
+
+ output
+ };
+
+ if let Some(task) = tracking_task {
+ info!(
+ "Starting task {} -> tracking",
+ selected_project.to_project_display()
+ );
+ task.start(state)
+ .await
+ .with_context(|| format!("Failed to start task {task}"))?;
+ }
+ tracking_task
+ };
+
+ let status = {
+ // #!/bin/sh
+ // # initial idea: Florian Bruhin (The-Compiler)
+ // # author: Thore Bödecker (foxxx0)
+ //
+ // _url="$1"
+ // _qb_version='1.0.4'
+ // _proto_version=1
+ // _ipc_socket="${XDG_RUNTIME_DIR}/qutebrowser/ipc-$(printf '%s' "$USER" | md5sum | cut -d' ' -f1)"
+ // _qute_bin="/usr/bin/qutebrowser"
+ //
+ // printf '{"args": ["%s"], "target_arg": null, "version": "%s", "protocol_version": %d, "cwd": "%s"}\n' \
+ // "${_url}" \
+ // "${_qb_version}" \
+ // "${_proto_version}" \
+ // "${PWD}" | socat -lf /dev/null - UNIX-CONNECT:"${_ipc_socket}" || "$_qute_bin" "$@" &
+
+ let ipc_socket_path = PathBuf::from(
+ env::var("XDG_RUNTIME_DIR").context("Failed to access XDG_RUNTIME_DIR var")?,
+ )
+ .join("qutebrowser")
+ .join(selected_project.to_project_display())
+ .join(format!("ipc-{:x}", {
+ let user_name = env::var("USER").context("Failed to get USER var")?;
+ let base_dir = env::var("XDG_DATA_HOME").context("Failed to get XDG_DATA_HOME")?;
+
+ md5::compute(
+ format!(
+ "{user_name}-{}",
+ PathBuf::from(base_dir)
+ .join("qutebrowser")
+ .join(selected_project.to_project_display())
+ .display()
+ )
+ .as_bytes(),
+ )
+ }));
+
+ let socket = if ipc_socket_path.exists() {
+ match UnixStream::connect(&ipc_socket_path) {
+ Ok(ok) => Some(ok),
+ Err(err) => match err.kind() {
+ std::io::ErrorKind::ConnectionRefused => {
+ // There is no qutebrowser listening to our connection.
+ fs::remove_file(&ipc_socket_path).with_context(|| {
+ format!(
+ "Failed to remove orphaned qutebrowser socket: {}",
+ ipc_socket_path.display()
+ )
+ })?;
+ None
+ }
+ _ => Err(err).with_context(|| {
+ format!(
+ "Failed to connect to qutebrowser's ipc socket at: {}",
+ ipc_socket_path.display()
+ )
+ })?,
+ },
+ }
+ } else {
+ None
+ };
+
+ if let Some(mut stream) = socket {
+ let real_url = if let Some(urls) = urls {
+ urls.into_iter().map(|url| url.into().to_string()).collect()
+ } else {
+ // Always add a new tab, so that qutebrowser is marked as “urgent”.
+ vec!["qute://start".to_owned()]
+ };
+
+ stream.write_all(
+ json! {
+ {
+ "args": real_url,
+ "target_arg": null,
+ "version": "1.0.4",
+ "protocol_version": 1,
+ "cwd": "/"
+ }
+ }
+ .to_string()
+ .as_bytes(),
+ )?;
+ stream.write_all(b"\n")?;
+
+ ExitStatus::default()
+ } else {
+ let args = if let Some(urls) = urls {
+ urls.into_iter()
+ .map(Into::<Url>::into)
+ .map(|u| u.to_string())
+ .collect()
+ } else {
+ vec![]
+ };
+
+ process::Command::new(format!(
+ "qutebrowser-{}",
+ selected_project.to_project_display()
+ ))
+ .args(args)
+ .status()
+ .context("Failed to start qutebrowser")?
+ }
+ };
+
+ if !status.success() {
+ error!("Qutebrowser run exited with error.");
+ }
+
+ if let Some(task) = tracking_task {
+ task.stop(state)
+ .await
+ .with_context(|| format!("Failed to stop task {task}"))?;
+ }
+ if let Some(task) = old_task {
+ task.start(state)
+ .await
+ .with_context(|| format!("Failed to start task {task}"))?;
+ }
+
+ if let Some(project) = old_project {
+ project.activate().with_context(|| {
+ format!(
+ "Failed to activate project {}",
+ project.to_project_display()
+ )
+ })?;
+ } else {
+ task::Project::clear().context("Failed to clear currently focused project")?;
+ }
+
+ Ok(())
+}
diff --git a/pkgs/by-name/ts/tskm/src/cli.rs b/pkgs/by-name/ts/tskm/src/cli.rs
index 99c8693e..3dc1181d 100644
--- a/pkgs/by-name/ts/tskm/src/cli.rs
+++ b/pkgs/by-name/ts/tskm/src/cli.rs
@@ -1,26 +1,90 @@
-use std::path::PathBuf;
+// 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 clap::{Parser, Subcommand};
+use std::{ffi::OsStr, path::PathBuf, thread};
+
+use anyhow::{bail, Result};
+use clap::{builder::StyledStr, ArgAction, Parser, Subcommand, ValueEnum};
+use clap_complete::{ArgValueCompleter, CompletionCandidate};
+use tokio::runtime::Runtime;
use crate::{
- interface::{input::Input, project::ProjectName},
- task,
+ interface::{
+ input::{Input, Tag},
+ open::UrlLike,
+ project::ProjectName,
+ },
+ state, task,
};
+macro_rules! as_sync {
+ (
+ wrap $old_name_1:ident($($arg_name_1:ident : $arg_type_1:ty),*) -> $output_1:ty => $new_name_1:ident;
+ $(
+ wrap $old_name:ident($($arg_name:ident : $arg_type:ty),*) -> $output:ty => $new_name:ident;
+ )+
+ ) => {
+ as_sync!(
+ wrap $old_name_1($($arg_name_1 : $arg_type_1),*) -> $output_1 => $new_name_1;
+ );
+ as_sync!(
+ $(
+ wrap $old_name($($arg_name : $arg_type),*) -> $output => $new_name;
+ )+
+ );
+ };
+ (
+ wrap $old_name:ident($($arg_name:ident : $arg_type:ty),*) -> $output:ty => $new_name:ident $(;)?
+ ) => {
+ fn $new_name($($arg_name: $arg_type),*) -> $output {
+ $(
+ let $arg_name = $arg_name.to_owned();
+ ),*
+
+ let handle: std::thread::JoinHandle<$output> = thread::spawn(move || {
+ let rt = Runtime::new().expect("No runtime issue");
+
+ let output = rt.block_on($old_name($($arg_name.as_ref()),*));
+
+ output
+ });
+
+ handle.join().expect("The thread should be joinable")
+ }
+ };
+}
+
#[derive(Parser, Debug)]
#[command(author, version, about, long_about, verbatim_doc_comment)]
/// This is the core interface to the system-integrated task management
///
/// `tskm` effectively combines multiple applications together:
-/// - `taskwarrior` projects are raised connected to `firefox` profiles, making it possible to “open”
+/// - `taskwarrior` projects are connected to `qutebrowser` profiles, making it possible to “open”
/// a project.
+///
/// - Every `taskwarrior` project has a determined `neorg` path, so that extra information for a
/// `project` can be stored in this `norg` file.
+///
/// - `tskm` can track inputs for you. These are URLs with optional tags which you can that
/// “review” to open tasks based on them.
pub struct CliArgs {
#[command(subcommand)]
pub command: Command,
+
+ /// Increase message verbosity
+ #[arg(long="verbose", short = 'v', action = ArgAction::Count, default_value_t = 2)]
+ pub verbosity: u8,
+
+ /// Silence all output
+ #[arg(long, short = 'q')]
+ pub quiet: bool,
}
#[derive(Subcommand, Debug)]
@@ -43,7 +107,7 @@ pub enum Command {
command: NeorgCommand,
},
- /// Interface with the Firefox profile of each project.
+ /// Interface with the Qutebrowser profile of each project.
Open {
#[command(subcommand)]
command: OpenCommand,
@@ -66,57 +130,246 @@ pub enum ProjectCommand {
#[derive(Subcommand, Debug, Clone, Copy)]
pub enum NeorgCommand {
/// Open the `neorg` project associated with id of the task.
- Task { id: task::Id },
+ Task {
+ /// The working set id of the task
+ #[arg(value_name = "ID", value_parser = task_from_working_set_id_sync, add = ArgValueCompleter::new(complete_task_id_sync))]
+ task: task::Task,
+ },
+}
+
+as_sync!(
+ wrap task_from_working_set_id(id: &str) -> Result<task::Task> => task_from_working_set_id_sync;
+ wrap complete_task_id(current: &OsStr) -> Vec<CompletionCandidate> => complete_task_id_sync;
+);
+
+async fn task_from_working_set_id(id: &str) -> Result<task::Task> {
+ let id: usize = id.parse()?;
+ let mut state = state::State::new_ro().await?;
+
+ let Some(task) = task::Task::from_working_set(id, &mut state).await? else {
+ bail!("Working set id '{id}' is not valid!")
+ };
+ Ok(task)
}
#[derive(Subcommand, Debug)]
pub enum OpenCommand {
- /// Open each project's Firefox profile consecutively, that was opened since the last review.
+ /// Open each project's Qutebrowser profile consecutively, that was opened since the last review.
///
/// This allows you to remove stale opened tabs and to commit open tabs to the `inputs`.
- Review,
+ Review {
+ /// Review all projects, if they contain tabs
+ #[arg(short, long, default_value_t)]
+ non_empty: bool,
+ },
- /// Opens Firefox with either the supplied project or the currently active project profile.
+ /// Opens Qutebrowser with either the supplied project or the currently active project profile.
Project {
/// The project to open.
- #[arg(value_parser = task::Project::from_project_string)]
- project: Option<task::Project>,
+ #[arg(value_parser = task::Project::from_project_string, add = ArgValueCompleter::new(complete_project))]
+ project: task::Project,
+
+ /// The URLs to open.
+ urls: Option<Vec<UrlLike>>,
},
- /// Open a selected project in it's Firefox profile.
+ /// Open a selected project in it's Qutebrowser profile.
///
/// This will use rofi's dmenu mode to select one project from the list of all registered
/// projects.
- Select,
+ Select {
+ /// The URLs to open.
+ urls: Option<Vec<UrlLike>>,
+ },
/// List all open tabs in the project.
ListTabs {
- /// The project to open.
- #[arg(value_parser = task::Project::from_project_string)]
- project: Option<task::Project>,
+ /// The projects to open.
+ #[arg(value_parser = task::Project::from_project_string, add = ArgValueCompleter::new(complete_project))]
+ projects: Option<Vec<task::Project>>,
+
+ /// Only show the tabs, that are in this mode
+ #[arg(short, long, conflicts_with = "projects")]
+ mode: Option<ListMode>,
},
}
+#[derive(Clone, Copy, ValueEnum, Debug)]
+pub enum ListMode {
+ // The tab contains no tabs.
+ Empty,
+
+ // The tab contains tabs.
+ NonEmpty,
+}
+
#[derive(Subcommand, Debug)]
pub enum InputCommand {
/// Add URLs as inputs to be categorized.
Add { inputs: Vec<Input> },
/// Remove URLs
- Remove { inputs: Vec<Input> },
+ Remove {
+ #[arg(add = ArgValueCompleter::new(complete_input_url))]
+ inputs: Vec<Input>,
+ },
/// Add all URLs in the file as inputs to be categorized.
///
/// This expects each line to contain one URL.
- File { file: PathBuf },
+ File {
+ /// The file to read from.
+ file: PathBuf,
+
+ /// Additional tags to apply to every read URL in the file.
+ #[arg(add = ArgValueCompleter::new(complete_tag))]
+ tags: Vec<Tag>,
+ },
/// Like 'review', but for the inputs that have previously been added.
/// It takes a project in which to open the URLs.
Review {
/// Opens all the URLs in this project.
- #[arg(value_parser = task::Project::from_project_string)]
+ #[arg(value_parser = task::Project::from_project_string, add = ArgValueCompleter::new(complete_project))]
project: task::Project,
},
/// List all the previously added inputs.
- List,
+ List {
+ /// Only list the inputs that have all the specified tags
+ #[arg(add = ArgValueCompleter::new(complete_tag))]
+ tags: Vec<Tag>,
+ },
+
+ /// Show all the available tags.
+ Tags {},
+}
+
+async fn complete_task_id(current: &OsStr) -> Vec<CompletionCandidate> {
+ async fn format_task(
+ task: task::Task,
+ current: &str,
+ state: &mut state::State,
+ ) -> Option<CompletionCandidate> {
+ let id = {
+ let Ok(base) = task.working_set_id(state).await else {
+ return None;
+ };
+ base.to_string()
+ };
+
+ if !id.starts_with(current) {
+ return None;
+ }
+
+ let description = {
+ let Ok(base) = task.description(state).await else {
+ return None;
+ };
+ StyledStr::from(base)
+ };
+
+ Some(CompletionCandidate::new(id).help(Some(description)))
+ }
+
+ let mut output = vec![];
+
+ let Some(current) = current.to_str() else {
+ return output;
+ };
+
+ let Ok(mut state) = state::State::new_ro().await else {
+ return output;
+ };
+
+ let Ok(pending) = state.replica().pending_tasks().await else {
+ return output;
+ };
+
+ let Ok(current_project) = task::Project::get_current() else {
+ return output;
+ };
+
+ if let Some(current_project) = current_project {
+ for t in pending {
+ let task = task::Task::from(&t);
+ if let Ok(project) = task.project(&mut state).await {
+ if project == current_project {
+ if let Some(out) = format_task(task, current, &mut state).await {
+ output.push(out);
+ }
+ }
+ }
+ }
+ } else {
+ for t in pending {
+ let task = task::Task::from(&t);
+ if let Some(out) = format_task(task, current, &mut state).await {
+ output.push(out);
+ }
+ }
+ }
+
+ output
+}
+fn complete_project(current: &OsStr) -> Vec<CompletionCandidate> {
+ let mut output = vec![];
+
+ let Some(current) = current.to_str() else {
+ return output;
+ };
+
+ let Ok(all) = task::Project::all() else {
+ return output;
+ };
+
+ for a in all {
+ if a.to_project_display().starts_with(current) {
+ output.push(CompletionCandidate::new(a.to_project_display()));
+ }
+ }
+
+ output
+}
+fn complete_input_url(current: &OsStr) -> Vec<CompletionCandidate> {
+ let mut output = vec![];
+
+ let Some(current) = current.to_str() else {
+ return output;
+ };
+
+ let Ok(all) = Input::all() else {
+ return output;
+ };
+
+ for a in all {
+ if a.to_string().starts_with(current) {
+ output.push(CompletionCandidate::new(a.to_string()));
+ }
+ }
+
+ output
+}
+fn complete_tag(current: &OsStr) -> Vec<CompletionCandidate> {
+ let mut output = vec![];
+
+ let Some(current) = current.to_str() else {
+ return output;
+ };
+
+ if !current.starts_with('+') {
+ output.push(CompletionCandidate::new(format!("+{current}")));
+ }
+
+ output
+}
+
+#[cfg(test)]
+mod test {
+ use clap::CommandFactory;
+
+ use super::CliArgs;
+ #[test]
+ fn verify_cli() {
+ CliArgs::command().debug_assert();
+ }
}
diff --git a/pkgs/by-name/ts/tskm/src/interface/input/handle.rs b/pkgs/by-name/ts/tskm/src/interface/input/handle.rs
index 0ff0e56e..cd868f7a 100644
--- a/pkgs/by-name/ts/tskm/src/interface/input/handle.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/input/handle.rs
@@ -1,23 +1,34 @@
+// 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::{
- fs, process,
+ collections::{HashMap, HashSet},
+ fs,
str::FromStr,
- thread::{self, sleep},
- time::Duration,
};
use anyhow::{Context, Result};
-use log::{error, info};
+use log::info;
+use taskchampion::chrono::Utc;
-use crate::cli::InputCommand;
+use crate::{browser::open_in_browser, cli::InputCommand, state::State};
-use super::Input;
+use super::{Input, Tag};
/// # Errors
/// When command handling fails.
///
/// # Panics
/// When internal assertions fail.
-pub fn handle(command: InputCommand) -> Result<()> {
+#[allow(clippy::too_many_lines)]
+pub async fn handle(command: InputCommand, state: &mut State) -> Result<()> {
match command {
InputCommand::Add { inputs } => {
for input in inputs {
@@ -33,47 +44,43 @@ pub fn handle(command: InputCommand) -> Result<()> {
})?;
}
}
- InputCommand::File { file } => {
- let file = fs::read_to_string(file)?;
- for line in file.lines() {
- let input = Input::from_str(line)?;
+ InputCommand::File { file, tags } => {
+ let file = fs::read_to_string(&file)
+ .with_context(|| format!("Failed to read input file '{}'", file.display()))?;
+
+ let mut tag_set = HashSet::with_capacity(tags.len());
+ for tag in tags {
+ tag_set.insert(tag);
+ }
+
+ tag_set.insert(
+ Tag::new(format!("+{}", Utc::now().format("%Y-%m-%d")).as_str())
+ .expect("hardcoded"),
+ );
+
+ for line in file.lines().map(str::trim) {
+ if line.is_empty() {
+ continue;
+ }
+
+ let mut input = Input::from_str(line)?;
+ input.tags = input.tags.union(&tag_set).cloned().collect();
+
input.commit().with_context(|| {
format!("Failed to add input ('{input}') to the input storage.")
})?;
}
}
InputCommand::Review { project } => {
- let project = project.to_project_display();
-
- let local_project = project.clone();
- let handle = thread::spawn(move || {
- // We assume that the project is not yet open.
- let mut firefox = process::Command::new("firefox")
- .args(["-P", local_project.as_str(), "about:newtab"])
- .spawn()?;
-
- Ok::<_, anyhow::Error>(firefox.wait()?)
- });
- // Give Firefox some time to start.
- info!("Waiting on firefox to start");
- sleep(Duration::from_secs(4));
-
- let project_str = project.as_str();
'outer: for all in Input::all()?.chunks(100) {
info!("Starting review for the first hundred URLs.");
- for input in all {
- info!("-> '{input}'");
- let status = process::Command::new("firefox")
- .args(["-P", project_str, input.url().to_string().as_str()])
- .status()?;
-
- if status.success() {
- input.remove()?;
- } else {
- error!("Adding `{input}` to Firefox failed!");
- }
- }
+ open_in_browser(
+ &project,
+ state,
+ Some(all.iter().map(|f| f.url.clone()).collect()),
+ )
+ .await?;
{
use std::io::{stdin, stdout, Write};
@@ -98,15 +105,51 @@ pub fn handle(command: InputCommand) -> Result<()> {
}
}
}
-
- info!("Waiting for firefox to stop");
- handle.join().expect("Should be joinable")?;
}
- InputCommand::List => {
- for url in Input::all()? {
+ InputCommand::List { tags } => {
+ let mut tag_set = HashSet::with_capacity(tags.len());
+ for tag in tags {
+ tag_set.insert(tag);
+ }
+
+ for url in Input::all()?
+ .iter()
+ .filter(|input| tag_set.is_subset(&input.tags))
+ {
println!("{url}");
}
}
+ InputCommand::Tags {} => {
+ let mut without_tags = 0;
+ let mut tag_set: HashMap<Tag, u64> = HashMap::new();
+
+ for input in Input::all()? {
+ if input.tags.is_empty() {
+ without_tags += 1;
+ }
+
+ for tag in input.tags {
+ if let Some(number) = tag_set.get_mut(&tag) {
+ *number += 1;
+ } else {
+ tag_set.insert(tag, 1);
+ }
+ }
+ }
+
+ let mut tags: Vec<(Tag, u64)> = tag_set.into_iter().collect();
+ tags.sort_by_key(|(_, number)| *number);
+ tags.reverse();
+
+ for (tag, number) in tags {
+ println!("{tag} {number}");
+ }
+
+ if without_tags != 0 {
+ println!();
+ println!("Witohut tags: {without_tags}");
+ }
+ }
}
Ok(())
}
diff --git a/pkgs/by-name/ts/tskm/src/interface/input/mod.rs b/pkgs/by-name/ts/tskm/src/interface/input/mod.rs
index 9ece7a3a..b6176a96 100644
--- a/pkgs/by-name/ts/tskm/src/interface/input/mod.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/input/mod.rs
@@ -1,14 +1,24 @@
+// 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::{
- collections::HashSet,
+ collections::{HashMap, HashSet},
fmt::Display,
- fs::{self, read_to_string, File},
+ fs,
io::Write,
path::PathBuf,
process::Command,
str::FromStr,
};
-use anyhow::{bail, Context, Result};
+use anyhow::{Context, Result, bail};
use url::Url;
use walkdir::WalkDir;
@@ -16,38 +26,47 @@ pub mod handle;
pub use handle::handle;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
-pub struct NoWhitespaceString(String);
+pub struct Tag(String);
-impl NoWhitespaceString {
- /// # Panics
- /// If the input contains whitespace.
- #[must_use]
- pub fn new(input: String) -> Self {
- if input.contains(' ') {
- panic!("Your input '{input}' contains whitespace. I did not expect that.")
+impl Tag {
+ pub fn new(input: &str) -> Result<Self> {
+ Self::from_str(input)
+ }
+}
+
+impl FromStr for Tag {
+ type Err = anyhow::Error;
+
+ fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
+ if let Some(tag) = s.strip_prefix('+') {
+ if tag.contains(' ') {
+ bail!("Your tag '{s}' should not whitespace.")
+ }
+
+ Ok(Self(tag.to_owned()))
} else {
- Self(input)
+ bail!("Your tag '{s}' does not start with the required '+'");
}
}
}
-impl Display for NoWhitespaceString {
+impl Display for Tag {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- self.0.fmt(f)
+ write!(f, "+{}", self.0)
}
}
-impl NoWhitespaceString {
+impl Tag {
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
}
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Input {
url: Url,
- tags: HashSet<NoWhitespaceString>,
+ tags: HashSet<Tag>,
}
impl FromStr for Input {
@@ -61,13 +80,7 @@ impl FromStr for Input {
tags: {
tags.trim()
.split(' ')
- .map(|tag| {
- if let Some(tag) = tag.strip_prefix('+') {
- Ok(NoWhitespaceString::new(tag.to_owned()))
- } else {
- bail!("Your tag '{tag}' does not start with the required '+'");
- }
- })
+ .map(Tag::new)
.collect::<Result<_, _>>()?
},
})
@@ -91,13 +104,9 @@ impl Display for Input {
self.url,
self.tags
.iter()
- .fold(String::new(), |mut acc, tag| {
- acc.push('+');
- acc.push_str(tag.as_str());
- acc.push(' ');
- acc
- })
- .trim()
+ .map(ToString::to_string)
+ .collect::<Vec<_>>()
+ .join(" ")
)
}
}
@@ -113,7 +122,10 @@ impl Input {
fn url_path(url: &Url) -> Result<PathBuf> {
let base_path = Self::base_path();
- let url_path = base_path.join(url.to_string());
+ let url_path = base_path
+ .join(url.scheme())
+ .join(url.host_str().unwrap_or("<No Host>"))
+ .join(url.path().trim_matches('/'));
fs::create_dir_all(&url_path)
.with_context(|| format!("Failed to open file: '{}'", url_path.display()))?;
@@ -132,17 +144,12 @@ impl Input {
pub fn commit(&self) -> Result<()> {
let url_path = Self::url_path(&self.url)?;
- let url_content = {
- if url_path.exists() {
- read_to_string(&url_path)?
- } else {
- String::new()
- }
- };
-
- let mut file = File::create(&url_path)
+ let mut file = fs::OpenOptions::new()
+ .create(true)
+ .append(true)
+ .open(&url_path)
.with_context(|| format!("Failed to open file: '{}'", url_path.display()))?;
- writeln!(file, "{url_content}{self}")?;
+ writeln!(file, "{self}")?;
Self::git_commit(&format!("Add new url: '{self}'"))?;
@@ -173,28 +180,7 @@ impl Input {
Ok(())
}
- /// Commit your changes
- fn git_commit(message: &str) -> Result<()> {
- let status = Command::new("git")
- .args(["add", "."])
- .current_dir(Self::base_path())
- .status()?;
- if !status.success() {
- bail!("Git add . failed!");
- }
-
- let status = Command::new("git")
- .args(["commit", "--message", message, "--no-gpg-sign"])
- .current_dir(Self::base_path())
- .status()?;
- if !status.success() {
- bail!("Git commit failed!");
- }
-
- Ok(())
- }
-
- /// Get all previously [`Self::commit`]ed inputs.
+ /// Get all previously [committed][`Self::commit`] inputs.
///
/// # Errors
/// When IO handling fails.
@@ -217,41 +203,58 @@ impl Input {
continue;
}
- let url_value_file = entry
- .path()
- .to_str()
- .expect("All of these should be URLs and thus valid strings");
- assert!(url_value_file.ends_with("/url_value"));
+ let url_value_file = entry.path();
+ assert!(url_value_file.ends_with("url_value"));
- let url = {
- let base = url_value_file
- .strip_prefix(&format!("{}/", Self::base_path().display()))
- .expect("This will exist");
+ let url_values = fs::read_to_string(PathBuf::from(url_value_file))?;
- let (proto, path) = base.split_once(':').expect("This will countain a :");
+ let mut inputs: HashMap<Url, Self> = HashMap::new();
+ for input in url_values
+ .lines()
+ .map(Self::from_str)
+ .collect::<Result<Vec<Self>, _>>()?
+ {
+ if let Some(found) = inputs.get_mut(&input.url) {
+ found.tags = found.tags.union(&input.tags).cloned().collect();
+ } else {
+ assert_eq!(inputs.insert(input.url.clone(), input), None);
+ }
+ }
- let path = path.strip_suffix("/url_value").expect("Will exist");
+ output.extend(inputs.drain().map(|(_, value)| value));
+ }
- Url::from_str(&format!("{proto}:/{path}"))
- .expect("This was a URL, it should still be one")
- };
- let tags = {
- let url_values = read_to_string(PathBuf::from(url_value_file))?;
- url_values
- .lines()
- .map(|line| {
- let input = Self::from_str(line)?;
- Ok::<_, anyhow::Error>(input.tags)
- })
- .collect::<Result<Vec<HashSet<NoWhitespaceString>>, _>>()?
- .into_iter()
- .flatten()
- .collect()
- };
+ Ok(output)
+ }
- output.push(Self { url, tags });
+ /// Commit your changes
+ fn git_commit(message: &str) -> Result<()> {
+ if !Self::base_path().join(".git").exists() {
+ let status = Command::new("git")
+ .args(["init"])
+ .current_dir(Self::base_path())
+ .status()?;
+ if !status.success() {
+ bail!("Git init failed!");
+ }
}
- Ok(output)
+ let status = Command::new("git")
+ .args(["add", "."])
+ .current_dir(Self::base_path())
+ .status()?;
+ if !status.success() {
+ bail!("Git add . failed!");
+ }
+
+ let status = Command::new("git")
+ .args(["commit", "--message", message, "--no-gpg-sign"])
+ .current_dir(Self::base_path())
+ .status()?;
+ if !status.success() {
+ bail!("Git commit failed!");
+ }
+
+ Ok(())
}
}
diff --git a/pkgs/by-name/ts/tskm/src/interface/mod.rs b/pkgs/by-name/ts/tskm/src/interface/mod.rs
index 1a0d934c..513ca317 100644
--- a/pkgs/by-name/ts/tskm/src/interface/mod.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/mod.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>.
+
pub mod input;
pub mod neorg;
pub mod open;
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 a9a46ee7..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,33 +1,59 @@
+// 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, OpenOptions},
+ fs::{self, read_to_string, File, OpenOptions},
io::Write,
process::Command,
};
-use anyhow::{bail, Result};
+use anyhow::{bail, Context, Result};
-use crate::cli::NeorgCommand;
+use crate::{cli::NeorgCommand, state::State};
-pub fn handle(command: NeorgCommand) -> Result<()> {
+pub async fn handle(command: NeorgCommand, state: &mut State) -> Result<()> {
match command {
- NeorgCommand::Task { id } => {
- let project = id.project()?;
- 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("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"))?;
{
- let contents = read_to_string(&path)?;
- if contents.contains(format!("% {}", id.to_uuid()?).as_str()) {
+ let contents = if path.exists() {
+ read_to_string(&path)
+ .with_context(|| format!("Failed to read file: '{}'", path.display()))?
+ } else {
+ File::create(&path)
+ .with_context(|| format!("Failed to create file: '{}'", path.display()))?;
+ String::new()
+ };
+
+ if !contents.contains(format!("% {}", task.uuid()).as_str()) {
let mut options = OpenOptions::new();
- options.append(true).create(true);
+ options.append(true).create(false);
let mut file = options.open(&path)?;
- file.write_all(format!("* TITLE (% {})", id.to_uuid()?).as_bytes())?;
+ 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()))?;
}
}
@@ -36,7 +62,7 @@ pub fn handle(command: NeorgCommand) -> Result<()> {
.args([
path.to_str().expect("Should be a utf-8 str"),
"-c",
- format!("/% {}", id.to_uuid()?).as_str(),
+ format!("/% {}", task.uuid()).as_str(),
])
.status()?;
if !status.success() {
@@ -46,7 +72,7 @@ pub fn handle(command: NeorgCommand) -> Result<()> {
{
let status = Command::new("git")
.args(["add", "."])
- .current_dir(&path)
+ .current_dir(path.parent().expect("Will exist"))
.status()?;
if !status.success() {
bail!("Git add . failed!");
@@ -56,14 +82,10 @@ pub fn handle(command: NeorgCommand) -> 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)
+ .current_dir(path.parent().expect("Will exist"))
.status()?;
if !status.success() {
bail!("Git commit failed!");
@@ -71,7 +93,7 @@ pub fn handle(command: NeorgCommand) -> Result<()> {
}
{
- id.annotate("[neorg data]")?;
+ 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))
}
}
diff --git a/pkgs/by-name/ts/tskm/src/interface/open/handle.rs b/pkgs/by-name/ts/tskm/src/interface/open/handle.rs
index dc0d165d..5b9100bc 100644
--- a/pkgs/by-name/ts/tskm/src/interface/open/handle.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/open/handle.rs
@@ -1,48 +1,77 @@
-use std::process;
+// 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::str::FromStr;
use anyhow::{bail, Context, Result};
use log::{error, info};
+use url::Url;
+
+use crate::{browser::open_in_browser, cli::OpenCommand, rofi, state::State, task};
+
+fn is_empty(project: &task::Project) -> Result<bool> {
+ let tabs = get_tabs(project)?;
-use crate::{cli::OpenCommand, rofi, task};
+ if tabs.is_empty() {
+ Ok(true)
+ } else if tabs.len() > 1 {
+ Ok(false)
+ } else {
+ let url = &tabs[0].1;
-pub fn handle(command: OpenCommand) -> Result<()> {
+ Ok(url == &Url::from_str("qute://start/").expect("Hardcoded"))
+ }
+}
+
+#[allow(clippy::too_many_lines)]
+pub async fn handle(command: OpenCommand, state: &mut State) -> Result<()> {
match command {
- OpenCommand::Review => {
+ OpenCommand::Review { non_empty } => {
for project in task::Project::all().context("Failed to get all project files")? {
- if project.is_touched() {
- info!("Reviewing project: '{}'", project.to_project_display());
- open_in_browser(project).with_context(|| {
- format!(
- "Failed to open project ('{}') in Firefox",
- project.to_project_display()
- )
- })?;
- project.untouch().with_context(|| {
- format!(
- "Failed to untouch project ('{}')",
- project.to_project_display()
- )
- })?;
+ let is_empty = is_empty(project)?;
+
+ if project.is_touched() || (non_empty && !is_empty) {
+ info!(
+ "Reviewing project: '{}' ({})",
+ project.to_project_display(),
+ if is_empty { "is empty" } else { "is not empty" }
+ );
+ open_in_browser(project, state, None::<Vec<Url>>)
+ .await
+ .with_context(|| {
+ format!(
+ "Failed to open project ('{}') in qutebrowser",
+ project.to_project_display()
+ )
+ })?;
+
+ if project.is_touched() {
+ project.untouch().with_context(|| {
+ format!(
+ "Failed to untouch project ('{}')",
+ project.to_project_display()
+ )
+ })?;
+ }
}
}
}
- OpenCommand::Project { project } => {
- let project = if let Some(p) = project {
- p
- } else if let Some(p) =
- task::Project::get_current().context("Failed to get currently focused project")?
- {
- p
- } else {
- bail!("You need to either supply a project or have a project active!");
- };
-
+ OpenCommand::Project { project, urls } => {
project.touch().context("Failed to touch project")?;
- open_in_browser(&project).with_context(|| {
- format!("Failed to open project: {}", project.to_project_display())
- })?;
+ open_in_browser(&project, state, urls)
+ .await
+ .with_context(|| {
+ format!("Failed to open project: {}", project.to_project_display())
+ })?;
}
- OpenCommand::Select => {
+ OpenCommand::Select { urls } => {
let selected_project: task::Project = task::Project::from_project_string(
&rofi::select(
task::Project::all()
@@ -60,130 +89,108 @@ pub fn handle(command: OpenCommand) -> Result<()> {
.touch()
.context("Failed to touch project")?;
- open_in_browser(&selected_project).context("Failed to open project")?;
+ open_in_browser(&selected_project, state, urls)
+ .await
+ .context("Failed to open project")?;
}
- OpenCommand::ListTabs { project } => {
- let project = if let Some(p) = project {
- p
- } else if let Some(p) =
- task::Project::get_current().context("Failed to get currently focused project")?
- {
- p
- } else {
- bail!("You need to either supply a project or have a project active!");
+ OpenCommand::ListTabs { projects, mode } => {
+ let projects = {
+ if let Some(p) = projects {
+ p
+ } else if mode.is_some() {
+ task::Project::all()
+ .context("Failed to get all projects")?
+ .to_owned()
+ } else if let Some(p) = task::Project::get_current()
+ .context("Failed to get currently focused project")?
+ {
+ vec![p]
+ } else {
+ bail!("You need to either select projects or pass --mode");
+ }
};
- let session_store = project.get_sessionstore().with_context(|| {
- format!(
- "Failed to get session store for project: '{}'",
- project.to_project_display()
- )
- })?;
+ for project in &projects {
+ if let Some(mode) = mode {
+ match mode {
+ crate::cli::ListMode::Empty => {
+ if !is_empty(project)? {
+ continue;
+ }
- let selected = session_store
- .windows
- .iter()
- .map(|w| w.selected)
- .collect::<Vec<_>>();
+ // We do not need to print, tabs they are always empty.
+ if projects.len() > 1 {
+ println!("/* {} */", project.to_project_display());
+ }
+ continue;
+ }
+ crate::cli::ListMode::NonEmpty => {
+ if is_empty(project)? {
+ continue;
+ }
+ }
+ }
+ }
- let tabs = session_store
- .windows
- .iter()
- .flat_map(|window| window.tabs.iter())
- .map(|tab| tab.entries.get(tab.index - 1).expect("This should be Some"))
- .collect::<Vec<_>>();
+ if projects.len() > 1 {
+ println!("/* {} */", project.to_project_display());
+ }
+
+ let tabs = match get_tabs(project) {
+ Ok(ok) => ok,
+ Err(err) => {
+ if projects.len() > 1 {
+ error!(
+ "While trying to get the sessionstore for {}: {:?}",
+ project.to_project_display(),
+ err
+ );
+ continue;
+ }
- for (index, entry) in tabs.iter().enumerate() {
- let index = index + 1;
- let is_selected = {
- if selected.contains(&index) {
- "🔻 "
- } else {
- " "
+ return Err(err).with_context(|| {
+ format!(
+ "While trying to get the sessionstore for {}",
+ project.to_project_display()
+ )
+ });
}
};
- println!("{}{}", is_selected, entry.url);
+
+ for (active, url) in tabs {
+ let is_selected = {
+ if active {
+ "🔻 "
+ } else {
+ " "
+ }
+ };
+ println!("{is_selected}{url}");
+ }
}
}
}
+
Ok(())
}
-fn open_in_browser(selected_project: &task::Project) -> Result<()> {
- let old_project: Option<task::Project> =
- task::Project::get_current().context("Failed to get currently active project")?;
- // We have ensured that only one task may be active
- let old_task: Option<task::Id> =
- task::Id::get_current().context("Failed to get currently active task")?;
-
- selected_project.activate().with_context(|| {
- format!(
- "Failed to active project: '{}'",
- selected_project.to_project_display()
- )
- })?;
-
- let tracking_task = {
- let all_tasks = selected_project.get_tasks().with_context(|| {
- format!(
- "Failed to get assoctiated tasks for project: '{}'",
- selected_project.to_project_display()
- )
- })?;
-
- let tracking_task = all_tasks.into_iter().find(|t| {
- let maybe_desc = t.description();
- if let Ok(desc) = maybe_desc {
- desc == "tracking"
- } else {
- error!(
- "Getting task description returned error: {}",
- maybe_desc.expect_err("We already check for Ok")
- );
- false
- }
- });
-
- if let Some(task) = tracking_task {
- info!(
- "Starting task {} -> tracking",
- selected_project.to_project_display()
- );
- task.start()
- .with_context(|| format!("Failed to start task {task}"))?;
- }
- tracking_task
- };
-
- let status = process::Command::new("firefox")
- .args([
- "-P",
- selected_project.to_project_display().as_str(),
- "about:newtab",
- ])
- .status()
- .context("Failed to start firefox")?;
-
- if !status.success() {
- error!("Firefox run exited with error.");
- }
-
- if let Some(task) = tracking_task {
- task.stop()
- .with_context(|| format!("Failed to stop task {task}"))?;
- }
- if let Some(task) = old_task {
- task.start()
- .with_context(|| format!("Failed to start task {task}"))?;
- }
+fn get_tabs(project: &task::Project) -> Result<Vec<(bool, Url)>> {
+ let session_store = project.get_sessionstore()?;
- if let Some(project) = old_project {
- project.activate().with_context(|| {
- format!("Failed to active project {}", project.to_project_display())
- })?;
- } else {
- task::Project::clear().context("Failed to clear currently focused project")?;
- }
+ let tabs = session_store
+ .windows
+ .iter()
+ .flat_map(|window| window.tabs.iter())
+ .filter_map(|tab| {
+ tab.history
+ .iter()
+ .find(|hist| hist.active)
+ .map(|hist| (tab.active, hist))
+ })
+ .collect::<Vec<_>>();
- Ok(())
+ Ok(tabs
+ .into_iter()
+ .map(|(active, hist)| (active, hist.url.clone()))
+ .collect())
}
diff --git a/pkgs/by-name/ts/tskm/src/interface/open/mod.rs b/pkgs/by-name/ts/tskm/src/interface/open/mod.rs
index 2dc75957..407536d2 100644
--- a/pkgs/by-name/ts/tskm/src/interface/open/mod.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/open/mod.rs
@@ -1,106 +1,198 @@
-use std::{collections::HashMap, fs::File, io};
+// 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 anyhow::{Context, Result};
-use lz4_flex::decompress_size_prepended;
-use serde::Deserialize;
-use serde_json::Value;
+use std::{
+ fs::{self, File},
+ io::Read,
+ str::FromStr,
+};
+
+use anyhow::{Context, Result, anyhow};
+use taskchampion::chrono::NaiveDateTime;
use url::Url;
+use yaml_rust2::Yaml;
use crate::task::Project;
pub mod handle;
pub use handle::handle;
+/// An Url that also accepts file paths
+#[derive(Debug, Clone)]
+pub struct UrlLike(Url);
+
+impl FromStr for UrlLike {
+ type Err = url::ParseError;
+
+ fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
+ if let Ok(u) = fs::canonicalize(s) {
+ Ok(Self(Url::from_file_path(u).expect(
+ "The path could be canonicalized, as such it is valid for this",
+ )))
+ } else {
+ Url::from_str(s).map(Self)
+ }
+ }
+}
+
+impl From<UrlLike> for Url {
+ fn from(value: UrlLike) -> Self {
+ value.0
+ }
+}
+
impl Project {
pub(super) fn get_sessionstore(&self) -> Result<SessionStore> {
- let path = dirs::home_dir()
- .expect("Will exist")
- .join(".mozilla/firefox")
+ let path = dirs::data_local_dir()
+ .context("Failed to get data dir")?
+ .join("qutebrowser")
.join(self.to_project_display())
- .join("sessionstore-backups/recovery.jsonlz4");
- let file = decompress_mozlz4(
- File::open(&path)
- .with_context(|| format!("Failed to open path '{}'", path.display()))?,
- )
- .with_context(|| format!("Failed to decompress file as mozlzh '{}'", path.display()))?;
+ .join("data/sessions/default.yml");
- let contents: SessionStore = serde_json::from_str(&file).with_context(|| {
- format!(
- "Failed to deserialize file ('{}') as session store.",
- path.display()
- )
- })?;
- Ok(contents)
+ let mut file = File::open(&path)
+ .with_context(|| format!("Failed to open path '{}'", path.display()))?;
+
+ let mut yaml_str = String::new();
+ file.read_to_string(&mut yaml_str)
+ .context("Failed to read _autosave.yml path")?;
+ let yaml = yaml_rust2::YamlLoader::load_from_str(&yaml_str)?;
+
+ let store = qute_store_from_yaml(&yaml).context("Failed to read yaml store")?;
+
+ Ok(store)
}
}
-fn decompress_mozlz4<P: io::Read>(mut file: P) -> Result<String> {
- const MOZLZ4_MAGIC_NUMBER: &[u8] = b"mozLz40\0";
+fn qute_store_from_yaml(yaml: &[Yaml]) -> Result<SessionStore> {
+ assert_eq!(yaml.len(), 1);
+ let doc = &yaml[0];
- let mut buf = [0u8; 8];
- file.read_exact(&mut buf)
- .context("Failed to read the mozlz40 header.")?;
+ let hash = doc.as_hash().context("Invalid yaml")?;
+ let windows = hash
+ .get(&Yaml::String("windows".to_owned()))
+ .ok_or(anyhow!("Missing windows"))?
+ .as_vec()
+ .ok_or(anyhow!("Windows not vector"))?;
- assert_eq!(buf, MOZLZ4_MAGIC_NUMBER);
+ Ok(SessionStore {
+ windows: windows
+ .iter()
+ .map(|window| {
+ let hash = window.as_hash().ok_or(anyhow!("Windows not hashmap"))?;
- let mut buf = vec![];
- file.read_to_end(&mut buf).context("Failed to read file")?;
+ Ok::<_, anyhow::Error>(Window {
+ geometry: hash
+ .get(&Yaml::String("geometry".to_owned()))
+ .ok_or(anyhow!("Missing window geometry"))?
+ .as_str()
+ .ok_or(anyhow!("geometry not string"))?
+ .to_owned(),
+ tabs: hash
+ .get(&Yaml::String("tabs".to_owned()))
+ .ok_or(anyhow!("Missing window tabs"))?
+ .as_vec()
+ .ok_or(anyhow!("Tabs not vec"))?
+ .iter()
+ .map(|tab| {
+ let hash = tab.as_hash().ok_or(anyhow!("Tab not hashmap"))?;
- let uncompressed = decompress_size_prepended(&buf).context("Failed to decompress file")?;
+ Ok::<_, anyhow::Error>(Tab {
+ history: hash
+ .get(&Yaml::String("history".to_owned()))
+ .ok_or(anyhow!("Missing tab history"))?
+ .as_vec()
+ .ok_or(anyhow!("tab history not vec"))?
+ .iter()
+ .map(|history| {
+ let hash = history
+ .as_hash()
+ .ok_or(anyhow!("Tab history not hashmap"))?;
- Ok(String::from_utf8(uncompressed).expect("This should be valid json and thus utf8"))
+ Ok::<_, anyhow::Error>(TabHistory {
+ active: hash
+ .get(&Yaml::String("active".to_owned()))
+ .unwrap_or(&Yaml::Boolean(false))
+ .as_bool()
+ .ok_or(anyhow!("tab history active not bool"))?,
+ last_visited: NaiveDateTime::from_str(
+ hash.get(&Yaml::String("last_visited".to_owned()))
+ .ok_or(anyhow!(
+ "Missing tab history last_visited"
+ ))?
+ .as_str()
+ .ok_or(anyhow!(
+ "tab history last_visited not string"
+ ))?,
+ )
+ .context("Failed to parse last_visited")?,
+ pinned: hash
+ .get(&Yaml::String("pinned".to_owned()))
+ .ok_or(anyhow!("Missing tab history pinned"))?
+ .as_bool()
+ .ok_or(anyhow!("tab history pinned not bool"))?,
+ title: hash
+ .get(&Yaml::String("title".to_owned()))
+ .ok_or(anyhow!("Missing tab history title"))?
+ .as_str()
+ .ok_or(anyhow!("tab history title not string"))?
+ .to_owned(),
+ url: Url::parse(
+ hash.get(&Yaml::String("url".to_owned()))
+ .ok_or(anyhow!("Missing tab history url"))?
+ .as_str()
+ .ok_or(anyhow!("tab history url not string"))?,
+ )
+ .context("Failed to parse url")?,
+ zoom: hash
+ .get(&Yaml::String("zoom".to_owned()))
+ .unwrap_or(&Yaml::Real("1.0".to_owned()))
+ .as_f64()
+ .ok_or(anyhow!("tab history zoom not 64"))?,
+ })
+ })
+ .collect::<Result<Vec<_>, _>>()?,
+ active: hash
+ .get(&Yaml::String("active".to_owned()))
+ .unwrap_or(&Yaml::Boolean(false))
+ .as_bool()
+ .ok_or(anyhow!("active not bool"))?,
+ })
+ })
+ .collect::<Result<Vec<_>, _>>()?,
+ })
+ })
+ .collect::<Result<Vec<_>, _>>()?,
+ })
}
-#[derive(Deserialize, Debug)]
+#[derive(Debug)]
pub struct SessionStore {
pub windows: Vec<Window>,
}
-
-#[derive(Deserialize, Debug)]
+#[derive(Debug)]
pub struct Window {
+ pub geometry: String,
pub tabs: Vec<Tab>,
- pub selected: usize,
}
-
-#[derive(Deserialize, Debug)]
+#[derive(Debug)]
pub struct Tab {
- pub entries: Vec<TabEntry>,
- #[serde(rename = "lastAccessed")]
- pub last_accessed: u64,
- pub hidden: bool,
- #[serde(rename = "searchMode")]
- pub search_mode: Option<Value>,
- #[serde(rename = "userContextId")]
- pub user_context_id: u32,
- pub attributes: TabAttributes,
- #[serde(rename = "extData")]
- pub ext_data: Option<HashMap<String, Value>>,
- pub index: usize,
- #[serde(rename = "requestedIndex")]
- pub requested_index: Option<u32>,
- pub image: Option<Url>,
+ pub history: Vec<TabHistory>,
+ pub active: bool,
}
-
-#[derive(Deserialize, Debug)]
-pub struct TabEntry {
- pub url: Url,
+#[derive(Debug)]
+pub struct TabHistory {
+ pub active: bool,
+ pub last_visited: NaiveDateTime,
+ pub pinned: bool,
+ // pub scroll-pos:
pub title: String,
- #[serde(rename = "cacheKey")]
- pub cache_key: u32,
- #[serde(rename = "ID")]
- pub id: u32,
- #[serde(rename = "docshellUUID")]
- pub docshell_uuid: Value,
- #[serde(rename = "resultPrincipalURI")]
- pub result_principal_uri: Option<Url>,
- #[serde(rename = "hasUserInteraction")]
- pub has_user_interaction: bool,
- #[serde(rename = "triggeringPrincipal_base64")]
- pub triggering_principal_base64: Value,
- #[serde(rename = "docIdentifier")]
- pub doc_identifier: u32,
- pub persist: bool,
+ pub url: Url,
+ pub zoom: f64,
}
-
-#[derive(Deserialize, Debug, Clone, Copy)]
-pub struct TabAttributes {}
diff --git a/pkgs/by-name/ts/tskm/src/interface/project/handle.rs b/pkgs/by-name/ts/tskm/src/interface/project/handle.rs
index 2b01f5d1..6d44b340 100644
--- a/pkgs/by-name/ts/tskm/src/interface/project/handle.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/project/handle.rs
@@ -1,6 +1,16 @@
+// 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::File, io::Write};
-use anyhow::{anyhow, Context, Result};
+use anyhow::{Context, Result, anyhow};
use log::trace;
use crate::{cli::ProjectCommand, task};
@@ -60,10 +70,12 @@ pub fn handle(command: ProjectCommand) -> Result<()> {
let new_definition = ProjectDefinition::default();
- assert!(definition
- .subprojects
- .insert(segment.clone(), new_definition)
- .is_none());
+ assert!(
+ definition
+ .subprojects
+ .insert(segment.clone(), new_definition)
+ .is_none()
+ );
definition = definition
.subprojects
diff --git a/pkgs/by-name/ts/tskm/src/interface/project/mod.rs b/pkgs/by-name/ts/tskm/src/interface/project/mod.rs
index 62069746..8a7fa1b0 100644
--- a/pkgs/by-name/ts/tskm/src/interface/project/mod.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/project/mod.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::collections::HashMap;
use anyhow::Result;
diff --git a/pkgs/by-name/ts/tskm/src/main.rs b/pkgs/by-name/ts/tskm/src/main.rs
index 7fc9c0d4..a852bd7b 100644
--- a/pkgs/by-name/ts/tskm/src/main.rs
+++ b/pkgs/by-name/ts/tskm/src/main.rs
@@ -1,64 +1,50 @@
-#![allow(clippy::missing_panics_doc)]
-#![allow(clippy::missing_errors_doc)]
+// 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 anyhow::Result;
-use clap::Parser;
+use clap::{CommandFactory, Parser};
-use crate::interface::{input, neorg, open, project};
+use crate::{
+ cli::{CliArgs, Command},
+ interface::{input, neorg, open, project},
+ state::State,
+};
+pub mod browser;
pub mod cli;
pub mod interface;
pub mod rofi;
+pub mod state;
pub mod task;
-use crate::cli::{CliArgs, Command};
+#[tokio::main]
+async fn main() -> Result<(), anyhow::Error> {
+ clap_complete::CompleteEnv::with_factory(CliArgs::command).complete();
-fn main() -> Result<(), anyhow::Error> {
- // TODO: Support these completions for the respective types <2025-04-04>
- //
- // ID_GENERATION_FUNCTION
- // ```sh
- // context="$(task _get rc.context)"
- // if [ "$context" ]; then
- // filter="project:$context"
- // else
- // filter="0-10000"
- // fi
- // tasks="$(task "$filter" _ids)"
- //
- // if [ "$tasks" ]; then
- // echo "$tasks" | xargs task _zshids | awk -F: -v q="'" '{gsub(/'\''/, q "\\" q q ); print $1 ":" q $2 q}'
- // fi
- // ```
- //
- // ARGUMENTS:
- // ID | *([0-9]) := [[%ID_GENERATION_FUNCTION]]
- // The function displays all possible IDs of the eligible tasks.
- //
- // WS := %ALL_WORKSPACES
- // All possible workspaces.
- //
- // P := %ALL_PROJECTS_PIPE
- // The possible project.
- //
- // F := [[fd . --max-depth 3]]
- // A URL-Input file to use as source.
let args = CliArgs::parse();
stderrlog::new()
.module(module_path!())
- .quiet(false)
+ .quiet(args.quiet)
.show_module_names(true)
.color(stderrlog::ColorChoice::Auto)
- .verbosity(5)
- .timestamp(stderrlog::Timestamp::Off)
+ .verbosity(usize::from(args.verbosity))
.init()
.expect("Let's just hope that this does not panic");
+ let mut state = State::new_rw().await?;
+
match args.command {
- Command::Inputs { command } => input::handle(command)?,
- Command::Neorg { command } => neorg::handle(command)?,
- Command::Open { command } => open::handle(command)?,
+ Command::Inputs { command } => input::handle(command, &mut state).await?,
+ Command::Neorg { command } => neorg::handle(command, &mut state).await?,
+ Command::Open { command } => open::handle(command, &mut state).await?,
Command::Projects { command } => project::handle(command)?,
}
diff --git a/pkgs/by-name/ts/tskm/src/rofi/mod.rs b/pkgs/by-name/ts/tskm/src/rofi/mod.rs
index a0591b7f..37c2eafa 100644
--- a/pkgs/by-name/ts/tskm/src/rofi/mod.rs
+++ b/pkgs/by-name/ts/tskm/src/rofi/mod.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::{
io::Write,
process::{Command, Stdio},
diff --git a/pkgs/by-name/ts/tskm/src/state.rs b/pkgs/by-name/ts/tskm/src/state.rs
new file mode 100644
index 00000000..57495bb8
--- /dev/null
+++ b/pkgs/by-name/ts/tskm/src/state.rs
@@ -0,0 +1,53 @@
+// 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 taskchampion::{
+ storage::{sqlite::SqliteStorage, AccessMode},
+ Replica,
+};
+
+pub struct State {
+ replica: Replica<SqliteStorage>,
+}
+
+impl std::fmt::Debug for State {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "State")
+ }
+}
+
+impl State {
+ fn taskdb_dir() -> PathBuf {
+ dirs::data_local_dir().expect("Should exist").join("task")
+ }
+
+ async fn new(taskdb_dir: PathBuf, access_mode: AccessMode) -> Result<Self> {
+ let storage = SqliteStorage::new(taskdb_dir, access_mode, false).await?;
+
+ let replica = Replica::new(storage);
+
+ Ok(Self { replica })
+ }
+
+ pub async fn new_ro() -> Result<Self> {
+ Self::new(Self::taskdb_dir(), AccessMode::ReadOnly).await
+ }
+ pub async fn new_rw() -> Result<Self> {
+ Self::new(Self::taskdb_dir(), AccessMode::ReadWrite).await
+ }
+
+ #[must_use]
+ pub fn replica(&mut self) -> &mut Replica<SqliteStorage> {
+ &mut self.replica
+ }
+}
diff --git a/pkgs/by-name/ts/tskm/src/task/mod.rs b/pkgs/by-name/ts/tskm/src/task/mod.rs
index c3a6d614..1362615d 100644
--- a/pkgs/by-name/ts/tskm/src/task/mod.rs
+++ b/pkgs/by-name/ts/tskm/src/task/mod.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::{
fmt::Display,
fs::{self, read_to_string, File},
@@ -9,109 +19,148 @@ use std::{
use anyhow::{bail, Context, Result};
use log::{debug, info, trace};
+use taskchampion::Tag;
-use crate::interface::project::ProjectName;
+use crate::{interface::project::ProjectName, state::State};
/// The `taskwarrior` id of a task.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Ord, Eq)]
-pub struct Id {
- id: u64,
+pub struct Task {
+ uuid: taskchampion::Uuid,
}
-impl Id {
- /// # Errors
- /// When `task` execution fails
- pub fn get_current() -> Result<Option<Self>> {
- // We have ensured that only one task may be active
- let self_str = run_task(&["+ACTIVE", "_ids"])?;
- if self_str.is_empty() {
- Ok(None)
+impl From<&taskchampion::Task> for Task {
+ fn from(value: &taskchampion::Task) -> Self {
+ Self {
+ uuid: value.get_uuid(),
+ }
+ }
+}
+impl From<&taskchampion::TaskData> for Task {
+ fn from(value: &taskchampion::TaskData) -> Self {
+ Self {
+ uuid: value.get_uuid(),
+ }
+ }
+}
+
+impl Task {
+ pub async fn from_working_set(id: usize, state: &mut State) -> Result<Option<Self>> {
+ Ok(state
+ .replica()
+ .working_set()
+ .await?
+ .by_index(id)
+ .map(|uuid| Self { uuid }))
+ }
+
+ pub async fn get_current(state: &mut State) -> Result<Option<Self>> {
+ let tasks = state
+ .replica()
+ .pending_tasks()
+ .await?
+ .into_iter()
+ .filter(taskchampion::Task::is_active)
+ .collect::<Vec<_>>();
+
+ assert!(
+ tasks.len() <= 1,
+ "We have ensured that only one task may be active, via a hook"
+ );
+ if let Some(active) = tasks.first() {
+ Ok(Some(Self::from(active)))
} else {
- Self::from_str(&self_str).map(Some)
+ Ok(None)
}
}
- /// # Errors
- /// When `task` execution fails
- pub fn to_uuid(&self) -> Result<String> {
- let uuid = run_task(&[self.to_string().as_str(), "uuids"])?;
+ #[must_use]
+ pub fn uuid(&self) -> &taskchampion::Uuid {
+ &self.uuid
+ }
+ pub async fn working_set_id(&self, state: &mut State) -> Result<usize> {
+ Ok(state
+ .replica()
+ .working_set()
+ .await?
+ .by_uuid(self.uuid)
+ .expect("The task should be in the working set"))
+ }
- Ok(uuid)
+ async fn as_task(&self, state: &mut State) -> Result<taskchampion::Task> {
+ Ok(state
+ .replica()
+ .get_task(self.uuid)
+ .await?
+ .expect("We have the task from this replica, it should still be in it"))
}
- /// # Panics
- /// When internal assertions fail.
- /// # Errors
- /// When `task` execution fails
- pub fn annotate(&self, message: &str) -> Result<()> {
- run_task(&["annotate", self.to_string().as_str(), "--", message])?;
+ /// Adds a tag to the task, to show the user that it has additional neorg data.
+ pub async fn mark_neorg_data(&self, state: &mut State) -> Result<()> {
+ let mut ops = vec![];
+ self.as_task(state)
+ .await?
+ .add_tag(&Tag::from_str("neorg_data").expect("Is valid"), &mut ops)?;
+ state.replica().commit_operations(ops).await?;
Ok(())
}
- /// # Panics
- /// When internal assertions fail.
- /// # Errors
- /// When `task` execution fails
- pub fn start(&self) -> Result<()> {
+ /// Try to start this task.
+ /// It will stop previously active tasks.
+ pub async fn start(&self, state: &mut State) -> Result<()> {
info!("Activating {self}");
- let output = run_task(&["start", self.to_string().as_str()])?;
- assert!(output.is_empty());
+ if let Some(active) = Self::get_current(state).await? {
+ active.stop(state).await?;
+ }
+
+ let mut ops = vec![];
+ self.as_task(state).await?.start(&mut ops)?;
+ state.replica().commit_operations(ops).await?;
Ok(())
}
- /// # Panics
- /// When internal assertions fail.
- /// # Errors
- /// When `task` execution fails
- pub fn stop(&self) -> Result<()> {
+
+ /// Stops this task.
+ pub async fn stop(&self, state: &mut State) -> Result<()> {
info!("Stopping {self}");
- let output = run_task(&["stop", self.to_string().as_str()])?;
- assert!(output.is_empty());
+ let mut ops = vec![];
+ self.as_task(state).await?.stop(&mut ops)?;
+ state.replica().commit_operations(ops).await?;
Ok(())
}
- /// # Panics
- /// When internal assertions fail.
- /// # Errors
- /// When `task` execution fails
- pub fn description(&self) -> Result<String> {
- let output = run_task(&["rc.context=none", "_zshids", self.to_string().as_str()])?;
- let (id, desc) = output
- .split_once(':')
- .expect("The output should always contain one colon");
- assert_eq!(id.parse::<Id>().expect("This should be a valid id"), *self);
- Ok(desc.to_owned())
+ pub async fn description(&self, state: &mut State) -> Result<String> {
+ Ok(self.as_task(state).await?.get_description().to_owned())
}
- /// # Panics
- /// When internal assertions fail.
- /// # Errors
- /// When `task` execution fails
- pub fn project(&self) -> Result<Project> {
- let output = run_task(&[
- "rc.context=none",
- "_get",
- format!("{self}.project").as_str(),
- ])?;
- let project = Project::from_project_string(output.as_str())
+ pub async fn project(&self, state: &mut State) -> Result<Project> {
+ let output = {
+ let task = self.as_task(state).await?;
+ let task_data = task.into_task_data();
+ task_data
+ .get("project")
+ .expect("Every task should have a project")
+ .to_owned()
+ };
+ let project = Project::from_project_string(output.as_str().trim())
.expect("This comes from tw, it should be valid");
Ok(project)
}
}
-impl Display for Id {
+impl Display for Task {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- self.id.fmt(f)
+ self.uuid.fmt(f)
}
}
-impl FromStr for Id {
+impl FromStr for Task {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
- let id = u64::from_str(s)?;
- Ok(Self { id })
+ let uuid = taskchampion::Uuid::from_str(s)?;
+ Ok(Self { uuid })
}
}
@@ -259,21 +308,15 @@ impl Project {
/// # Errors
/// When `task` execution fails.
- pub fn get_tasks(&self) -> Result<Vec<Id>> {
- let output = run_task(&[
- "rc.context=none",
- format!("project:{}", self.to_project_display()).as_str(),
- "_ids",
- ])?;
-
- if output.is_empty() {
- Ok(vec![])
- } else {
- output
- .lines()
- .map(Id::from_str)
- .collect::<Result<Vec<Id>>>()
- }
+ pub async fn get_tasks(&self, state: &mut State) -> Result<Vec<Task>> {
+ Ok(state
+ .replica()
+ .pending_task_data()
+ .await?
+ .into_iter()
+ .filter(|t| t.get("project").expect("Is set") == self.to_project_display())
+ .map(|t| Task::from(&t))
+ .collect())
}
/// # Errors
@@ -318,5 +361,13 @@ pub(crate) fn run_task(args: &[&str]) -> Result<String> {
trace!("Output (stdout): '{}'", stdout.trim());
trace!("Output (stderr): '{}'", stderr.trim());
+ if !output.status.success() {
+ bail!(
+ "Command `task {}` failed with status: {}",
+ args.join(" "),
+ output.status
+ );
+ }
+
Ok(stdout.trim().to_owned())
}