completion, util: Check for io.popen failure.
Signed-off-by: Maarten Maathuis <madman2003@gmail.com> Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
6e199bbd76
commit
02e4be93dc
|
@ -9,6 +9,7 @@
|
|||
local io = io
|
||||
local table = table
|
||||
local math = math
|
||||
local print = print
|
||||
|
||||
--- Completion module for awful
|
||||
module("awful.completion")
|
||||
|
@ -26,7 +27,8 @@ keywords = {}
|
|||
-- @param src The bash completion source file, /etc/bash_completion by default.
|
||||
function bashcomp_load(src)
|
||||
if src then bashcomp_src = src end
|
||||
local c = io.popen("/usr/bin/env bash -c 'source " .. bashcomp_src .. "; complete -p'")
|
||||
local c, err = io.popen("/usr/bin/env bash -c 'source " .. bashcomp_src .. "; complete -p'")
|
||||
if c then
|
||||
while true do
|
||||
local line = c:read("*line")
|
||||
if not line then break end
|
||||
|
@ -36,6 +38,9 @@ function bashcomp_load(src)
|
|||
end
|
||||
end
|
||||
c:close()
|
||||
else
|
||||
print(err)
|
||||
end
|
||||
end
|
||||
|
||||
--- Use bash completion system to complete command and filename.
|
||||
|
@ -88,9 +93,10 @@ function bash(command, cur_pos, ncomp)
|
|||
else
|
||||
bash_cmd = "/usr/bin/env bash -c 'compgen -A " .. comptype .. " " .. words[cword_index] .. "'"
|
||||
end
|
||||
local c = io.popen(bash_cmd)
|
||||
local c, err = io.popen(bash_cmd)
|
||||
local output = {}
|
||||
i = 0
|
||||
if c then
|
||||
while true do
|
||||
local line = c:read("*line")
|
||||
if not line then break end
|
||||
|
@ -98,6 +104,9 @@ function bash(command, cur_pos, ncomp)
|
|||
end
|
||||
|
||||
c:close()
|
||||
else
|
||||
print(err)
|
||||
end
|
||||
|
||||
-- no completion, return
|
||||
if #output == 0 then
|
||||
|
|
|
@ -73,10 +73,14 @@ end
|
|||
-- @return A string with the program output.
|
||||
function pread(cmd)
|
||||
if cmd and cmd ~= "" then
|
||||
local f = io.popen(cmd, 'r')
|
||||
local f, err = io.popen(cmd, 'r')
|
||||
if f then
|
||||
local s = f:read("*all")
|
||||
f:close()
|
||||
return s
|
||||
else
|
||||
print(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue