NYAOS.ORG

Nihongo Yet Another {OS/2|OSes|Open|GOing} Shell's support site

What powered by Lua

Table-like objects

  • nyaos.alias
  • nyaos.option
  • nyaos.suffix
  • nyaos.folder
  • nyaos.argv

nyaos.XXXXX is the interface of ''XXXXX'.

lua_e "
    nyaos.alias['cp'] = 'cmd /c copy'
    print('cp='..nyaos.alias['cp'])
    for key,val in pairs(nyaos.alias) do
        print(key..'='..val)
    end
"

History/dirstack object

  • nyaos.history
    • which is the interface for history
  • nyaos.dirstack
    • whici is the interface for pushd/popd/dirs
lua_e "
  local h=nyaos.history
  for i=1,#h do
    print(i,h[i])
  end
"
lua_e "for i,e in ipairs(nyaos.history) do print(i,e) end"

add string to history

nyaos.history:add('hogehoge')

drop string from history

nyaos.history:drop()

Calling Lua functions as an internal command in nyaos

nyaos.command.xxxxx

When called with

    COMMANDNAME X Y Z > foo.txt

Lua function is called like:

    nyaos.command.COMMANDNAME('X','Y','Z')

and redirected to 'foo.txt'.

nyaos.command2.yyyyyyyy

When called with

    COMMANDNAME X Y Z > foo.txt

Lua function is called like:

    nyaos.command2.COMMANDNAME('X Y Z > foo.txt')

Lua's return value of function is translated as below

  • Number => not changed
  • false => 1
  • true,nil,others => 0

Command-line filter

The function nyaos.filter can rewrite the text user input on command-line.

Example in _nya:

lua_e "
    function nyaos.filter(cmdline)
        return cmdline:gsub('%%(%b())',function(m)
            return loadstring('return '..m)()
        end)
    end
"

you can do:

[c:nyaos3k]
$ echo %(1+2+3)
6

nyaos.filter2 is like nyaos.filter but its parameter is the commandline after alias and suffix are extracted.

Keyboard-hook

NYAOS calls the function nyaos.keyhook everytime user types key.

Example in _nya:

lua_e "
    function nyaos.keyhook(t)
        if t.key == nyaos.key.ESCAPE and t.text == '' then
            return os.getenv('EDITOR') or 'notepad',true
        end
        return nil
    end
"

When command-line is empty , your favorite editor raise with ESCAPE-Key typing.

The function nyaos.keyhook's spec is below

  • Arguments:
    • t.key : keycode
    • t.text : commandline-text
    • t.pos : cursor's position on text
  • return values:
    • nil : no effort. nyaos nterprets only user-typed-key.
    • string : insert it into cursor's position
    • integer : interpret it as key-code
    • true : same as ENTER
    • false : same as Ctrl-C

Key-code constants

Please check with the below code:

lua_e "
    for key,val in pairs(nyaos.key) do 
        print('nyaos.key.'..key..'='..val)
    end
"

Hook at exit

Defined nyaos.goodbye, NYAOS calls it at exit.

for instance:

    lua_e "nyaos.goodbye = function() print 'GOOD-BYE' end"

Completion Hook

    function nyaos.complete(BASESTRING,POSITION,MISC)
        :
        return LIST
    end
  • BASESTRING
    • The string to be completed when TAB is typed.
  • POSITION
    • The postion of BASESTRING on the command-line. Then it is 0 , completion should include command names.
  • MISC
    • MISC.text
      • All the command-line string
    • MISC.cursor
      • The postion of cursor.
  • LIST
    • return-value.
      • LIST[n][1] or LIST[n]
        • string for completion
      • LIST[n][2]
        • string for listing

for instance:

    lua_e "
        function nyaos.complete(basestring,n)
            local list = nyaos.default_complete(basestring,n)
            table.insert( list , '127.0.0.1' )
            table.insert( list , 'localhost' ) 
            return list
        end
    "

nyaos.default_complete is built-in function which does NYAOS's default completion.

nyaos.default_complete always returns

    {
        { "FULLPATH-1" , "FILENAME-1 without DIRECTORY" } ,
        { "FULLPATH-2" , "FILENAME-2 without DIRECTORY" } ,
        { "FULLPATH-3" , "FILENAME-3 without DIRECTORY" } ,
        { "FULLPATH-4" , "FILENAME-4 without DIRECTORY" } ,
    }

nyaos.default_complete does not use the third argument.

Tools

nyaos.getkey() - get keycode typed

    lua_e "print(nyaos.getkey())"

nyaos.goodbye() - hook at exit

    lua_e "nyaos.goodbye = function() print 'SAYONARA' end"

nyaos.rcfname - current runnning codefilename

In _nya :

    print('Loading ' .. nyaos.rcfname)

Execute NYAOS-command in Lua-code

lua_e "nyaos.exec('ls -l')"

Test whether the file exists or not.

lua_e "print( nyaos.access('_nya',0) )"

Quote NYAOS-command output

    lua_e "
        local quote=nyaos.eval('ls -1')
        for fn in string.gmatch(quote,'[^\n]+') do 
            print(fn) 
        end
    "

Test file existance.

lua_e "print( nyaos.access('_nya',0) )"

Reading directory

lua_e "
  for filename in nyaos.dir('c:/') do
    print(filename)
  end
"

Change the current working directory

lua_e "
  nyaos.chdir('..')
"

Bit operation.

lua_e "
   print(nyaos.bitand(1,2))
   print(nyaos.bitor(1,2))
   print(nyaos.bitxor(1,2))
   print(nyaos.rshift(8,1))
   print(nyaos.lshift(8,1))
"

option as the front end of Lua interpretor.

one-liner Lua code

nyaos -E "lua-code...." arg1 arg2 arg3...

Interactive shell does not start.

execute lua-script

nyaos -F lua-script-file arg1 arg2 arg3...

Interactive shell does not start.