mirror of
https://github.com/Cian-H/My_NixOS_Config.git
synced 2026-02-24 08:38:03 +00:00
Added babashka, and package for obsidian searching via walker
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
in {
|
||||
home.packages = [
|
||||
pkgs.bitwarden-desktop
|
||||
unstablePkgs.babashka
|
||||
pkgs.bat-extras.batman
|
||||
pkgs.bat-extras.batdiff
|
||||
pkgs.bat-extras.batgrep
|
||||
@@ -58,6 +59,7 @@ in {
|
||||
myPkgs.vivaldi-wayland
|
||||
unstablePkgs.visidata
|
||||
pkgs.vivaldi-ffmpeg-codecs
|
||||
myPkgs.walker-obsidian-search
|
||||
pkgs.warpinator
|
||||
pkgs.xarchiver
|
||||
pkgs.yubikey-agent
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{pkgs}: {
|
||||
python = pkgs.callPackage ./python.nix {};
|
||||
vivaldi-wayland = pkgs.callPackage ./vivaldi_wayland.nix {};
|
||||
rbw-autofill = pkgs.callPackage ./rbw_autofill.nix {};
|
||||
vivaldi-wayland = pkgs.callPackage ./vivaldi_wayland.nix {};
|
||||
walker-obsidian-search = pkgs.callPackage ./walker_obsidian_search.nix {};
|
||||
}
|
||||
|
||||
39
home-manager/worklaptop/packages/walker_obsidian_search.clj
Normal file
39
home-manager/worklaptop/packages/walker_obsidian_search.clj
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
#!/usr/bin/env bb
|
||||
|
||||
(require '[clojure.string :as str]
|
||||
'[babashka.process :refer [shell]]
|
||||
'[babashka.fs :as fs])
|
||||
|
||||
(def vault-name "Work_Notes")
|
||||
(def walker-sep " ")
|
||||
(def rg-sep "<rg:sep/>")
|
||||
|
||||
(def vault-path
|
||||
(-> (or (System/getenv "OBSIDIAN_VAULT")
|
||||
(str (fs/home) "/Documents/" vault-name))
|
||||
fs/expand-home
|
||||
fs/absolutize))
|
||||
|
||||
(def rg-results
|
||||
(let [output (:out (shell {:dir (str vault-path) :out :string}
|
||||
"rg" "--no-config" "--field-match-separator" rg-sep
|
||||
"--with-filename" "--line-number" "--no-heading" "--color=never" "-t" "md" "."))]
|
||||
(for [line (str/split-lines output)]
|
||||
(let [[file line-num content] (str/split line (re-pattern rg-sep) 3)]
|
||||
{:file file :line line-num :content content :raw (str file walker-sep content)}))))
|
||||
|
||||
(def selection
|
||||
(let [input (str/join "\n" (map :raw rg-results))]
|
||||
(-> (shell
|
||||
{:out :string :in input :continue true}
|
||||
"walker --dmenu --placeholder \"Search Obsidian Notes\"")
|
||||
:out
|
||||
str/trim)))
|
||||
|
||||
(if (str/blank? selection)
|
||||
(System/exit 0)
|
||||
(let [selected-row (first (filter #(= (:raw %) selection) rg-results))
|
||||
encoded-file (str/replace (:file selected-row) " " "%20")
|
||||
uri (str "obsidian://adv-uri?vault=" vault-name "&filepath=" encoded-file "&line=" (:line selected-row))]
|
||||
(shell "xdg-open" uri)))
|
||||
@@ -0,0 +1,6 @@
|
||||
{pkgs}:
|
||||
pkgs.writeShellApplication {
|
||||
name = "walker-obsidian-search";
|
||||
runtimeInputs = [pkgs.babashka pkgs.ripgrep];
|
||||
text = builtins.readFile ./walker_obsidian_search.clj;
|
||||
}
|
||||
Reference in New Issue
Block a user