2019-06-28 17:50:02 +00:00
|
|
|
local Config = require('opus.config')
|
|
|
|
local UI = require('opus.ui')
|
2018-12-23 03:11:16 +00:00
|
|
|
|
2019-04-07 14:09:47 +00:00
|
|
|
local kernel = _G.kernel
|
|
|
|
|
2019-01-30 20:11:41 +00:00
|
|
|
local aliasTab = UI.Tab {
|
2018-12-23 03:11:16 +00:00
|
|
|
tabTitle = 'Aliases',
|
|
|
|
description = 'Shell aliases',
|
|
|
|
alias = UI.TextEntry {
|
|
|
|
x = 2, y = 2, ex = -2,
|
|
|
|
limit = 32,
|
|
|
|
shadowText = 'Alias',
|
|
|
|
},
|
|
|
|
path = UI.TextEntry {
|
|
|
|
y = 3, x = 2, ex = -2,
|
|
|
|
limit = 256,
|
|
|
|
shadowText = 'Program path',
|
|
|
|
accelerators = {
|
|
|
|
enter = 'new_alias',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
grid = UI.Grid {
|
2020-03-31 15:57:23 +00:00
|
|
|
x = 2, y = 5, ex = -2, ey = -2,
|
2018-12-23 03:11:16 +00:00
|
|
|
sortColumn = 'alias',
|
|
|
|
columns = {
|
|
|
|
{ heading = 'Alias', key = 'alias' },
|
|
|
|
{ heading = 'Program', key = 'path' },
|
|
|
|
},
|
|
|
|
accelerators = {
|
|
|
|
delete = 'delete_alias',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
function aliasTab.grid:draw()
|
|
|
|
self.values = { }
|
|
|
|
local env = Config.load('shell')
|
2019-04-07 14:09:47 +00:00
|
|
|
for k in pairs(kernel.getShell().aliases()) do
|
|
|
|
kernel.getShell().clearAlias(k)
|
|
|
|
end
|
2018-12-23 03:11:16 +00:00
|
|
|
for k,v in pairs(env.aliases) do
|
|
|
|
table.insert(self.values, { alias = k, path = v })
|
2019-04-07 14:09:47 +00:00
|
|
|
kernel.getShell().setAlias(k, v)
|
2018-12-23 03:11:16 +00:00
|
|
|
end
|
|
|
|
self:update()
|
|
|
|
UI.Grid.draw(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
function aliasTab:eventHandler(event)
|
|
|
|
if event.type == 'delete_alias' then
|
2019-04-07 14:09:47 +00:00
|
|
|
local env = Config.load('shell', { aliases = { } })
|
2018-12-23 03:11:16 +00:00
|
|
|
env.aliases[self.grid:getSelected().alias] = nil
|
2019-04-07 14:09:47 +00:00
|
|
|
Config.update('shell', env)
|
2018-12-23 03:11:16 +00:00
|
|
|
self.grid:setIndex(self.grid:getIndex())
|
|
|
|
self.grid:draw()
|
2019-04-07 14:09:47 +00:00
|
|
|
self:emit({ type = 'success_message', message = 'Aliases updated' })
|
2018-12-23 03:11:16 +00:00
|
|
|
return true
|
|
|
|
|
|
|
|
elseif event.type == 'new_alias' then
|
2019-04-07 14:09:47 +00:00
|
|
|
local env = Config.load('shell', { aliases = { } })
|
2018-12-23 03:11:16 +00:00
|
|
|
env.aliases[self.alias.value] = self.path.value
|
2019-04-07 14:09:47 +00:00
|
|
|
Config.update('shell', env)
|
2018-12-23 03:11:16 +00:00
|
|
|
self.alias:reset()
|
|
|
|
self.path:reset()
|
|
|
|
self:draw()
|
|
|
|
self:setFocus(self.alias)
|
2019-04-07 14:09:47 +00:00
|
|
|
self:emit({ type = 'success_message', message = 'Aliases updated' })
|
2018-12-23 03:11:16 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return aliasTab
|