From 31645370a105e59270634ec14665149e919f7432 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Thu, 19 Jan 2023 00:26:56 -0800 Subject: [PATCH] refactor!: change scp:// urls back to oil-ssh:// --- README.md | 13 +++++++++++-- lua/oil/config.lua | 14 +++++++++----- lua/oil/init.lua | 24 ++++++++++++++---------- tests/url_spec.lua | 4 ++-- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 9a2e739..bc5dbba 100644 --- a/README.md +++ b/README.md @@ -184,10 +184,10 @@ Note that file operations work _across adapters_. This means that you can use oi This adapter allows you to browse files over ssh, much like netrw. To use it, simply open a buffer using the following name template: ``` -nvim scp://[username@]hostname[:port]/[path] +nvim oil-ssh://[username@]hostname[:port]/[path] ``` -This may look familiar. In fact, this is the exact same url format that netrw uses. +This may look familiar. In fact, this is the same url format that netrw uses. Note that at the moment the ssh adapter does not support Windows machines, and it requires the server to have a `/bin/bash` binary as well as standard unix commands (`rm`, `mv`, `mkdir`, `chmod`, `cp`, `touch`, `ln`, `echo`). @@ -328,3 +328,12 @@ If you don't need those features specifically, check out the alternatives listed - [vidir](https://github.com/trapd00r/vidir): Never personally used, but might be the first plugin to come up with the idea of editing a directory like a buffer. There's also file trees like [neo-tree](https://github.com/nvim-neo-tree/neo-tree.nvim) and [nvim-tree](https://github.com/nvim-tree/nvim-tree.lua), but they're really a different category entirely. + +**Q: I don't need netrw anymore. How can I disable it?** + +**A:** Oil can fully replace netrw for local and ssh file browsing/editing, but keep in mind that netrw also supports rsync, http, ftp, and dav. If you don't need these other features, you can disable netrw with the following: + +```lua +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 +``` diff --git a/lua/oil/config.lua b/lua/oil/config.lua index f80b993..f9c0098 100644 --- a/lua/oil/config.lua +++ b/lua/oil/config.lua @@ -67,12 +67,9 @@ local default_config = { -- reason, I'm taking them out of the section above so they won't show up in the autogen docs. default_config.adapters = { ["oil://"] = "files", - ["scp://"] = "ssh", -} --- For backwards compatibility -default_config.adapter_aliases = { - ["oil-ssh://"] = "scp://", + ["oil-ssh://"] = "ssh", } +default_config.adapter_aliases = {} local M = {} @@ -147,6 +144,13 @@ M.get_adapter_by_scheme = function(scheme) local adapter = M._adapter_by_scheme[scheme] if adapter == nil then local name = M.adapters[scheme] + if not name then + vim.notify( + string.format("Could not find oil adapter for scheme '%s'", scheme), + vim.log.levels.ERROR + ) + return nil + end local ok ok, adapter = pcall(require, string.format("oil.adapters.%s", name)) if ok then diff --git a/lua/oil/init.lua b/lua/oil/init.lua index 7b7599c..d8bcafe 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -553,12 +553,6 @@ local function load_oil_buffer(bufnr) local bufname = vim.api.nvim_buf_get_name(bufnr) local scheme, path = util.parse_url(bufname) if config.adapter_aliases[scheme] then - if scheme == "oil-ssh://" then - vim.notify_once( - 'The "oil-ssh://" url scheme is deprecated, use "scp://" instead.\nSupport will be removed on 2023-06-01.', - vim.log.levels.WARN - ) - end scheme = config.adapter_aliases[scheme] bufname = scheme .. path util.rename_buffer(bufnr, bufname) @@ -603,10 +597,6 @@ end M.setup = function(opts) local config = require("oil.config") - -- Disable netrw - vim.g.loaded_netrw = 1 - vim.g.loaded_netrwPlugin = 1 - config.setup(opts) set_colors() vim.api.nvim_create_user_command("Oil", function(args) @@ -693,6 +683,20 @@ M.setup = function(opts) end end, }) + if not config.silence_scp_warning then + vim.api.nvim_create_autocmd("BufNew", { + desc = "Warn about scp:// usage", + group = aug, + pattern = "scp://*", + once = true, + callback = function() + vim.notify( + "If you are trying to browse using Oil, use oil-ssh:// instead of scp://\nSet `silence_scp_warning = true` in oil.setup() to disable this message.\nSee https://github.com/stevearc/oil.nvim/issues/27 for more information.", + vim.log.levels.WARN + ) + end, + }) + end vim.api.nvim_create_autocmd("WinNew", { desc = "Restore window options when splitting an oil window", group = aug, diff --git a/tests/url_spec.lua b/tests/url_spec.lua index 0045d81..43d5b3d 100644 --- a/tests/url_spec.lua +++ b/tests/url_spec.lua @@ -7,8 +7,8 @@ describe("url", function() { "/foo/bar.txt", "oil:///foo/", "bar.txt" }, { "oil:///foo/bar.txt", "oil:///foo/", "bar.txt" }, { "oil:///", "oil:///" }, - { "scp://user@hostname:8888//bar.txt", "scp://user@hostname:8888//", "bar.txt" }, - { "scp://user@hostname:8888//", "scp://user@hostname:8888//" }, + { "oil-ssh://user@hostname:8888//bar.txt", "oil-ssh://user@hostname:8888//", "bar.txt" }, + { "oil-ssh://user@hostname:8888//", "oil-ssh://user@hostname:8888//" }, } for _, case in ipairs(cases) do local input, expected, expected_basename = unpack(case)