about summary refs log tree commit diff stats
path: root/pkgs/by-name/ts/tskm/src/interface
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-20 18:41:16 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-20 18:41:16 +0200
commit24d7d3e14ff14d6e43670023bd0862e82f9408e7 (patch)
tree79d0da401fac0dbc451f8c0ac63e2306d4c4ac16 /pkgs/by-name/ts/tskm/src/interface
parentmodules/legacy/conf/iamb: Move to `by-name` and modernize (diff)
downloadnixos-config-24d7d3e14ff14d6e43670023bd0862e82f9408e7.zip
pkgs/tskm: Support raw paths in place of URLs
Otherwise, using `tskm` as an URL opener might fail (e.g., as `xdg-open
/some/path`, would still invoke it).
Diffstat (limited to 'pkgs/by-name/ts/tskm/src/interface')
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/open/handle.rs2
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/open/mod.rs30
2 files changed, 30 insertions, 2 deletions
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 0cf60b41..3897a63b 100644
--- a/pkgs/by-name/ts/tskm/src/interface/open/handle.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/open/handle.rs
@@ -43,7 +43,7 @@ pub fn handle(command: OpenCommand, state: &mut State) -> Result<()> {
                         project.to_project_display(),
                         if is_empty { "is empty" } else { "is not empty" }
                     );
-                    open_in_browser(project, state, None).with_context(|| {
+                    open_in_browser(project, state, None::<Vec<Url>>).with_context(|| {
                         format!(
                             "Failed to open project ('{}') in qutebrowser",
                             project.to_project_display()
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 e302c7d1..e403b4a8 100644
--- a/pkgs/by-name/ts/tskm/src/interface/open/mod.rs
+++ b/pkgs/by-name/ts/tskm/src/interface/open/mod.rs
@@ -8,7 +8,11 @@
 // 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::File, io::Read, str::FromStr};
+use std::{
+    fs::{self, File},
+    io::Read,
+    str::FromStr,
+};
 
 use anyhow::{anyhow, Context, Result};
 use taskchampion::chrono::NaiveDateTime;
@@ -20,6 +24,30 @@ 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::data_local_dir()