diff options
Diffstat (limited to '')
-rwxr-xr-x | _.lua | 37 |
1 files changed, 32 insertions, 5 deletions
@@ -59,10 +59,12 @@ _._ = function(c) | |||
59 | self.logging = true | 59 | self.logging = true |
60 | return self | 60 | return self |
61 | end | 61 | end |
62 | |||
62 | function exe:show() | 63 | function exe:show() |
63 | self.showing = true | 64 | self.showing = true |
64 | return self | 65 | return self |
65 | end | 66 | end |
67 | |||
66 | function exe:Nice(c) | 68 | function exe:Nice(c) |
67 | if nil == c then | 69 | if nil == c then |
68 | self.cmd = 'ionice -c3 nice -n 19 ' .. self.cmd | 70 | self.cmd = 'ionice -c3 nice -n 19 ' .. self.cmd |
@@ -71,6 +73,7 @@ _._ = function(c) | |||
71 | end | 73 | end |
72 | return self | 74 | return self |
73 | end | 75 | end |
76 | |||
74 | function exe:timeout(c) | 77 | function exe:timeout(c) |
75 | -- timeout returns a status of - command status if --preserve-status; "128+9" (actually 137) if --kill-after ends up being done; 124 if it had to TERM; command status if all went well. | 78 | -- timeout returns a status of - command status if --preserve-status; "128+9" (actually 137) if --kill-after ends up being done; 124 if it had to TERM; command status if all went well. |
76 | -- --kill-after means "send KILL after TERM fails. | 79 | -- --kill-after means "send KILL after TERM fails. |
@@ -81,33 +84,40 @@ _._ = function(c) | |||
81 | end | 84 | end |
82 | return self | 85 | return self |
83 | end | 86 | end |
84 | function exe:also(c) | 87 | |
88 | function exe:also(c) -- Should be called "then" but that's a reserved word. | ||
85 | if nil == c then c = '' else c = ' ' .. c end | 89 | if nil == c then c = '' else c = ' ' .. c end |
86 | self.cmd = self.cmd .. '; ' .. c .. ' ' | 90 | self.cmd = self.cmd .. '; ' .. c .. ' ' |
87 | return self | 91 | return self |
88 | end | 92 | end |
93 | |||
89 | function exe:And(c) | 94 | function exe:And(c) |
90 | if nil == c then c = '' else c = ' ' .. c end | 95 | if nil == c then c = '' else c = ' ' .. c end |
91 | self.cmd = self.cmd .. ' && ' .. c .. ' ' | 96 | self.cmd = self.cmd .. ' && ' .. c .. ' ' |
92 | return self | 97 | return self |
93 | end | 98 | end |
99 | |||
94 | function exe:Or(c) | 100 | function exe:Or(c) |
95 | if nil == c then c = '' end | 101 | if nil == c then c = '' end |
96 | self.cmd = self.cmd .. ' || ' .. c .. ' ' | 102 | self.cmd = self.cmd .. ' || ' .. c .. ' ' |
97 | return self | 103 | return self |
98 | end | 104 | end |
105 | |||
99 | function exe:noErr() | 106 | function exe:noErr() |
100 | self.cmd = self.cmd .. ' 2>/dev/null ' | 107 | self.cmd = self.cmd .. ' 2>/dev/null ' |
101 | return self | 108 | return self |
102 | end | 109 | end |
110 | |||
103 | function exe:noOut() | 111 | function exe:noOut() |
104 | self.cmd = self.cmd .. ' 1>/dev/null ' | 112 | self.cmd = self.cmd .. ' 1>/dev/null ' |
105 | return self | 113 | return self |
106 | end | 114 | end |
115 | |||
107 | function exe:wait(w) | 116 | function exe:wait(w) |
108 | self.cmd = self.cmd .. ' && touch ' .. w .. ' ' | 117 | self.cmd = self.cmd .. ' && touch ' .. w .. ' ' |
109 | return self | 118 | return self |
110 | end | 119 | end |
120 | |||
111 | function exe:Do() | 121 | function exe:Do() |
112 | --[[ "The condition expression of a control structure can return any | 122 | --[[ "The condition expression of a control structure can return any |
113 | value. Both false and nil are considered false. All values different | 123 | value. Both false and nil are considered false. All values different |
@@ -135,23 +145,40 @@ _._ = function(c) | |||
135 | end | 145 | end |
136 | return self | 146 | return self |
137 | end | 147 | end |
148 | |||
138 | function exe:fork(host) | 149 | function exe:fork(host) |
139 | if nil ~= host then self.cmd = self.cmd .. '; r=$?; if [ $r -ge 124 ]; then echo "$r ' .. host .. ' failed forked command ' .. string.gsub(self.cmd, '"', "'") .. '"; fi' end | 150 | -- if nil ~= host then self.cmd = self.cmd .. '; r=$?; if [ $r -ge 124 ]; then echo "$r ' .. host .. ' failed forked command ' .. string.gsub(self.cmd, '"', "'") .. '"; fi' end |
140 | self.cmd = '{ ' .. self.cmd .. ' ; } & ' | 151 | self.cmd = '{ ' .. self.cmd .. ' ; } & ' |
141 | if true == self.logging then D(" forking - " .. self.cmd) end | 152 | if true == self.logging then D(" forking - " .. self.cmd) end |
142 | os.execute(self.cmd) | 153 | os.execute(self.cmd) |
143 | return self | 154 | return self |
144 | end | 155 | end |
156 | |||
157 | function exe:forkOnce() | ||
158 | if _.running(self.command) then | ||
159 | D('Already running ' .. self.command) | ||
160 | else | ||
161 | self:fork() | ||
162 | end | ||
163 | end | ||
164 | |||
145 | return exe | 165 | return exe |
146 | end | 166 | end |
167 | |||
147 | local __ = _._ | 168 | local __ = _._ |
148 | 169 | ||
170 | _.runnable = function(c) | ||
171 | return ( 0 == __('which ' .. c):Do().status ) | ||
172 | end | ||
149 | 173 | ||
150 | _.exists = function(c) | 174 | _.running = function(c) |
151 | if 0 == __('which ' .. c):Do().status then return true end | 175 | return ( 1 ~= tonumber(__("pgrep -u $USER -cf " .. c):Do().lines[1]) ) |
152 | return false | ||
153 | end | 176 | end |
154 | 177 | ||
178 | _.exists = function(f) | ||
179 | local h, e = io.open(f, "r") | ||
180 | if nil == h then return false else h:close(); return true end | ||
181 | end | ||
155 | 182 | ||
156 | _.killEmAll = function(all) | 183 | _.killEmAll = function(all) |
157 | for i,l in ipairs(all) do | 184 | for i,l in ipairs(all) do |