Skip to content

Commit

Permalink
add contribution section to README, add .stylua.toml for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
linarcx committed Jan 13, 2022
1 parent 6bcc60d commit a0824a5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
column_width = 120
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "ForceDouble"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ require('telescope').load_extension('env')
# Usage
`:Telescope env`

# Contribution
If you have any idea to improve this project, please create a pull-request for it. To make changes consistent, i have some rules for PRs:
1. Before submit your work, please format it with [StyLua](https://github.com/JohnnyMorganz/StyLua).
1.1. I provided an __.stylua__ file in root of the project. Just call: `stylua lua/telescope/_extensions/env.lua`
2. There should be a one-to-one relation between features and pull requests. Please create separate pull-requests for each feature.

# Roadmap :blue_car:
- [ ] copy selected value when select an item in picker.
- [ ] use previews because some variables like `PATH` don't fit on screen.
Expand Down
42 changes: 18 additions & 24 deletions lua/telescope/_extensions/env.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
local pickers = require "telescope.pickers"
local finders = require "telescope.finders"
local actions = require "telescope.actions"
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local actions = require("telescope.actions")
local conf = require("telescope.config").values
local entry_display = require('telescope.pickers.entry_display')
local entry_display = require("telescope.pickers.entry_display")

local function prepareEnvironmentVariables()
Items = {}
for key, value in pairs(vim.fn.environ()) do
table.insert(Items, {key, value})
table.insert(Items, { key, value })
end
return Items
end
Expand All @@ -16,14 +16,11 @@ local function showEnvironmentVariables(opts)
opts = opts or {}
pickers.new(opts, {
prompt_title = "Environment Variables",
finder = finders.new_table {
finder = finders.new_table({
results = prepareEnvironmentVariables(),
entry_maker = function(entry)
local cols = vim.o.columns
local width = conf.width
or conf.layout_config.width
or conf.layout_config[conf.layout_strategy].width
or cols
local width = conf.width or conf.layout_config.width or conf.layout_config[conf.layout_strategy].width or cols
local tel_win_width
if width > 1 then
tel_win_width = width
Expand All @@ -34,32 +31,29 @@ local function showEnvironmentVariables(opts)
local command_width = 22

-- NOTE: the width calculating logic is not exact, but approx enough
local displayer = entry_display.create {
local displayer = entry_display.create({
separator = "",
items = {
{ width = command_width },
{ width = tel_win_width - desc_width - command_width },
{ remaining = true },
},
}
})

local function make_display(ent)
return displayer
{
return displayer({
{ entry[1] },
{ entry[2] },
}
})
end

return
{
return {
value = entry,
display = make_display,
ordinal = string.format('%s %s', entry[1], entry[2])
display = make_display,
ordinal = string.format("%s %s", entry[1], entry[2]),
}
end,

},
}),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
Expand All @@ -74,9 +68,9 @@ local function run()
showEnvironmentVariables()
end

return require('telescope').register_extension {
return require("telescope").register_extension({
exports = {
-- Default when to argument is given, i.e. :Telescope env
env = run,
}
}
},
})

0 comments on commit a0824a5

Please sign in to comment.