Skip to content

Instantly share code, notes, and snippets.

@krymtkts
Created January 18, 2018 04:19
Show Gist options
  • Save krymtkts/5728d9c03005c0ce917b2dbcc613e0c2 to your computer and use it in GitHub Desktop.
Save krymtkts/5728d9c03005c0ce917b2dbcc613e0c2 to your computer and use it in GitHub Desktop.
my NYAGOS settings.
-- This is a sample .nyagos written with Lua.
-- Edit and put it on %USERPROFILE%, %HOME% or the same folder with nyagos.exe
-- prompt options.
share.prompt = {
eq='$q', -- equal '='
dollar='$$', -- dollar '$'
time='$t', -- current time
date='$d', -- current date
path='$p', -- current path (with drive letter)
ver='$v', -- windows version
drive='$n', -- current drive letter
gt='$g', -- greater than '>'
lt='$l', -- less than '<'
pipe='$b', -- pipe '|'
crlf='$_', -- line break
esc='$e', -- escape
bs='$h', -- backspace
amp='$a', -- ampersand '&'
l_par='$c', -- left parenthesis '('
r_par='$f', -- right parenthesis ')'
space='$s', -- space
}
share.escape_sequence = {
-- attribute
attr = {
off='0',
bold='1',
bold_off='21',
underline='4',
underline_off='24',
blink='5',
blink_off='25'
},
-- foreground
fg = {
black='30',
red='31',
green='32',
yellow='33',
blue='34',
magenta='35',
cyan='36',
white='37',
default='39',
-- prefix 'l' is 'Light'
l_gray='90',
l_red='91',
l_green='92',
l_yellow='93',
l_blue='94',
l_magenta='95',
l_cyan='96',
l_white='97'
},
-- background
bg = {
black='40',
red='41',
green='42',
yellow='43',
blue='44',
magenta='45',
cyan='46',
white='47',
default='49',
-- prefix 'l' is 'Light'
l_gray='100',
l_red='101',
l_green='102',
l_yellow='103',
l_blue='104',
l_magenta='105',
l_cyan='106',
l_white='107'
},
create_sequence = function(...)
local attrs = {...}
local joined_attrs = ''
for n, v in pairs(attrs) do
local val = tostring(v)
if val ~= nil then
joined_attrs = joined_attrs ~= ''
and joined_attrs .. ';' .. val
or val
end
end
return string.format('\x1b[%sm', joined_attrs)
end
}
-- Simple Prompt for CMD.EXE
nyagos.env.prompt='$L'.. nyagos.getenv('COMPUTERNAME') .. ':$P$G$_$$$s'
-- escape original prompt.
share.org_prompter=nyagos.prompt
-- Coloring Prompt for NYAGOS.exe
nyagos.prompt = function(this)
-- local wd = nyagos.getwd()
-- local env = nyagos.env
-- local home = env.home or env.userprofile
-- local home_len = home:len()
local prompt = share.prompt
local esc = share.escape_sequence
-- add dir name (with drive letter)
local dir_color = esc.create_sequence(esc.attr.bold, esc.fg.green)
local prompt_message = string.format('%s[%s]', dir_color, prompt.path)
-- add git branch name if current is git branch
local git_branch_name = nyagos.eval('git rev-parse --abbrev-ref HEAD 2>nul')
if (git_branch_name ~= '') then
local branch_color = esc.create_sequence(esc.fg.yellow)
prompt_message = string.format(prompt_message .. ' %s[%s]', branch_color, git_branch_name)
end
-- add datetime
local datetime_color = esc.create_sequence(esc.fg.l_yellow)
prompt_message = prompt_message .. prompt.space
.. datetime_color .. prompt.l_par .. prompt.date .. prompt.space .. prompt.time .. prompt.r_par
-- add line break
prompt_message = prompt_message .. prompt.crlf
-- add lambda
local prompt_color
if nyagos.elevated() then
prompt_color = esc.create_sequence(esc.fg.magenta)
else
prompt_color = esc.create_sequence(esc.fg.cyan)
end
prompt_message = prompt_message .. prompt_color .. 'λ'
-- add input command color
local c_input_command = esc.create_sequence(esc.fg.white)
prompt_message = string.format(prompt_message .. ' %s', c_input_command)
return share.org_prompter(prompt_message)
end
-- vim:set ft=lua: --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment