allow .shrc to use tty stdin

This commit is contained in:
payonel 2017-11-16 18:40:58 -08:00
parent 5107afb176
commit f26cb54c28
2 changed files with 16 additions and 9 deletions

View File

@ -17,13 +17,20 @@ if not file then
return 1
end
local current_data = process.info().data
local lines = file:lines()
local source_proc = process.load((assert(os.getenv("SHELL"), "no $SHELL set")))
local source_data = process.list[source_proc].data
source_data.aliases = current_data.aliases -- hacks to propogate sub shell env changes
source_data.vars = current_data.vars
source_data.io[0] = file -- set stdin to the file
process.internal.continue(source_proc, "-c")
while true do
local line = lines()
if not line then
break
end
local current_data = process.info().data
local source_proc = process.load((assert(os.getenv("SHELL"), "no $SHELL set")))
local source_data = process.list[source_proc].data
source_data.aliases = current_data.aliases -- hacks to propogate sub shell env changes
source_data.vars = current_data.vars
process.internal.continue(source_proc, _ENV, line)
end
file:close() -- should have closed when the process closed, but just to be sure
file:close()

View File

@ -38,6 +38,6 @@ os.setenv("LS_COLORS", "di=0;36:fi=0:ln=0;33:*.lua=0;32")
shell.setWorkingDirectory(os.getenv("HOME"))
local home_shrc = shell.resolve(".shrc")
if fs.exists(home_shrc) then
if fs.size(home_shrc) > 0 then
loadfile(shell.resolve("source", "lua"))(home_shrc)
end