about summary refs log tree commit diff
path: root/.local
diff options
context:
space:
mode:
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/rofi-notes104
1 files changed, 6 insertions, 98 deletions
diff --git a/.local/bin/rofi-notes b/.local/bin/rofi-notes
index 876bc66..840dea6 100755
--- a/.local/bin/rofi-notes
+++ b/.local/bin/rofi-notes
@@ -1,101 +1,9 @@
-#!/usr/bin/env lua
+#!/usr/bin/env sh
 
-local HOME   = os.getenv("HOME")
-local NOTES  = HOME .. "/Documents/Notes"
-local TERM   = "foot -a=floating_foot"
-local EDITOR = "nvim"
+note_list=$(zk list -f "{{ title }}" -d $'\n' -q)
 
-local MODE   = arg[1] -- nil | "--delete" | "-d"
+selected=$(printf "%s\n" "$note_list" | rofi -dmenu -i -p "󱞁 ")
 
-local function rofi(prompt, lines)
-  local cmd = string.format(
-    'printf "%s" | rofi -dmenu -i -p "%s"',
-    table.concat(lines, "\n"),
-    prompt
-  )
-  local handle = io.popen(cmd)
-  local selection = handle:read("*a")
-  handle:close()
-  selection = selection:gsub("%s+$", "")
-  if selection == "" then return nil end
-  return selection
-end
-
-local function list_notes()
-  local display = {}
-  local lookup  = {}
-
-  local cmd     = string.format('find "%s" -type f', NOTES)
-  local pipe    = assert(io.popen(cmd, "r"))
-
-  for fullPath in pipe:lines() do
-    local relPath  = fullPath:gsub("^" .. NOTES .. "/", "")
-    local noteName = relPath:gsub("%.[^./]*$", "")
-
-    table.insert(display, noteName)
-    lookup[noteName] = fullPath
-  end
-
-  pipe:close()
-  return display, lookup
-end
-
-local function normalize_path(input)
-  input = input:gsub("^/", "")
-  if not input:match("%.md$") then
-    input = input .. ".md"
-  end
-  return NOTES .. "/" .. input
-end
-
-local function ensure_parent_dir(path)
-  local dir = path:match("(.+)/[^/]+$")
-  if dir then
-    os.execute(string.format('mkdir -p "%s"', dir))
-  end
-end
-
-local function open_in_nvim(path)
-  local cmd = string.format(
-    '%s -e %s "%s"',
-    TERM,
-    EDITOR,
-    path
-  )
-  os.execute(cmd)
-end
-
-local function delete_note(path, name)
-  local confirm = rofi("Delete " .. name .. "?", { "No", "Yes" })
-  if confirm == "Yes" then
-    os.execute(string.format('rm -- "%s"', path))
-  end
-end
-
--- ---- main ----
-
-local notes, paths = list_notes()
-
-if MODE == "--delete" or MODE == "-d" then
-  local choice = rofi(" ", notes)
-  if not choice then os.exit(0) end
-
-  local path = paths[choice]
-  if path then
-    delete_note(path, choice)
-  end
-
-  os.exit(0)
-end
-
--- default: open / create
-local choice = rofi(" ", notes)
-if not choice then os.exit(0) end
-
-local path = paths[choice]
-if not path then
-  path = normalize_path(choice)
-  ensure_parent_dir(path)
-end
-
-open_in_nvim(path)
+if [[ -n $selected ]]; then
+    foot -a=floating_foot -e sh -c "zk edit --match \"${selected}\""
+fi