mirror of
https://github.com/Hilbis/Hilbish
synced 2025-04-21 04:53:24 +00:00
Compare commits
3 Commits
149d3244e0
...
1cb9a60539
Author | SHA1 | Date | |
---|---|---|---|
1cb9a60539 | |||
c969f5ed15 | |||
eded38c7b5 |
@ -1,6 +1,9 @@
|
||||
# 🎀 Changelog
|
||||
|
||||
## Unreleased
|
||||
### Added
|
||||
- Forward/Right arrow key will fill in hint text (#327)
|
||||
|
||||
### Fixed
|
||||
- Skip over file and prevent panic if info cannot be retrieved during file completion (due to permission error or anything else)
|
||||
|
||||
|
@ -1,3 +1,23 @@
|
||||
local fs = require 'fs'
|
||||
|
||||
-- explanation: this specific function gives to us info about
|
||||
-- the currently running source. this includes a path to the
|
||||
-- source file (info.source)
|
||||
-- we will use that to automatically load all commands by reading
|
||||
-- all the files in this dir and just requiring it.
|
||||
local info = debug.getinfo(1)
|
||||
local commandDir = fs.dir(info.source)
|
||||
if commandDir == '.' then return end
|
||||
|
||||
local commands = fs.readdir(commandDir)
|
||||
for _, command in ipairs(commands) do
|
||||
local name = command:gsub('%.lua', '') -- chop off extension
|
||||
if name ~= 'init' then
|
||||
-- skip this file (for obvious reasons)
|
||||
require('nature.completions.' .. name)
|
||||
end
|
||||
end
|
||||
|
||||
function hilbish.completion.handler(line, pos)
|
||||
if type(line) ~= 'string' then error '#1 must be a string' end
|
||||
if type(pos) ~= 'number' then error '#2 must be a number' end
|
53
nature/completions/sudo.lua
Normal file
53
nature/completions/sudo.lua
Normal file
@ -0,0 +1,53 @@
|
||||
local function curry(f)
|
||||
return function (x) return function (y) return f(x,y) end end
|
||||
end
|
||||
|
||||
local flags = {}
|
||||
local function flag(f, description)
|
||||
flags[f] = {description}
|
||||
end
|
||||
|
||||
local addflag = curry(flag)
|
||||
|
||||
addflag '-A' 'Ask for password via askpass or $SUDO_ASKPASS'
|
||||
addflag '-B' 'Ring the bell as part of the password prompt.'
|
||||
|
||||
hilbish.complete('command.sudo', function(query, ctx, fields)
|
||||
table.remove(fields, 1)
|
||||
local nonflags = table.filter(fields, function(v)
|
||||
if v == '' then
|
||||
return false
|
||||
end
|
||||
return v:match '^%-' == nil
|
||||
end)
|
||||
|
||||
if #fields == 1 or #nonflags == 0 then
|
||||
-- complete commands or sudo flags
|
||||
if query:match ('^%-') then
|
||||
local compFlags = {}
|
||||
for flg, flgstuff in pairs(flags) do
|
||||
if flg:match('^' .. query) then
|
||||
compFlags[flg] = flgstuff
|
||||
end
|
||||
end
|
||||
|
||||
local compGroup = {
|
||||
items = compFlags,
|
||||
type = 'list'
|
||||
}
|
||||
|
||||
return {compGroup}, query
|
||||
end
|
||||
|
||||
local comps, pfx = hilbish.completion.bins(query, ctx, fields)
|
||||
local compGroup = {
|
||||
items = comps,
|
||||
type = 'grid'
|
||||
}
|
||||
|
||||
return {compGroup}, pfx
|
||||
end
|
||||
|
||||
-- otherwise, get command flags
|
||||
return hilbish.completion.call('command.' .. fields[2], query, ctx, fields)
|
||||
end)
|
@ -56,3 +56,10 @@ func (rl *Instance) resetHintText() {
|
||||
//rl.hintY = 0
|
||||
rl.hintText = []rune{}
|
||||
}
|
||||
|
||||
func (rl *Instance) insertHintText() {
|
||||
if len(rl.hintText) != 0 {
|
||||
// fill in hint text
|
||||
rl.insert(rl.hintText)
|
||||
}
|
||||
}
|
||||
|
@ -707,6 +707,9 @@ func (rl *Instance) escapeSeq(r []rune) {
|
||||
rl.renderHelpers()
|
||||
return
|
||||
}
|
||||
|
||||
rl.insertHintText()
|
||||
|
||||
if (rl.modeViMode == VimInsert && rl.pos < len(rl.line)) ||
|
||||
(rl.modeViMode != VimInsert && rl.pos < len(rl.line)-1) {
|
||||
rl.moveCursorByAdjust(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user