--
-- ion/share/ioncore_wd.lua
--
--- Copyright (c) Tuomo Valkonen 2004-2006.
+-- Copyright (c) Tuomo Valkonen 2004-2008.
--
--- Ion is free software; you can redistribute it and/or modify it under
--- the terms of the GNU Lesser General Public License as published by
--- the Free Software Foundation; either version 2.1 of the License, or
--- (at your option) any later version.
+-- See the included file LICENSE for details.
--
local savefile="saved_wd"
local dirs={}
-local px
+local lfs
-if pcall(function() return require('posix') end) then
- px=posix
+if pcall(function() return require('lfs') end) then
+ lfs=_G["lfs"]
end
local function checkdir(d)
- if not px then
+ if not lfs then
return true
else
- local t, err=px.stat(d, "type")
+ local t, err=lfs.attributes(d, "mode")
if not t then
return nil, err
- elseif t=="link" then
- local d2, err=px.readlink(d)
- if not d2 then
- return nil, err
- else
- print('follow')
- return checkdir(d2)
- end
elseif t=="directory" then
return true
else
- return TR("Not a directory.")
+ return nil, TR("Not a directory.")
end
end
end
--DOC
-- Change default working directory for new programs started in \var{reg}.
function ioncore.chdir_for(reg, dir)
- assert(type(dir)=="string")
+ assert(dir==nil or type(dir)=="string")
if dir=="" or dir==nil then
dirs[reg]=nil
return true
local function lookup_runinxterm_warn(prog, title, wait)
local rx=lookup_script_warn("ion-runinxterm")
if rx then
+ rx="exec "..rx
if wait then
rx=rx.." -w"
end
cmd='XTERMCMD='..string.shell_safe(XTERM)..' '..cmd
end
end
- return ioncore.do_exec_rw(reg:rootwin_of(), cmd,
- ioncore.get_dir_for(reg),
+ return ioncore.do_exec_on(reg, cmd, ioncore.get_dir_for(reg),
merr_internal)
end
local function save_config()
local t={}
for r, d in pairs(dirs) do
- t[r:name()]=d
+ local nm=obj_exists(r) and r:name()
+ if nm then
+ t[nm]=d
+ end
end
ioncore.write_savefile(savefile, t)
end