# _nya  NYAOS ̏ݒt@Cł.
#   (1) NYAOS.EXE ̂fBNg
#   (2) %HOME% ̉(`ł %USERPROFILE%)
#   (3) JgfBNg
# ɂ _nya uɑSāvĂяo܂.
#  A(1)==(3) ̏ꍇ́A(3)Ăяo܂.
#
# ʏ
#    - NYAOS.EXE ɓYt _nya (t@C)  (1) 
#    - ̃[UŒ`ݒ (2) 
# zuĂ.

suffix ny  %nyatype% -f
suffix pl  perl
suffix py  python
suffix rb  ruby
suffix jar java -jar
suffix lua lua
suffix awk awk -f
suffix vbs cscript
suffix js  cscript

option +backquote
option +history
option +nullcomplete
option +tilde
option +glob
option prompt $e[31;40;1m[$w]$_$$ $e[37;1m
option uncompletechar ,;=``

foreach i (mkdir rmdir type md rd start )
    alias $i $COMSPEC /c $i
end

foreach cmd (dir copy move del rename ren del)
    $cmd{
        if %glob.defined% -ne 0 then
            option -glob
            $COMSPEC /c $0 $*
            option +glob
        else
            $COMSPEC /c $0 $*
        endif
    }
end

bindkey CTRL_P vzlike-previous-history
bindkey CTRL_N vzlike-next-history

### VzCNȃL[oChɂ֐
### pɂ́uvzbindvƂ̍sĂB
vzbind{
    bindkey CTRL_R xscript:start            xscript:pageup
    bindkey CTRL_S backward                 xscript:backward
    bindkey CTRL_D forward                  xscript:forward
    bindkey CTRL_E vzlike-previous-history  xscript:previous
    bindkey CTRL_X vzlike-next-history      xscript:next
    bindkey CTRL_F forward-word
    bindkey CTRL_A backward-word
}
# vzbind

lua_e "
    --- NYAOS ĨtbN ---
    function nyaos.goodbye.message()
        print('Good bye !!')
    end

    -- L[tbNTv --
    -- (unyaos.keyhook = sample_keyhookvŗp\)
    function sample_keyhook(t)
        if t.key == nyaos.key.F1 and t.text == '' then
            return os.getenv('EDITOR') or 'notepad',true
        end
        return nil
    end

    -- R}hCtB^[Tv:u$lua(c)v(ʓLua) --
    -- (unyaos.filter.sample = sample_filtervŗp\ɂȂ)
    function sample_filter(cmdline)
        return cmdline:gsub('$lua(%b())',function(m)
            local status,result=pcall( loadstring('return '..m) )
            if status then
                return result
            else
                print('Ignore invalid Lua expression: '..m)
                return false;
            end
        end)
    end

    --- which R}h ---
    function nyaos.command.which(cmd)
        local path='.;' .. os.getenv('PATH')

        --- ꍇ́APATH ̈ꗗ\邾 ---
        if not cmd or cmd:len()==0 then
            for path1 in path:gmatch('[^;]+') do
                print(path1)
            end
            return
        end

        local cmdl=cmd:lower()

        --- GCAX ---
        local a=nyaos.alias[ cmdl ]
        if a then
            print('aliased as '..a)
        end
        --- ֐ ---
        local f=nyaos.functions[ cmdl ]
        if f then
            print('defined as function')
        end

        local variation={
            [ cmdl ] = true ,
            [ cmdl .. '.exe' ] = true ,
            [ cmdl .. '.cmd' ] = true ,
            [ cmdl .. '.bat' ] = true ,
            [ cmdl .. '.com' ] = true
        }
        for key,val in pairs(nyaos.suffix) do
            variation[ cmdl .. '.' .. key:lower() ] = true
        end

        for path1 in path:gmatch('[^;]+') do
            for fname in nyaos.dir(path1) do
                if variation[ fname:lower() ] then
                    print( path1 .. '\\' .. fname )
                end
            end
        end
    end

    -- u-tvIvVtŋNꂽF
    for i,e in pairs(nyaos.argv) do
        if e == '-t' then
            -- ls ɃJ[IvVt --
            nyaos.alias.ls = (nyaos.alias.ls or 'ls')..' --color'

            if os.getenv('VIMSHELL') == '1' then
                nyaos.option.ls_colors='fi=37:di=32:sy=31:ro=34:hi=33:ex=35:ec=0'
                nyaos.option.prompt='$e[31m[$w]$_$$ $e[37m'
                nyaos.option.term_clear = ''
                nyaos.option.term_cursor_on = ''

                function nyaos.command.complete_test(arg)
                    local list=nyaos.default_complete(arg,1)
                    for i=1,#list do
                        print(list[i][2])
                    end
                end
            else
                nyaos.option.ls_colors='fi=30:di=32:sy=31:ro=34:hi=33:ex=35:ec=0'
                nyaos.option.prompt='$e[31m[$w]$_$$ $e[30m'
            end
        end
    end
"
