shellex: fix aliasing and colorize grep

This commit is contained in:
kepler155c@gmail.com
2019-05-13 09:30:27 -04:00
parent 9f3070bbdc
commit 180f0f9b93
5 changed files with 132 additions and 26 deletions

View File

@@ -8,12 +8,23 @@ local cmap = {
[ 0x44CC00 ] = colors.lime,
[ 0xB0B00F ] = colors.yellow,
[ 0xFFFFFF ] = colors.white,
[ 0xb000b0 ] = colors.purple,
[ 0x00FF00 ] = colors.green,
[ 0xFF0000 ] = colors.red,
[ 0x00FFFF ] = colors.cyan,
[ 0x000000 ] = colors.black,
}
return {
gpu = function()
local current = 0xFFFFFF
return {
setForeground = function(c) term.setTextColor(cmap[c]) end,
setForeground = function(c)
current = c
term.setTextColor(cmap[c])
end,
getForeground = function() return current end,
}
end,
getViewport = term.getSize,

View File

@@ -1,6 +1,4 @@
local Config = require('config')
local kernel = _G.kernel
local fs = _G.fs
local os = _G.os
local settings = _G.settings
@@ -13,12 +11,7 @@ function os.getenv(k)
return settings.get(k)
end
local config = Config.load('shell', { aliases = { } })
if not config.openOsInit then
config.openOsInit = true
for _, alias in pairs({ 'ls', 'rm', 'cp', 'mv' }) do
config.aliases[alias] = nil
kernel.getShell().clearAlias(alias)
end
Config.update('shell', config)
end
fs.mount('rom/programs/list.lua', 'linkfs', 'packages/shellex/ls.lua')
fs.mount('rom/programs/delete.lua', 'linkfs', 'packages/shellex/rm.lua')
fs.mount('rom/programs/copy.lua', 'linkfs', 'packages/shellex/cp.lua')
fs.mount('rom/programs/move.lua', 'linkfs', 'packages/shellex/mv.lua')

View File

@@ -40,7 +40,7 @@ end
local LABEL_COLOR = 0xb000b0
local LINE_NUM_COLOR = 0x00FF00
local MATCH_COLOR = 0xFF0000
local MATCH_COLOR = 0xB0B00F
local COLON_COLOR = 0x00FFFF
local function pop(...)
@@ -115,7 +115,7 @@ local quiet = pop('q','quiet','silent')
local print_count = pop('c','count')
local colorize = pop('color','colour') and io.output().tty and tty.isAvailable()
colorize = true
local noop = function(...)return ...;end
local setc = colorize and gpu.setForeground or noop
local getc = colorize and gpu.getForeground or noop
@@ -203,13 +203,19 @@ local function readLines()
meta.label = file
local file, reason = resolve(file)
if fs.exists(file) then
curHand, reason = io.open(file, 'r')
if not curHand then
local msg = string.format("failed to read from %s: %s", meta.label, reason)
if fs.isDirectory(file) then
local msg = string.format("%s: Is a directory", meta.label)
stderr:write("grep: ",msg,"\n")
return false, 2
else
curFile = meta.label
curHand, reason = io.open(file, 'r')
if not curHand then
local msg = string.format("failed to read from %s: %s", meta.label, reason)
stderr:write("grep: ",msg,"\n")
return false, 2
else
curFile = meta.label
end
end
else
stderr:write("grep: ",file,": file not found\n")