summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-01-04 09:53:08 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-01-04 09:53:08 +0800
commit5852b8d8865800b128d8dea5af453b2a975a9807 (patch)
tree4fa869f29fc13eb35533e31f2b130f7e62e17e01
parent30a5667bd8a39db3cae781ad9d3d26a9383ec83b (diff)
downloadlua-language-server-5852b8d8865800b128d8dea5af453b2a975a9807.zip
close #335 supports `~` in command line
-rw-r--r--changelog.md3
-rw-r--r--main.lua18
2 files changed, 18 insertions, 3 deletions
diff --git a/changelog.md b/changelog.md
index 273024d5..885ab0c3 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,8 @@
# changelog
+## 1.9.1
+* `CHG` supports `~` in command line
+
## 1.9.0
`2020-12-31`
* `NEW` YEAR! Peace and love!
diff --git a/main.lua b/main.lua
index 9fd1794d..9bbd8a1f 100644
--- a/main.lua
+++ b/main.lua
@@ -2,7 +2,18 @@ local currentPath = debug.getinfo(1, 'S').source:sub(2)
local rootPath = currentPath:gsub('[/\\]*[^/\\]-$', '')
loadfile((rootPath == '' and '.' or rootPath) .. '/platform.lua')('script')
local fs = require 'bee.filesystem'
-ROOT = fs.path(rootPath)
+
+local function expanduser(path)
+ if path:sub(1, 1) == '~' then
+ local home = os.getenv('HOME')
+ if not home then -- has to be Windows
+ home = os.getenv 'USERPROFILE' or (os.getenv 'HOMEDRIVE' .. os.getenv 'HOMEPATH')
+ end
+ return home .. path:sub(2)
+ else
+ return path
+ end
+end
local function loadArgs()
for _, v in ipairs(arg) do
@@ -22,8 +33,9 @@ end
loadArgs()
-LOGPATH = LOGPATH or (ROOT:string() .. '/log')
-METAPATH = METAPATH or (ROOT:string() .. '/meta')
+ROOT = fs.path(expanduser(rootPath))
+LOGPATH = LOGPATH and expanduser(LOGPATH) or (ROOT:string() .. '/log')
+METAPATH = METAPATH and expanduser(METAPATH) or (ROOT:string() .. '/meta')
debug.setcstacklimit(200)
collectgarbage('generational', 10, 100)