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

Fixed problem with shellslash #371

Closed
wants to merge 6 commits into from
Closed
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
3 changes: 2 additions & 1 deletion lua/plenary/curl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ local util, parse, request = {}, {}, nil
local F = require "plenary.functional"
local J = require "plenary.job"
local P = require "plenary.path"
local S = require "plenary.system"

-- Utils ----------------------------------------------------
-------------------------------------------------------------
Expand Down Expand Up @@ -70,7 +71,7 @@ util.gen_dump_path = function()
local v = (l == "x") and math.random(0, 0xf) or math.random(0, 0xb)
return string.format("%x", v)
end)
if P.path.sep == "\\" then
if S.is_windows() then
path = string.format("%s\\AppData\\Local\\Temp\\plenary_curl_%s.headers", os.getenv "USERPROFILE", id)
else
path = "/tmp/plenary_curl_" .. id .. ".headers"
Expand Down
14 changes: 7 additions & 7 deletions lua/plenary/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local bit = require "plenary.bit"
local uv = vim.loop

local F = require "plenary.functional"
local S = require "plenary.system"

local S_IF = {
-- S_IFDIR = 0o040000 # directory
Expand All @@ -20,8 +21,7 @@ path.home = vim.loop.os_homedir()

path.sep = (function()
if jit then
local os = string.lower(jit.os)
if os ~= "windows" then
if not S.is_windows() or S.uses_shellslash() then
return "/"
else
return "\\"
Expand All @@ -32,7 +32,7 @@ path.sep = (function()
end)()

path.root = (function()
if path.sep == "/" then
if not S.is_windows() or S.uses_shellslash then
return function()
return "/"
end
Expand All @@ -55,7 +55,7 @@ local concat_paths = function(...)
end

local function is_root(pathname)
if path.sep == "\\" then
if S.is_windows() then
return string.match(pathname, "^[A-Z]:\\?$")
end
return pathname == "/"
Expand All @@ -77,7 +77,7 @@ local is_uri = function(filename)
end

local is_absolute = function(filename, sep)
if sep == "\\" then
if S.is_windows() then
return string.match(filename, "^[%a]:\\.*$") ~= nil
end
return string.sub(filename, 1, 1) == sep
Expand All @@ -103,7 +103,7 @@ local function _normalize_path(filename, cwd)
local split_without_disk_name = function(filename_local)
local parts = _split_by_separator(filename_local)
-- Remove disk name part on Windows
if path.sep == "\\" and is_abs then
if S.is_windows() and is_abs then
table.remove(parts, 1)
end
return parts
Expand Down Expand Up @@ -431,7 +431,7 @@ local function shorten_len(filename, len, exclude)
end

local shorten = (function()
if jit and path.sep ~= "\\" then
if jit and not S.is_windows() then
local ffi = require "ffi"
ffi.cdef [[
typedef unsigned char char_u;
Expand Down
9 changes: 5 additions & 4 deletions lua/plenary/scandir.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local Path = require "plenary.path"
local os_sep = Path.path.sep
local F = require "plenary.functional"
local S = require "plenary.system"

local uv = vim.loop

Expand Down Expand Up @@ -319,7 +320,7 @@ local gen_date = (function()
end)()

local get_username = (function()
if jit and os_sep ~= "\\" then
if jit and not S.is_windows() then
local ffi = require "ffi"
ffi.cdef [[
typedef unsigned int __uid_t;
Expand Down Expand Up @@ -369,7 +370,7 @@ local get_username = (function()
end)()

local get_groupname = (function()
if jit and os_sep ~= "\\" then
if jit and not S.is_windows() then
local ffi = require "ffi"
ffi.cdef [[
typedef unsigned int __gid_t;
Expand Down Expand Up @@ -446,8 +447,8 @@ local gen_ls = function(data, path, opts)

local results, sections = {}, {}

local users_tbl = os_sep ~= "\\" and {} or nil
local groups_tbl = os_sep ~= "\\" and {} or nil
local users_tbl = not S.is_windows() and {} or nil
local groups_tbl = not S.is_windows() and {} or nil

local stats, permissions_cache = {}, {}
for _, v in ipairs(data) do
Expand Down
5 changes: 3 additions & 2 deletions lua/plenary/strings.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
local path = require("plenary.path").path
local S = require "plenary.system"

local M = {}

M.strdisplaywidth = (function()
if jit and path.sep ~= [[\]] then
if jit and not S.is_windows() then
local ffi = require "ffi"
ffi.cdef [[
typedef unsigned char char_u;
Expand All @@ -29,7 +30,7 @@ M.strdisplaywidth = (function()
end)()

M.strcharpart = (function()
if jit and path.sep ~= [[\]] then
if jit and not S.is_windows() then
local ffi = require "ffi"
ffi.cdef [[
typedef unsigned char char_u;
Expand Down
22 changes: 22 additions & 0 deletions lua/plenary/system.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local system = {}

function system.is_windows()
-- The shellslash option is not able to change this variable
if package.config:sub(1,1) == "\\" then
return true
end

return false
Comment on lines +4 to +9
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could just do return package.config:sub(1,1) == "\\"

end

function system.uses_shellslash()
local shellslash_exists = vim.fn.exists("+shellslash") ~= 0

if shellslash_exists then
return vim.o.shellslash
end

return false
end

return system
11 changes: 6 additions & 5 deletions tests/plenary/path_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local Path = require "plenary.path"
local path = Path.path
local System = require "plenary.system"

describe("Path", function()
it("should find valid files", function()
Expand Down Expand Up @@ -104,7 +105,7 @@ describe("Path", function()
end)

it("can take absolute paths and make them relative to a given path", function()
local root = path.sep == "\\" and "c:\\" or "/"
local root = System.is_windows() and "c:\\" or "/"
local r = Path:new { root, "home", "prime" }
local p = Path:new { "aoeu", "agen.lua" }
local absolute = r.filename .. path.sep .. p.filename
Expand All @@ -120,7 +121,7 @@ describe("Path", function()
end)

it("can take double separator absolute paths and make them relative to a given path", function()
local root = path.sep == "\\" and "c:\\" or "/"
local root = System.is_windows() and "c:\\" or "/"
local r = Path:new { root, "home", "prime" }
local p = Path:new { "aoeu", "agen.lua" }
local absolute = r.filename .. path.sep .. path.sep .. p.filename
Expand All @@ -129,7 +130,7 @@ describe("Path", function()
end)

it("can take absolute paths and make them relative to a given path with trailing separator", function()
local root = path.sep == "\\" and "c:\\" or "/"
local root = System.is_windows() and "c:\\" or "/"
local r = Path:new { root, "home", "prime" }
local p = Path:new { "aoeu", "agen.lua" }
local absolute = r.filename .. path.sep .. p.filename
Expand All @@ -138,15 +139,15 @@ describe("Path", function()
end)

it("can take absolute paths and make them relative to the root directory", function()
local root = path.sep == "\\" and "c:\\" or "/"
local root = System.is_windows() and "c:\\" or "/"
local p = Path:new { "home", "prime", "aoeu", "agen.lua" }
local absolute = root .. p.filename
local relative = Path:new(absolute):make_relative(root)
assert.are.same(relative, p.filename)
end)

it("can take absolute paths and make them relative to themselves", function()
local root = path.sep == "\\" and "c:\\" or "/"
local root = System.is_windows() and "c:\\" or "/"
local p = Path:new { root, "home", "prime", "aoeu", "agen.lua" }
local relative = Path:new(p.filename):make_relative(p.filename)
assert.are.same(relative, ".")
Expand Down