Neovim plugin improving access to clipboard history (mirror)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add config option for database path #22

ptdewey 3a18535f e917ea8c

+12 -12
+4
README.md
··· 66 66 | registers | table container for register overrides | `{ }` | 67 67 | registers.yank_register | default register to yank from popup to | `"+"` | 68 68 | persist_type | string defining persistence type "sqlite" or nil | `nil` | 69 + | db_path | string defining database file path for use with sqlite persistence | plugin install directory | 69 70 70 71 71 72 #### Example Configuration ··· 123 124 Note: The database can be cleared with the `:YankBankClearDB` command or by deleting the db file (found in the plugin install directory by default). 124 125 125 126 If you run into any SQL related issues, please file an issue on GitHub. (As a temporary fix, you can also try clearing the database) 127 + 128 + 129 + If you run into permissions issues when creating the db file (i.e. when installing using Nix), use the `db_path` option to change the default file path. (`vim.fn.stdpath("data")` should work) 126 130 127 131 ## Usage 128 132
+2 -1
lua/yankbank/init.lua
··· 20 20 registers = { 21 21 yank_register = "+", 22 22 }, 23 + keymaps = {}, 23 24 persist_type = nil, 24 - keymaps = {}, 25 + db_path = nil, 25 26 } 26 27 27 28 --- wrapper function for main plugin functionality
+6 -11
lua/yankbank/persistence/sql.lua
··· 2 2 3 3 local sqlite = require("sqlite") 4 4 5 - -- local dbdir = vim.fn.stdpath("data") .. "/databases" 6 - local dbdir = debug.getinfo(1).source:sub(2):match("(.*/).*/.*/.*/") or "./" 5 + local dbdir = YB_OPTS.db_path 6 + or debug.getinfo(1).source:sub(2):match("(.*/).*/.*/.*/") 7 + or "./" 8 + -- or vim.fn.stdpath("data") 7 9 local max_entries = 10 8 10 9 11 ---@class YankBankDB:sqlite_db ··· 22 24 ---@class sqlite_tbl 23 25 local data = db.bank 24 26 25 - -- NOTE: escape and unescape query text 26 - -- TODO: adjust to only escape text that matches function syntax 27 - --- 28 27 ---@param content string 29 28 ---@return string 30 29 function M.escape(content) 31 30 return string.format("__ESCAPED__'%s'", content) 32 31 end 33 32 34 - --- 35 33 ---@param content string 36 34 ---@return string 37 35 ---@return integer? ··· 146 144 --- pin entry in yankbank to prevent removal 147 145 ---@param text string text to match and pin 148 146 ---@param reg_type string reg_type corresponding to text 149 - ---@return boolean 147 + ---@return boolean? 150 148 function data.pin(text, reg_type) 151 149 return db:with_open(function() 152 - -- TODO: always returns true or nothing 153 150 return ( 154 151 db:eval( 155 152 "UPDATE bank SET pinned = 1 WHERE yank_text = :yank_text and reg_type = :reg_type", ··· 162 159 --- unpin entry in yankbank to prevent removal 163 160 ---@param text string 164 161 ---@param reg_type string reg_type corresponding to text 165 - ---@return boolean 162 + ---@return boolean? 166 163 function data.unpin(text, reg_type) 167 164 return db:with_open(function() 168 - -- TODO: always returns true or nothing 169 - -- - figure out how to return if updated or remove return 170 165 return db:eval( 171 166 "UPDATE bank SET pinned = 0 WHERE yank_text = :yank_text and reg_type = :reg_type", 172 167 { yank_text = M.escape(text), reg_type = reg_type }