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,16 +27,20 @@ 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'")
|
||||
while true do
|
||||
local line = c:read("*line")
|
||||
if not line then break end
|
||||
-- if a bash function is used for completion, register it
|
||||
if line:match(".* -F .*") then
|
||||
bashcomp_funcs[line:gsub(".* (%S+)$","%1")] = line:gsub(".*-F +(%S+) .*$", "%1")
|
||||
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
|
||||
-- if a bash function is used for completion, register it
|
||||
if line:match(".* -F .*") then
|
||||
bashcomp_funcs[line:gsub(".* (%S+)$","%1")] = line:gsub(".*-F +(%S+) .*$", "%1")
|
||||
end
|
||||
end
|
||||
c:close()
|
||||
else
|
||||
print(err)
|
||||
end
|
||||
c:close()
|
||||
end
|
||||
|
||||
--- Use bash completion system to complete command and filename.
|
||||
|
@ -88,16 +93,20 @@ 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
|
||||
while true do
|
||||
local line = c:read("*line")
|
||||
if not line then break end
|
||||
table.insert(output, line)
|
||||
end
|
||||
if c then
|
||||
while true do
|
||||
local line = c:read("*line")
|
||||
if not line then break end
|
||||
table.insert(output, line)
|
||||
end
|
||||
|
||||
c:close()
|
||||
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 s = f:read("*all")
|
||||
f:close()
|
||||
return s
|
||||
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