Merge pull request #1736 from blueyed/completion-zsh-nullglob

awful.completion: zsh: fix command completion from PWD
This commit is contained in:
Daniel Hahler 2017-06-27 08:01:46 +02:00 committed by GitHub
commit 6d5cf6cdbb
3 changed files with 73 additions and 8 deletions

View File

@ -40,8 +40,8 @@ install:
# See also `apt-cache showsrc awesome | grep -E '^(Version|Build-Depends)'`.
- sudo apt-get install -y libcairo2-dev gir1.2-gtk-3.0 xmlto asciidoc libpango1.0-dev libxcb-xtest0-dev libxcb-icccm4-dev libxcb-randr0-dev libxcb-keysyms1-dev libxcb-xinerama0-dev libdbus-1-dev libxdg-basedir-dev libstartup-notification0-dev imagemagick libxcb1-dev libxcb-shape0-dev libxcb-util0-dev libx11-xcb-dev libxcb-cursor-dev libxcb-xkb-dev libxkbcommon-dev libxkbcommon-x11-dev
# Deps for functional tests.
- sudo apt-get install -y dbus-x11 xterm xdotool xterm xvfb
# Deps for tests.
- sudo apt-get install -y dbus-x11 xterm xdotool xterm xvfb zsh
# Need xorg-macros
- sudo apt-get install -y xutils-dev

View File

@ -93,7 +93,7 @@ function completion.shell(command, cur_pos, ncomp, shell)
i = i + 1
end
if cword_index == 1 and not string.find(words[cword_index], "/") then
if cword_index == 1 then
comptype = "command"
end
@ -103,15 +103,17 @@ function completion.shell(command, cur_pos, ncomp, shell)
-- NOTE: ${~:-"..."} turns on GLOB_SUBST, useful for expansion of
-- "~/" ($HOME). ${:-"foo"} is the string "foo" as var.
shell_cmd = "/usr/bin/env zsh -c 'local -a res; res=( ${~:-"
.. string.format('%q', words[cword_index]) .. "}* ); "
.. string.format('%q', words[cword_index]) .. "}*(N) ); "
.. "print -ln -- ${res[@]}'"
else
-- check commands, aliases, builtins, functions and reswords
shell_cmd = "/usr/bin/env zsh -c 'local -a res; "..
-- Check commands, aliases, builtins, functions and reswords.
-- Adds executables and non-empty dirs from $PWD (pwd_exe).
shell_cmd = "/usr/bin/env zsh -c 'local -a res pwd_exe; "..
"pwd_exe=(*(N*:t) *(NF:t)); "..
"res=( "..
"\"${(k)commands[@]}\" \"${(k)aliases[@]}\" \"${(k)builtins[@]}\" \"${(k)functions[@]}\" "..
"\"${(k)reswords[@]}\" "..
"${PWD}/*(:t)"..
"./${^${pwd_exe}} "..
"); "..
"print -ln -- ${(M)res[@]:#" .. string.format('%q', words[cword_index]) .. "*}'"
end
@ -156,7 +158,7 @@ function completion.shell(command, cur_pos, ncomp, shell)
end
local str = command:sub(1, cword_start - 1) .. output[ncomp] .. command:sub(cword_end)
cur_pos = cword_end + #output[ncomp] + 1
cur_pos = cword_start + #output[ncomp]
return str, cur_pos, output
end

View File

@ -0,0 +1,63 @@
local compl = require("awful.completion")
local shell = function(...)
local command, pos, matches = compl.shell(...)
return {command, pos, matches}
end
local gfs = require("gears.filesystem")
describe("awful.completion.shell in empty directory", function()
local orig_popen = io.popen
setup(function()
gfs.make_directories('/tmp/awesome-tests/empty')
io.popen = function(...) --luacheck: ignore
return orig_popen('cd /tmp/awesome-tests/empty && ' .. ...)
end
end)
teardown(function()
os.remove('/tmp/awesome-tests/empty')
io.popen = orig_popen --luacheck: ignore
end)
it("handles completion of true", function()
assert.same(shell('true', 5, 1, 'zsh'), {'true', 5, {'true'}})
assert.same(shell('true', 5, 1, 'bash'), {'true', 5, {'true'}})
assert.same(shell('true', 5, 1, nil), {'true', 5, {'true'}})
end)
end)
describe("awful.completion.shell", function()
local orig_popen = io.popen
setup(function()
gfs.make_directories('/tmp/awesome-tests/dir')
os.execute('cd /tmp/awesome-tests/dir && touch localcommand && chmod +x localcommand')
io.popen = function(...) --luacheck: ignore
return orig_popen('cd /tmp/awesome-tests/dir && ' .. ...)
end
end)
teardown(function()
os.remove('/tmp/awesome-tests/dir')
io.popen = orig_popen --luacheck: ignore
end)
it("handles empty input", function()
assert.same(shell('', 1, 1, 'zsh'), {'', 1})
assert.same(shell('', 1, 1, 'bash'), {'', 1})
assert.same(shell('', 1, 1, nil), {'', 1})
end)
it("completes local command", function()
assert.same(shell('./localcomm', 12, 1, 'zsh'), {'./localcommand', 15, {'./localcommand'}})
assert.same(shell('./localcomm', 12, 1, 'bash'), {'./localcommand', 15, {'./localcommand'}})
end)
it("completes local file", function()
assert.same(shell('ls ', 4, 1, 'zsh'), {'ls localcommand', 16, {'localcommand'}})
assert.same(shell('ls ', 4, 1, 'bash'), {'ls localcommand', 16, {'localcommand'}})
end)
end)
-- vim: ft=lua:et:sw=4:ts=8:sts=4:tw=80