about summary refs log tree commit diff stats
path: root/pkgs/by-name/ts/tskm/src
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/ts/tskm/src')
-rw-r--r--pkgs/by-name/ts/tskm/src/cli.rs190
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/input/handle.rs32
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/input/mod.rs179
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/mod.rs10
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/neorg/handle.rs26
-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.rs110
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/open/mod.rs10
-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.rs53
-rw-r--r--pkgs/by-name/ts/tskm/src/rofi/mod.rs10
-rw-r--r--pkgs/by-name/ts/tskm/src/state.rs12
-rw-r--r--pkgs/by-name/ts/tskm/src/task/mod.rs24
14 files changed, 513 insertions, 196 deletions
diff --git a/pkgs/by-name/ts/tskm/src/cli.rs b/pkgs/by-name/ts/tskm/src/cli.rs
index bd389ca5..ac8f8ee9 100644
--- a/pkgs/by-name/ts/tskm/src/cli.rs
+++ b/pkgs/by-name/ts/tskm/src/cli.rs
@@ -1,12 +1,26 @@
-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 std::{ffi::OsStr, path::PathBuf};
 
 use anyhow::{bail, Result};
-use clap::{ArgAction, Parser, Subcommand};
+use clap::{builder::StyledStr, ArgAction, Parser, Subcommand};
+use clap_complete::{ArgValueCompleter, CompletionCandidate};
+use url::Url;
 
 use crate::{
-    interface::{input::Input, project::ProjectName},
-    state::State,
-    task,
+    interface::{
+        input::{Input, Tag},
+        project::ProjectName,
+    },
+    state, task,
 };
 
 #[derive(Parser, Debug)]
@@ -16,8 +30,10 @@ use crate::{
 /// `tskm` effectively combines multiple applications together:
 /// - `taskwarrior` projects are raised connected to `firefox` 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 {
@@ -78,14 +94,14 @@ pub enum NeorgCommand {
     /// Open the `neorg` project associated with id of the task.
     Task {
         /// The working set id of the task
-        #[arg(value_parser = task_from_working_set_id)]
+        #[arg(value_parser = task_from_working_set_id, add = ArgValueCompleter::new(complete_task_id))]
         id: task::Task,
     },
 }
 
 fn task_from_working_set_id(id: &str) -> Result<task::Task> {
     let id: usize = id.parse()?;
-    let mut state = State::new_ro()?;
+    let mut state = state::State::new_ro()?;
 
     let Some(task) = task::Task::from_working_set(id, &mut state)? else {
         bail!("Working set id '{id}' is not valid!")
@@ -103,20 +119,26 @@ pub enum OpenCommand {
     /// Opens Firefox 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 URL to open.
+        url: Option<Url>,
     },
 
     /// Open a selected project in it's Firefox profile.
     ///
     /// This will use rofi's dmenu mode to select one project from the list of all registered
     /// projects.
-    Select,
+    Select {
+        /// The URL to open.
+        url: Option<Url>,
+    },
 
     /// List all open tabs in the project.
     ListTabs {
         /// The project to open.
-        #[arg(value_parser = task::Project::from_project_string)]
+        #[arg(value_parser = task::Project::from_project_string, add = ArgValueCompleter::new(complete_project))]
         project: Option<task::Project>,
     },
 }
@@ -126,21 +148,161 @@ 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,
 }
+
+fn complete_task_id(current: &OsStr) -> Vec<CompletionCandidate> {
+    fn format_task(
+        task: task::Task,
+        current: &str,
+        state: &mut state::State,
+    ) -> Option<CompletionCandidate> {
+        let id = {
+            let Ok(base) = task.working_set_id(state) else {
+                return None;
+            };
+            base.to_string()
+        };
+
+        if !id.starts_with(current) {
+            return None;
+        }
+
+        let description = {
+            let Ok(base) = task.description(state) 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() else {
+        return output;
+    };
+
+    let Ok(pending) = state.replica().pending_tasks() 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) {
+                if project == current_project {
+                    if let Some(out) = format_task(task, current, &mut state) {
+                        output.push(out);
+                    }
+                }
+            }
+        }
+    } else {
+        for t in pending {
+            let task = task::Task::from(&t);
+            if let Some(out) = format_task(task, current, &mut state) {
+                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..09827fca 100644
--- a/pkgs/by-name/ts/tskm/src/interface/input/handle.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/input/handle.rs
@@ -1,4 +1,15 @@
+// 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,
     fs, process,
     str::FromStr,
     thread::{self, sleep},
@@ -33,10 +44,23 @@ 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);
+            }
+
+            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.")
                 })?;
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..747ba349 100644
--- a/pkgs/by-name/ts/tskm/src/interface/input/mod.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/input/mod.rs
@@ -1,10 +1,15 @@
+// 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,
-    fmt::Display,
-    fs::{self, read_to_string, File},
-    io::Write,
-    path::PathBuf,
-    process::Command,
+    collections::HashSet, fmt::Display, fs, io::Write, path::PathBuf, process::Command,
     str::FromStr,
 };
 
