Skip to content

Commit

Permalink
close #335 supports ~ in command line
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jan 4, 2021
1 parent 30a5667 commit 5852b8d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions 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!
Expand Down
18 changes: 15 additions & 3 deletions main.lua
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 5852b8d

Please sign in to comment.