Skip to content

Instantly share code, notes, and snippets.

@rgieseke
Created September 1, 2010 21:37
Show Gist options
  • Save rgieseke/561413 to your computer and use it in GitHub Desktop.
Save rgieseke/561413 to your computer and use it in GitHub Desktop.
module('_m.common.open', package.seeall)
local filtered_folders = {'^%.?$', '%.hg$', '%.git'}
function open(path)
local lfs = require 'lfs'
local items, files = {}, {}
for item in lfs.dir(path) do
if lfs.attributes(path..'/'..item).mode == 'directory' then
if not _m.textadept.snapopen.exclude(item, filtered_folders) then
items[#items + 1] = item
end
elseif _m.textadept.mime_types.extensions[item:match('\.(%w+)$')] then
files[#files + 1] = item
end
end
table.sort(items)
table.sort(files)
for _, v in ipairs(files) do
items[#items+1] = v
end
local out =
gui.dialog('filteredlist',
'--title', path,
'--button1', 'gtk-ok',
'--button2', 'gtk-cancel',
'--no-newline',
'--string-output',
'--columns', 'File',
'--items', unpack(items))
local response, name = out:match('([^\n]+)\n([^\n]+)$')
if response and response ~= 'gtk-cancel' then
if name == '..' then
if path:match('/home$') then
open(path)
else
open(path:match('(.+)/'))
end
elseif lfs.attributes(path..'/'..name).mode == 'directory' then
open(path..'/'..name)
else
io.open_file(path..'/'..name)
end
end
end
keys.co = { function()
if buffer.filename then
local path = buffer.filename:match('(.+)/')
_m.common.open.open(path)
else
_m.common.open.open(_HOME:match('(/%w+/%w+/)'))
end
end}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment