From 5852b8d8865800b128d8dea5af453b2a975a9807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 4 Jan 2021 09:53:08 +0800 Subject: close #335 supports `~` in command line --- changelog.md | 3 +++ main.lua | 18 +++++++++++++++--- 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) -- cgit v1.2.3