@@ -16,28 +21,37 @@ 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
@@ -47,7 +61,7 @@ impl NoWhitespaceString {
 #[derive(Debug, Clone)]
 pub struct Input {
     url: Url,
-    tags: HashSet<NoWhitespaceString>,
+    tags: HashSet<Tag>,
 }
 
 impl FromStr for Input {
@@ -61,13 +75,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 +99,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 +117,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 +139,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,27 +175,6 @@ 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.
     ///
     /// # Errors
@@ -217,41 +198,51 @@ 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 path = path.strip_suffix("/url_value").expect("Will exist");
-
-                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))?;
+            output.extend(
                 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()
-            };
-
-            output.push(Self { url, tags });
+                    .map(Self::from_str)
+                    .collect::<Result<Vec<Self>, _>>()?
+                    .into_iter(),
+            );
         }
 
         Ok(output)
     }
+
+    /// 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!");
+            }
+        }
+
+        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 577de02c..194e3926 100644
--- a/pkgs/by-name/ts/tskm/src/interface/neorg/handle.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/neorg/handle.rs
@@ -1,11 +1,21 @@
+// 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},
+    fs::{self, File, OpenOptions, read_to_string},
     io::Write,
     process::Command,
 };
 
-use anyhow::{bail, Context, Result};
+use anyhow::{Context, Result, bail};
 
 use crate::{cli::NeorgCommand, state::State};
 
