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

feat: allow bufnr optional parameter for get_current_dir function #440

Merged
merged 1 commit into from
Jul 6, 2024
Merged
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
8 changes: 6 additions & 2 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ Change how oil determines if the file is hidden
Toggle hidden files and directories


## get_current_dir()
## get_current_dir(bufnr)

`get_current_dir(): nil|string` \
`get_current_dir(bufnr): nil|string` \
Get the current directory

| Param | Type | Desc |
| ----- | -------------- | --------------------------------------------- |
| bufnr | `nil\|integer` | When nil, get directory of the current buffer |


## open_float(dir)

Expand Down
4 changes: 3 additions & 1 deletion doc/oil.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,11 @@ toggle_hidden() *oil.toggle_hidde
Toggle hidden files and directories


get_current_dir(): nil|string *oil.get_current_dir*
get_current_dir({bufnr}): nil|string *oil.get_current_dir*
Get the current directory

Parameters:
{bufnr} `integer` When nil, get directory of the current buffer

open_float({dir}) *oil.open_float*
Open oil browser in a floating window
Expand Down
6 changes: 4 additions & 2 deletions lua/oil/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,14 @@ M.toggle_hidden = function()
end

---Get the current directory
---@param bufnr? integer
---@return nil|string
M.get_current_dir = function()
M.get_current_dir = function(bufnr)
local config = require("oil.config")
local fs = require("oil.fs")
local util = require("oil.util")
local scheme, path = util.parse_url(vim.api.nvim_buf_get_name(0))
local buf_name = vim.api.nvim_buf_get_name(bufnr or 0)
local scheme, path = util.parse_url(buf_name)
if config.adapters[scheme] == "files" then
assert(path)
return fs.posix_to_os_path(path)
Expand Down