Skip to content

Commit

Permalink
feat(vrsjmp): Add safari_history.ll
Browse files Browse the repository at this point in the history
  • Loading branch information
leoshimo committed Dec 31, 2024
1 parent 543a5a2 commit 5322830
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lyric/src/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,7 @@ mod tests {
);
}
}

// TODO(bug): Cannot parse non-number "-" prefix:
// vrs> (- (read (get (exec "date" "+%s") 1)) 10)
// Incomplete expression - Unable to parse integer - -
20 changes: 20 additions & 0 deletions scripts/safari_history.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env vrsctl
# safari_history.ll - Access Safari History
#

# TODO: Timeout block? (timeout DURATION PROC) - would be nice to cap (exec ...) time

(def safari_history '())

(bind_srv :os_notify)

(defn get_safari_history ()
"(get_safari_history) - Get the list of items from Safari History"
safari_history)

(defn refresh_safari_history ()
"(refresh_safari_history) - Refresh in-memory Safari History"
(def (:ok res) (exec "./scripts/safari_history_shim.tcl"))
(set safari_history (read res)))

(spawn_srv :safari_history :interface '(get_safari_history refresh_safari_history))
34 changes: 34 additions & 0 deletions scripts/safari_history_shim.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env tclsh
# safari_history_shim.tcl - Shim for Safari History SQLite and VRS
#
# TODO: Embed sqlite bindings in VRS?
# TODO: Ergonomics for embedded scripts within lyric lang?

package require sqlite3

set output "(\n"

catch {
sqlite3 historydb "$env(HOME)/Library/Safari/History.db"
historydb eval {
SELECT datetime(visit_time + 978307200, 'unixepoch', 'localtime') as local_visit_time, TRIM(title) as trim_title, url, domain_expansion
FROM history_visits
JOIN history_items ON history_visits.history_item = history_items.id
WHERE LENGTH(TRIM(COALESCE(title, ''))) > 0
AND LENGTH(TRIM(COALESCE(url, ''))) > 0
AND LENGTH(url) < 500
AND url NOT LIKE "%/search%"
AND url NOT LIKE "%read.amazon.co.jp%"
GROUP BY history_item
ORDER BY visit_time DESC, visit_count_score DESC
LIMIT 250
} {
append output "(:safari_history_item :title \"$trim_title\" :url \"$url\" :domain_expansion \"$domain_expansion\")"
}
}

append output ")"

historydb close

puts "$output"
1 change: 1 addition & 0 deletions scripts/serve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ while true; do
cargo run --bin vrsctl $CARGO_ARGS ./scripts/os_cal.ll >/dev/null
cargo run --bin vrsctl $CARGO_ARGS ./scripts/os_clipboard.ll >/dev/null

cargo run --bin vrsctl $CARGO_ARGS ./scripts/safari_history.ll >/dev/null
cargo run --bin vrsctl $CARGO_ARGS ./scripts/youtube.ll >/dev/null

if [ "$MODE" = "demo" ]; then
Expand Down
14 changes: 14 additions & 0 deletions scripts/vrsjmp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
(bind_srv :os_notes)
(bind_srv :youtube)
(bind_srv :cmd_macro)
(bind_srv :safari_history)

(defn get_items (query)
"Retrieve items to display"
Expand All @@ -27,6 +28,7 @@
(scheduler_items query)
(rlist_items query)
(youtube_items query)
(safari_history_items query)
(macro_items query)
(query_items query)))

Expand Down Expand Up @@ -125,6 +127,18 @@
(map (list_videos) (fn (n) (list :title (format "yt: {}" (get n :title))
:on_click (list 'open_file (get n :path)))))))

# TODO: Nice-to-have - "subtitle" UI to show url / domain
(defn safari_history_items (query)
"(safari_history_items QUERY) - Returns markup for safari history items"
(if (not? (contains? query "h:"))
'()
(begin
(if (eq? query "h:") (refresh_safari_history)) # refresh on "appear"
(map (get_safari_history) (fn (h) (make_item_ex (format "h: {}" (get h :title))
(list 'open_url (get h :url))
(get h :domain_expansion)))))))


# TODO: Nice to have "prefix-drop" for these prefixed names
(defn macro_items (query)
"(macro_items QUERY) - Returns markup for macro items"
Expand Down

0 comments on commit 5322830

Please sign in to comment.