Skip to content

Commit

Permalink
feat: add path_sep option to file_info provider (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
ram02z authored Sep 15, 2022
1 parent 331a794 commit 68ff807
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,8 @@ The `file_info` provider has some special provider options that can be passed th
Default:`'●'`
- `file_readonly_icon` (string): The icon that is shown when a file is read-only.<br>
Default:`'🔒'`
- `path_sep` (string): The separator character in the file path. <br>
Default: `/` or `\` depending on OS
- `type` (string): Determines which parts of the filename are shown. Its value can be one of:

- `'full-path'`: Full path of the file (eg: `'/home/user/.config/nvim/init.lua'`)
Expand Down
21 changes: 21 additions & 0 deletions lua/feline/providers/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ local function get_unique_filename(filename, shorten)
return string.reverse(string.sub(filename, 1, index))
end

-- Get path separator depending on OS
local function get_path_separator()
if jit then
local os = string.lower(jit.os)
if os == 'linux' or os == 'osx' or os == 'bsd' then
return [[/]]
else
return [[\]]
end
else
return package.config:sub(1, 1)
end
end

local default_seperator = get_path_separator()

function M.file_info(component, opts)
local readonly_str, modified_str, icon

Expand Down Expand Up @@ -122,6 +138,11 @@ function M.file_info(component, opts)

-- escape any special statusline characters in the filename
filename = filename:gsub('%%', '%%%%')

if opts.path_sep then
filename = filename:gsub(default_seperator, opts.path_sep)
end

return string.format('%s%s%s', readonly_str, filename, modified_str), icon
end

Expand Down

0 comments on commit 68ff807

Please sign in to comment.