2 -- ion/query/mod_query_chdir.lua
4 -- Copyright (c) Tuomo Valkonen 2004-2009.
6 -- See the included file LICENSE for details.
9 local function simplify_path(path
)
10 local npath
=string.gsub(path
, "([^/]+)/+%.%./+", "")
12 return simplify_path(npath
)
14 return string.gsub(string.gsub(path
, "([^/]+)/+%.%.$", ""), "/+", "/")
18 local function relative_path(path
)
19 return not string.find(path
, "^/")
22 local function empty_path(path
)
23 return (not path
or path
=="")
26 local function ws_chdir(mplex
, params
)
29 ws
=assert(ioncore
.find_manager(mplex
, "WGroupWS"))
31 if not empty_path(nwd
) and relative_path(nwd
) then
32 local owd
=ioncore
.get_dir_for(ws
)
33 if empty_path(owd
) then
40 local ok
, err
=ioncore
.chdir_for(ws
, nwd
and simplify_path(nwd
))
42 mod_query
.warn(mplex
, err
)
46 local function ws_showdir(mplex
, params
)
47 local dir
=ioncore
.get_dir_for(mplex
)
48 if empty_path(dir
) then
51 mod_query
.message(mplex
, dir
or "(?)")
54 mod_query
.defcmd("cd", ws_chdir
)
55 mod_query
.defcmd("pwd", ws_showdir
)