@@ -13,10 +23,10 @@ pub fn handle(command: NeorgCommand, state: &mut State) -> Result<()> {
     match command {
         NeorgCommand::Task { id } => {
             let project = id.project(state)?;
-            let path = dirs::data_local_dir()
+            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"))?;
 
@@ -69,11 +79,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"))
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 0b565abd..82f468b3 100644
--- a/pkgs/by-name/ts/tskm/src/interface/open/handle.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/open/handle.rs
@@ -1,7 +1,23 @@
-use std::process;
-
-use anyhow::{bail, Context, Result};
-use log::{error, info};
+// 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,
+    net::{IpAddr, Ipv4Addr},
+    path::PathBuf,
+    process,
+};
+
+use anyhow::{Context, Result, bail};
+use log::{error, info, warn};
+use url::Url;
 
 use crate::{cli::OpenCommand, rofi, state::State, task};
 
@@ -11,7 +27,7 @@ pub fn handle(command: OpenCommand, state: &mut State) -> Result<()> {
             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, state).with_context(|| {
+                    open_in_browser(project, state, None).with_context(|| {
                         format!(
                             "Failed to open project ('{}') in Firefox",
                             project.to_project_display()
@@ -26,23 +42,13 @@ pub fn handle(command: OpenCommand, state: &mut State) -> Result<()> {
                 }
             }
         }
-        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, url } => {
             project.touch().context("Failed to touch project")?;
-            open_in_browser(&project, state).with_context(|| {
+            open_in_browser(&project, state, url).with_context(|| {
                 format!("Failed to open project: {}", project.to_project_display())
             })?;
         }
-        OpenCommand::Select => {
+        OpenCommand::Select { url } => {
             let selected_project: task::Project = task::Project::from_project_string(
                 &rofi::select(
                     task::Project::all()
@@ -60,7 +66,7 @@ pub fn handle(command: OpenCommand, state: &mut State) -> Result<()> {
                 .touch()
                 .context("Failed to touch project")?;
 
-            open_in_browser(&selected_project, state).context("Failed to open project")?;
+            open_in_browser(&selected_project, state, url).context("Failed to open project")?;
         }
         OpenCommand::ListTabs { project } => {
             let project = if let Some(p) = project {
@@ -109,7 +115,11 @@ pub fn handle(command: OpenCommand, state: &mut State) -> Result<()> {
     Ok(())
 }
 
-fn open_in_browser(selected_project: &task::Project, state: &mut State) -> Result<()> {
+fn open_in_browser(
+    selected_project: &task::Project,
+    state: &mut State,
+    url: Option<Url>,
+) -> Result<()> {
     let old_project: Option<task::Project> =
         task::Project::get_current().context("Failed to get currently active project")?;
     let old_task: Option<task::Task> =
@@ -154,14 +164,58 @@ fn open_in_browser(selected_project: &task::Project, state: &mut State) -> Resul
         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")?;
+    let status = {
+        let mut args = vec!["-P".to_owned(), selected_project.to_project_display()];
+        if let Some(url) = url {
+            args.push(url.to_string());
+        } else {
+            let lock_file = dirs::home_dir()
+                .expect("Exists")
+                .join(".mozilla/firefox")
+                .join(selected_project.to_project_display())
+                .join("lock");
+
+            if lock_file.exists() {
+                let (ip, pid): (IpAddr, u32) = {
+                    let link = fs::read_link(&lock_file).with_context(|| {
+                        format!("Failed to readlink lock at '{}'", lock_file.display())
+                    })?;
+
+                    let (ip, pid) = link
+                        .to_str()
+                        .expect("Should work")
+                        .split_once(':')
+                        .expect("The split works");
+
+                    (
+                        ip.parse().expect("Should be a valid ip address"),
+                        pid.parse().expect("Should be a valid pid"),
+                    )
+                };
+
+                if ip != Ipv4Addr::new(127, 0, 0, 2) {
+                    warn!("Your ip is weird..");
+                }
+
+                if PathBuf::from("/proc").join(pid.to_string()).exists() {
+                    // Another Firefox instance has already been started for this project
+                    // Add a buffer URL to force Firefox to open it in the already open instance
+                    args.push("about:newtab".to_owned());
+                } else {
+                    // This project does not yet have another Firefox instance
+                    // We do not need to add anything to the arguments, Firefox will open a new
+                    // instance.
+                }
+            } else {
+                // There is no lock file and thus no instance already open.
+            }
+        };
+
+        process::Command::new("firefox")
+            .args(args)
+            .status()
+            .context("Failed to start firefox")?
+    };
 
     if !status.success() {
         error!("Firefox run exited with error.");
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..a4060fa3 100644
--- a/pkgs/by-name/ts/tskm/src/interface/open/mod.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/open/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, fs::File, io};
 
 use anyhow::{Context, Result};
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 f4416c6d..dc425dcc 100644
--- a/pkgs/by-name/ts/tskm/src/main.rs
+++ b/pkgs/by-name/ts/tskm/src/main.rs
@@ -1,8 +1,21 @@
+// 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 state::State;
+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 cli;
 pub mod interface;
@@ -10,38 +23,9 @@ pub mod rofi;
 pub mod state;
 pub mod task;
 
-use crate::cli::{CliArgs, Command};
-
 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.
+    clap_complete::CompleteEnv::with_factory(CliArgs::command).complete();
+
     let args = CliArgs::parse();
 
     stderrlog::new()
@@ -50,7 +34,6 @@ fn main() -> Result<(), anyhow::Error> {
         .show_module_names(true)
         .color(stderrlog::ColorChoice::Auto)
         .verbosity(usize::from(args.verbosity))
-        .timestamp(stderrlog::Timestamp::Off)
         .init()
         .expect("Let's just hope that this does not panic");
 
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
index 175a7f03..ae71764e 100644
--- a/pkgs/by-name/ts/tskm/src/state.rs
+++ b/pkgs/by-name/ts/tskm/src/state.rs
@@ -1,7 +1,17 @@
+// 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::AccessMode, Replica, StorageConfig};
+use taskchampion::{Replica, StorageConfig, storage::AccessMode};
 
 pub struct State {
     replica: Replica,
diff --git a/pkgs/by-name/ts/tskm/src/task/mod.rs b/pkgs/by-name/ts/tskm/src/task/mod.rs
index 03a12faa..04efbec5 100644
--- a/pkgs/by-name/ts/tskm/src/task/mod.rs
+++ b/pkgs/by-name/ts/tskm/src/task/mod.rs
@@ -1,13 +1,23 @@
+// 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},
+    fs::{self, File, read_to_string},
     path::PathBuf,
     process::Command,
     str::FromStr,
     sync::OnceLock,
 };
 
-use anyhow::{bail, Context, Result};
+use anyhow::{Context, Result, bail};
 use log::{debug, info, trace};
 use taskchampion::Tag;
 
@@ -66,6 +76,14 @@ impl Task {
     pub fn uuid(&self) -> &taskchampion::Uuid {
         &self.uuid
     }
+    #[must_use]
+    pub fn working_set_id(&self, state: &mut State) -> Result<usize> {
+        Ok(state
+            .replica()
+            .working_set()?
+            .by_uuid(self.uuid)
+            .expect("The task should be in the working set"))
+    }
 
     fn as_task(&self, state: &mut State) -> Result<taskchampion::Task> {
         Ok(state
@@ -121,7 +139,7 @@ impl Task {
                 .expect("Every task should have a project")
                 .to_owned()
         };
-        let project = Project::from_project_string(output.as_str())
+        let project = Project::from_project_string(output.as_str().trim())
             .expect("This comes from tw, it should be valid");
         Ok(project)
     }