Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions filemanager-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ If the directory is expanded, there will be a `+` to the left of it. If it is co

| Option | Purpose | Default |
| :--------------------------- | :----------------------------------------------------------- | :------ |
| `filemanager-showdotfiles` | Show dotfiles (hidden if false) | `true` |
| `filemanager-showignored` | Show gitignore'd files (hidden if false) | `true` |
| `filemanager-compressparent` | Collapse the parent dir when left is pressed on a child file | `true` |
| `filemanager-foldersfirst` | Sorts folders above any files | `true` |
| `filemanager-openonstart` | Automatically open the file tree when starting Micro | `false` |
| `filemanager.showdotfiles` | Show dotfiles (hidden if false) | `true` |
| `filemanager.showignored` | Show gitignore'd files (hidden if false) | `true` |
| `filemanager.compressparent` | Collapse the parent dir when left is pressed on a child file | `true` |
| `filemanager.foldersfirst` | Sorts folders above any files | `true` |
| `filemanager.openonstart` | Automatically open the file tree when starting Micro | `false` |

### Commands and Keybindings

Expand Down
48 changes: 34 additions & 14 deletions filemanager-plugin/filemanager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ end
local function get_ignored_files(tar_dir)
-- True/false if the target dir returns a non-fatal error when checked with 'git status'
local function has_git()
local git_rp_results = shell.ExecCommand('git -C "' .. tar_dir .. '" rev-parse --is-inside-work-tree')
local git_rp_results = shell.ExecCommand('git', '-C', tar_dir, 'rev-parse', '--is-inside-work-tree')
return git_rp_results:match("^true%s*$")
end
local readout_results = {}
-- TODO: Support more than just Git, such as Mercurial or SVN
if has_git() then
-- If the dir is a git dir, get all ignored in the dir
local git_ls_results =
shell.ExecCommand('git -C "' .. tar_dir .. '" ls-files . --ignored --exclude-standard --others --directory')
shell.ExecCommand('git', '-C', tar_dir, 'ls-files', '.', '--ignored', '--exclude-standard', '--others', '--directory')
-- Cut off the newline that is at the end of each result
for split_results in string.gmatch(git_ls_results, "([^\r\n]+)") do
-- git ls-files adds a trailing slash if it's a dir, so we remove it (if it is one)
Expand Down Expand Up @@ -335,7 +335,7 @@ end
local function compress_target(y, delete_y)
-- Can't compress the top stuff, or if there's nothing there, so exit early
if y == 0 or scanlist_is_empty() then
return
return false
end
-- Check if the target is a dir, since files don't have anything to compress
-- Also make sure it's actually an uncompressed dir by checking the gutter message
Expand Down Expand Up @@ -401,7 +401,7 @@ local function compress_target(y, delete_y)
elseif config.GetGlobalOption("filemanager.compressparent") and not delete_y then
goto_parent_dir()
-- Prevent a pointless refresh of the view
return
return true
end

-- Put outside check above because we call this to delete targets as well
Expand Down Expand Up @@ -433,6 +433,8 @@ local function compress_target(y, delete_y)
end

refresh_and_select()

return true
end

-- Prompts the user for deletion of a file/dir when triggered
Expand Down Expand Up @@ -516,6 +518,7 @@ local function try_open_at_y(y)
-- 2 is the zero-based index of ".."
if y == 2 then
go_back_dir()
return true
elseif y > 2 and not scanlist_is_empty() then
-- -2 to conform to our scanlist "missing" first 3 indicies
y = y - 2
Expand All @@ -530,16 +533,18 @@ local function try_open_at_y(y)
-- Resizes all views after opening a file
-- tabs[curTab + 1]:Resize()
end
return true
else
micro.InfoBar():Error("Can't open that")
return false
end
end

-- Opens the dir's contents nested under itself
local function uncompress_target(y)
-- Exit early if on the top 3 non-list items
if y == 0 or scanlist_is_empty() then
return
return false
end
-- Only uncompress if it's a dir and it's not already uncompressed
if scanlist[y].dirmsg == "+" then
Expand Down Expand Up @@ -591,6 +596,10 @@ local function uncompress_target(y)
end

refresh_and_select()

return true
else
return false
end
end

Expand Down Expand Up @@ -841,6 +850,8 @@ local function open_tree()
tree_view.Buf:SetOptionNative("softwrap", true)
-- No line numbering
tree_view.Buf:SetOptionNative("ruler", false)
-- No diff gutter
tree_view.Buf:SetOptionNative("diffgutter", false)
-- Is this needed with new non-savable settings from being "vtLog"?
tree_view.Buf:SetOptionNative("autosave", false)
-- Don't show the statusline to differentiate the view from normal views
Expand Down Expand Up @@ -877,22 +888,26 @@ end

function uncompress_at_cursor()
if micro.CurPane() == tree_view then
uncompress_target(get_safe_y())
return uncompress_target(get_safe_y())
else
return false
end
end

function compress_at_cursor()
if micro.CurPane() == tree_view then
-- False to not delete y
compress_target(get_safe_y(), false)
return compress_target(get_safe_y(), false)
else
return false
end
end

-- Goes up 1 visible directory (if any)
-- Not local so it can be bound
function goto_prev_dir()
if micro.CurPane() ~= tree_view or scanlist_is_empty() then
return
return false
end

local cur_y = get_safe_y()
Expand All @@ -906,17 +921,18 @@ function goto_prev_dir()
-- Jump to its parent (the ownership)
tree_view.Cursor:UpN(move_count)
select_line()
break
return true
end
end
end
return false
end

-- Goes down 1 visible directory (if any)
-- Not local so it can be bound
function goto_next_dir()
if micro.CurPane() ~= tree_view or scanlist_is_empty() then
return
return false
end

local cur_y = get_safe_y()
Expand All @@ -935,17 +951,18 @@ function goto_next_dir()
-- Jump to its parent (the ownership)
tree_view.Cursor:DownN(move_count)
select_line()
break
return true
end
end
end
return false
end

-- Goes to the parent directory (if any)
-- Not local so it can be keybound
function goto_parent_dir()
if micro.CurPane() ~= tree_view or scanlist_is_empty() then
return
return false
end

local cur_y = get_safe_y()
Expand All @@ -954,15 +971,18 @@ function goto_parent_dir()
-- Jump to its parent (the ownership)
tree_view.Cursor:UpN(cur_y - scanlist[cur_y].owner)
select_line()
return true
else
return false
end
end

function try_open_at_cursor()
if micro.CurPane() ~= tree_view or scanlist_is_empty() then
return
return false
end

try_open_at_y(tree_view.Cursor.Loc.Y)
return try_open_at_y(tree_view.Cursor.Loc.Y)
end

-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down