Skip to content

Commit 2542929

Browse files
authored
feat: config option for custom environment variables file (#83)
1 parent 759bf5b commit 2542929

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ use {
7676
},
7777
-- Jump to request line on run
7878
jump_to_request = false,
79+
env_file = '.env'
7980
})
8081
end
8182
}
@@ -105,12 +106,13 @@ To run `rest.nvim` you should map the following commands:
105106

106107
## Settings
107108

108-
- `result_split_horizontal` opens result on a horizontal split (default opens
109+
- `result_split_horizontal` opens result on a horizontal split (default opens
109110
on vertical)
110111
- `skip_ssl_verification` passes the `-k` flag to cURL in order to skip SSL verification,
111112
useful when using unknown certificates
112113
- `highlight` allows to enable and configure the highlighting of the selected request when send,
113114
- `jump_to_request` moves the cursor to the selected request line when send,
115+
- `env_file` specifies file name that consist environment variables (default: .env)
114116

115117
## Usage
116118

doc/rest-nvim.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function, it looks like this by default:
6363
` },`
6464
` -- Jump to request line on run`
6565
` jump_to_request = false,`
66+
` env_file = '.env'`
6667
`})`
6768

6869
In this section we will be using `https://reqres.in/` for requests.
@@ -144,8 +145,8 @@ ENVIRONMENT VARIABLES *rest-nvim-usage-environment-variables*
144145
To use environment variables, the following syntax is used: `{{VARIABLE_NAME}}`
145146

146147
These environment variables can be obtained from:
148+
- File in the current working directory (env_file in config or '.env')
147149
- System
148-
- `.env` file in the current working directory
149150

150151

151152
===============================================================================

doc/tags

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ rest-nvim-license rest-nvim.txt /*rest-nvim-license*
88
rest-nvim-quick-start rest-nvim.txt /*rest-nvim-quick-start*
99
rest-nvim-usage rest-nvim.txt /*rest-nvim-usage*
1010
rest-nvim-usage-commands rest-nvim.txt /*rest-nvim-usage-commands*
11+
rest-nvim-usage-dynamic-variables rest-nvim.txt /*rest-nvim-usage-dynamic-variables*
1112
rest-nvim-usage-environment-variables rest-nvim.txt /*rest-nvim-usage-environment-variables*
13+
rest-nvim-usage-external-files rest-nvim.txt /*rest-nvim-usage-external-files*
1214
rest-nvim-usage-requests rest-nvim.txt /*rest-nvim-usage-requests*
1315
rest-nvim.txt rest-nvim.txt /*rest-nvim.txt*

lua/rest-nvim/config/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ local config = {
1313
show_headers = true,
1414
},
1515
jump_to_request = false,
16+
env_file = ".env",
1617
}
1718

1819
--- Get a configuration value

lua/rest-nvim/utils/init.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local config = require("rest-nvim.config")
2+
13
local random = math.random
24
math.randomseed(os.time())
35

@@ -45,17 +47,19 @@ M.read_file = function(file)
4547
return lines
4648
end
4749

48-
-- read_env_file Reads the environment variables found in the `.env` file and
49-
-- returns a table with the variables
50+
-- read_env_file Reads the environment variables found in the env_file option
51+
-- (defualt: .env) specified in configuration and returns a table with the
52+
-- variables
5053
M.read_env_file = function()
5154
local variables = {}
55+
local env_file = "/" .. (config.get("env_file") or ".env")
5256

5357
-- Directories to search for env files
5458
local env_file_paths = {
5559
-- current working directory
56-
vim.fn.getcwd() .. "/.env",
60+
vim.fn.getcwd() .. env_file,
5761
-- directory of the currently opened file
58-
vim.fn.expand("%:p:h") .. "/.env",
62+
vim.fn.expand("%:p:h") .. env_file,
5963
}
6064

6165
-- If there's an env file in the current working dir

0 commit comments

Comments
 (0)