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