Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow opening files from picker #73

Closed
anandkumar89 opened this issue Mar 19, 2024 · 3 comments
Closed

Allow opening files from picker #73

anandkumar89 opened this issue Mar 19, 2024 · 3 comments

Comments

@anandkumar89
Copy link

since the BibTeX file is used - this file also contains file: path_to_file. I am looking for ways to open this file from picker with a keybinding in external pdf reader e.g. open ...

How can one go about extending telescope-bibtex for this purpose?

@life00
Copy link

life00 commented Apr 9, 2024

Duplicate of #20

@anandkumar89
Copy link
Author

thanks, will continue in #20

@anandkumar89
Copy link
Author

anandkumar89 commented Apr 16, 2024

Note for people interested :

I added a shortcut when setting up bibtex extension for telescope as below to open pdf files in desired app. For me, Sioyek.

This was inspired by solutions in #20, and help from chatGPT.

local bibtex_actions = require('telescope-bibtex.actions')
local action_state  = require('telescope.actions.state')
local actions 		= require('telescope.actions')
local job 			= require('plenary.job')
require('telescope').setup({
	extensions = {
		bibtex = {
			depth=2,
			format='plain',
			global_files = {'~/Dropbox/Apps/Overleaf/bib/online.bib', '~/Dropbox/Apps/Overleaf/bib/library.bib'},
			search_keys = {'author', 'year', 'title'},
			context = true,
			mappings = {
				    i = {
						["<CR>"] = function(prompt_bufnr)
							local entry = action_state.get_selected_entry().id.content
							-- local files = {} -- TODO handle multiple files, show harpoon like UI to select file
							-- local extensions = {}
							actions.close(prompt_bufnr)
							entry = table.concat(entry, "\n")
							for paths in entry:gmatch("file%s*=%s*{([^}]+)}") do
								for path in paths:gmatch("[^,]+") do
    									path = vim.trim(path)
    									local ext  = path:match("^.+%.(.+)$")
    									-- table.insert(files, path)
    									-- table.insert(extensions,ext)
    									if ext == "pdf" then
    											job:new({
    											  command = "/Applications/sioyek.app/Contents/MacOS/sioyek",
    											  args = { path },
    											  detached = true,
    											}):start()
    									end
    								end
    							end
    					  end,
					  }
				 },
			wrap = true,
			}
		}
})
require('telescope').load_extension("bibtex")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants