Created
June 28, 2020 08:36
-
-
Save kolja/8ee1ba60a84ff065d4eaa242f9d85c65 to your computer and use it in GitHub Desktop.
babashka bookmark plugin for nnn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bb | |
; kolja (@01k) 2020 | |
; | |
; usage: | |
; | |
; create a directory where you would like to keep your bookmarks. | |
; create an env variable NNN_BMDIR with the path to that directory (e.g. "~/.config/nnn/bookmarks") | |
; save this file in ~/.config/nnn/plugins as "bookmark" (for example) | |
; | |
; example: | |
; | |
; export NNN_BMDIR="~/.config/nnn/bookmarks" | |
; export NNN_BMS="b:${NNN_BMDIR}" | |
; export NNN_PLUG="b:bookmark" | |
; | |
; then it's ";b" to bookmark a file or directory | |
; and "bb" to change change to the bookmarks folder. | |
(ns bookmark | |
(:require [clojure.java.io :as io] | |
[clojure.java.shell :refer [sh]] | |
[clojure.string :as str])) | |
(defn expand-home [bmdir] | |
(if (.startsWith bmdir "~") | |
(clojure.string/replace-first bmdir "~" (System/getProperty "user.home")) | |
bmdir)) | |
(defn input [message] | |
(do | |
(print message) | |
(flush) | |
(-> (io/reader *in*) line-seq first))) | |
(let [[target pwd] *command-line-args* | |
bookmark_dir (expand-home (System/getenv "NNN_BMDIR")) | |
bookmark_name (input (str "Bookmark " pwd "/" target " as: ")) | |
{:keys [:exit :err :out]} (sh "ln" "-s" | |
(str pwd "/" target) | |
(str bookmark_dir "/" bookmark_name))] | |
(if (zero? exit) | |
(println out) | |
(do (println "ERROR:" err) | |
(System/exit 1)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment