/
view_workdir.lua
61 lines (54 loc) · 2.03 KB
/
view_workdir.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
--
-- Copyright (c) 2008, Bart Trojanowski <bart@jukie.net>
--
-- This plugin binds Mod1-' to create a terminal with the same working
-- directory as the last directory entered on the shell[*] in that view.
--
-- [*] you will have to modify your zshrc or bashrc to generate the
-- "ShellChangeDir" wmii event.
--
-- zshrc:
-- chpwd_functions+='zsh_wmii_chpwd'
-- function zsh_wmii_chpwd () { echo "ShellChangeDir $PWD" | wmiir write /event ; }
--
-- bashrc:
-- function cd () { builtin cd $@ && \
-- ( echo "ShellChangeDir $PWD" | wmiir write /event ) ; }
--
local wmii = require("wmii")
local os = require("os")
local io = require("io")
local math = require("math")
local type = type
local error = error
local tostring = tostring
module("view_workdir")
api_version = 0.1
local view_workdirs = {}
wmii.add_event_handler("ShellChangeDir",
function(ev,arg)
wmii.log("view_workdir: arg is " .. type(arg))
if type(arg) == 'string' then
local view = wmii.get_view()
wmii.log("view_workdir: view is " .. type(view))
if type(view) == 'string' then
wmii.log("view_workdir: view_workdirs["..view.."] = "..arg)
view_workdirs[view] = arg
end
end
end)
wmii.add_key_handler("Mod1-apostrophe",
function (key)
local xterm = wmii.get_conf("xterm") or "xterm"
local cd_cmd = ''
local view = wmii.get_view()
wmii.log("view_workdir: view is " .. type(view))
if type(view) == 'string' then
local dir = view_workdirs[view]
if type(dir) == 'string' then
cd_cmd = "cd '"..dir.."' ; "
end
end
wmii.log (" executing: " .. cd_cmd .. xterm)
os.execute (cd_cmd .. xterm .. " &")
end)