###############################################################################
# ruby library search path
###############################################################################
#$:.push(".")
#$:.push("/usr/local/lib/ruby/1.8")
#$:.push("/usr/local/lib/ruby/1.8/i386-freebsd5")

#require "nkf"

###############################################################################
# set Env
###############################################################################

#ENV['PAGER'] = ''
#ENV['EDITOR'] = ''
#ENV['SHELL'] = ''

###############################################################################
# check Env
###############################################################################
if ENV['PAGER'] == nil || ENV['PAGER'] == ""
    if File.exist?("/usr/bin/lv") || File.exist?("/usr/local/bin/lv")
        ENV['PAGER'] = "lv"
    elsif File.exist?("/usr/bin/less") || File.exist?("/usr/local/bin/less") 
        ENV['PAGER'] = "less"
    else
        ENV['PAGER'] = "more"
    end
end

if ENV['EDITOR'] == nil || ENV['EDITOR'] == ""
    if File.exist?("/usr/bin/vim") || File.exist?("/usr/local/bin/vim") 
        ENV['EDITOR'] = "vim"
    else
        ENV['EDITOR'] = "vi"
    end
end

if ENV['SHELL'] == nil || ENV['SHELL'] == "" 
    if File.exist?("/bin/zsh") || File.exist?("/usr/bin/zsh") || File.exist?("/usr/local/bin/zsh") 
        ENV['SHELL'] = "zsh"
    elsif File.exist?("/bin/bash") || File.exist?("/usr/bin/bash") || File.exist?("/usr/local/bin/bash") 
        ENV['SHELL'] = "bash"
    elsif File.exist?("/bin/tcsh") || File.exist?("/usr/bin/tcsh") || File.exist?("/usr/local/bin/tcsh") 
        ENV['SHELL'] = "tcsh"
     else
        ENV['SHELL'] = "sh"
    end
end

###############################################################################
# function definitions
###############################################################################
def is_one_dir()
    vo = view_option();

    return vo == "one_dir" || vo == "one_dir2" || vo == "one_dir3" || vo == "one_dir5";
end

def glob_mark(glob)
    garray = Dir[glob]

    i = 0
    while i < cursor_max
        if file_name(i) != "." && file_name(i) != ".."
            garray.each {|item|
                if item == file_name(i)
                    mark_on(i)
                    break
                end
            }
        end

        i = i + 1
    end
end

def mark_all_clear()
    i = 0
    while i < cursor_max
        mark_off(i)
        i = i + 1
    end
end

def fdclone_type_pagedown()
    if is_one_dir() then
        cursor_move(cursor()+5)
    else
        if cursor_max() <= cursor_maxy() then
            cursor_move(cursor()+5)
        else
            n = (cursor_max()/cursor_maxy())*cursor_maxy()
            if cursor() < n then
                cursor_move(cursor()+cursor_maxy())
            end
        end
    end
end

def afu_type_pagedown()
    if is_one_dir() then
        cursor_move(cursor()+5)
    else
        if cursor_max() <= cursor_maxy() then
            cursor_move(cursor()+5)
        else
            cursor_move(cursor()+cursor_maxy()-2)
        end
    end
end

def fdclone_type_pageup()
    if is_one_dir() then
        cursor_move(cursor()-5)
    else
        if cursor_max() <= cursor_maxy() then
            cursor_move(cursor()-5)
        else 
            if cursor() >= cursor_maxy() then
                cursor_move(cursor()-cursor_maxy())
            end
        end
    end
end

def afu_type_pageup()
    if is_one_dir() then
        cursor_move(cursor()-5)
    else
        if cursor_max() <= cursor_maxy() then
            cursor_move(cursor()-5)
        else    
            cursor_move(cursor()-cursor_maxy()+2)
        end
    end
end

###############################################################################
# hook
###############################################################################
def fdclone_type_cursor_move_hook()
    vo = view_option()
    maxy = cursor_maxy()
    
    if vo == "all" || vo == "one_dir" then
         if cursor() >= scrolltop() + maxy then
             set_scrolltop( (cursor()/maxy)*maxy )
         end
         if cursor() < scrolltop() then
             set_scrolltop( (cursor()/maxy)*maxy )
         end
    elsif vo == "one_dir2" then
        if cursor() >= scrolltop() + maxy*2 then
             set_scrolltop( (cursor()/(maxy*2))*(maxy*2) )
        end
        if cursor() < scrolltop() then
            set_scrolltop( (cursor()/(maxy*2))*(maxy*2) )
        end
    elsif vo == "one_dir3" then
        if cursor() >= scrolltop() + maxy*3 then
             set_scrolltop( (cursor()/(maxy*3))*(maxy*3) )
        end
        if cursor() < scrolltop() then
            set_scrolltop( (cursor()/(maxy*3))*(maxy*3) )
        end
    elsif vo == "one_dir5" then
        if cursor() >= scrolltop() + maxy*5 then
             set_scrolltop( (cursor()/(maxy*5))*(maxy*5) )
        end
        if cursor() < scrolltop() then
            set_scrolltop( (cursor()/(maxy*5))*(maxy*5) )
        end
    end
end

def afu_type_cursor_move_hook()
    vo = view_option()
    maxy = cursor_maxy()
    
    if vo == "all" || vo == "one_dir" then
         if cursor() >= scrolltop() + maxy-2 then
             set_scrolltop(cursor() -maxy+2)
         end
         if cursor() < scrolltop() then
             set_scrolltop(cursor())
         end
    elsif vo == "one_dir2" then
        if cursor() >= scrolltop() + maxy*2 then
             set_scrolltop( (cursor()/(maxy*2))*(maxy*2) )
        end
        if cursor() < scrolltop() then
            set_scrolltop( (cursor()/(maxy*2))*(maxy*2) )
        end
    elsif vo == "one_dir3" then
        if cursor() >= scrolltop() + maxy*3 then
             set_scrolltop( (cursor()/(maxy*3))*(maxy*3) )
        end
        if cursor() < scrolltop() then
            set_scrolltop( (cursor()/(maxy*3))*(maxy*3) )
        end
    elsif vo == "one_dir5" then
        if cursor() >= scrolltop() + maxy*5 then
             set_scrolltop( (cursor()/(maxy*5))*(maxy*5) )
        end
        if cursor() < scrolltop() then
            set_scrolltop( (cursor()/(maxy*5))*(maxy*5) )
        end
    end
end

def cursor_move_hook(i)
    afu_type_cursor_move_hook()
end

###############################################################################
# key settings
###############################################################################
keycommand NOMETA, KEY_UP,           "*",        "cursor_move(cursor()-1)"
keycommand NOMETA, KEY_DOWN,         "*",        "cursor_move(cursor()+1)"

def key_left()
    if is_one_dir() then
        if cursor_x() > 0 then
            cursor_move(cursor()-cursor_maxy())
        end
    else
        if is_adir_left() then
            dir_move('..');
        else
            cursor_left();
        end
    end
end

keycommand NOMETA, KEY_LEFT,         "*",        "key_left()"

def key_right()
    if is_one_dir() then
        if cursor_x() < (cursor_maxx()-1)
            cursor_move(cursor()+cursor_maxy())
        end
    else
        if is_adir_right() then
            dir_move('..');
        else
            cursor_right();
        end
    end
end

keycommand NOMETA, KEY_RIGHT,        "*",        "key_right()"

keycommand NOMETA, KEY_PAGEUP,       "*",        "afu_type_pageup()"
keycommand NOMETA, KEY_PAGEDOWN,     "*",        "afu_type_pagedown()"
keycommand NOMETA, KEY_CTRL_P,       "*",        "cursor_move(cursor()-1)"
keycommand NOMETA, KEY_CTRL_N,       "*",        "cursor_move(cursor()+1)"
keycommand NOMETA, KEY_CTRL_B,       "*",        "key_left()"
keycommand NOMETA, KEY_CTRL_F,       "*",        "key_right()"
keycommand NOMETA, KEY_CTRL_D,       "*",        "afu_type_pagedown()"
keycommand NOMETA, KEY_CTRL_U,       "*",        "afu_type_pageup()"
keycommand NOMETA, KEY_CTRL_A,       "*",        "cursor_move(0)"
keycommand NOMETA, KEY_CTRL_E,       "*",        "cursor_move(cursor_max()-1)"
keycommand NOMETA, KEY_CTRL_H,       "*",        "dir_move('..')"
keycommand NOMETA, KEY_BACKSPACE,    "*",        "dir_move('..')"
keycommand NOMETA, 127,              "*",        "dir_move('..')"
keycommand NOMETA, KEY_DELETE,       "*",        "dir_move('..')"
keycommand META,   KEY_LEFT,         "*",        "dir_back()"
keycommand NOMETA, KEY_BACKSLASH,    "*",        "dir_move('/')"
keycommand NOMETA, KEY_TILDA,        "*",        "dir_move('~')"
keycommand NOMETA, KEY_SPACE,        "*",        "mark2(cursor); cursor_move(cursor + 1)"
keycommand NOMETA, KEY_HOME,         "*",        "mark_all_files()"
keycommand NOMETA, KEY_END,          "*",        "mark_all()"
keycommand NOMETA, KEY_CTRL_L,       "*",        "refresh()"
keycommand NOMETA, KEY_CTRL_I,       "*",        "dir_up()"
keycommand NOMETA, KEY_CTRL_T,       "*",        "dir_new()"
keycommand NOMETA, KEY_CTRL_W,       "*",        "dir_close()"
keycommand NOMETA, KEY_QMARK,        "*",        "help()"
keycommand NOMETA, KEY_ESCAPE,       "*",        "mf_exit()"
keycommand NOMETA, KEY_SLASH,        "*",        "isearch()"

def key_copy()
    if is_one_dir
        cmdline('%Q%r copy(adir_path2(), adir_mark(), %D1s)', -2)
    else 
        if $option_afu_copy
            if marking
                copy(adir_path2(), adir_mark(), sdir_path2())
            end
        else
            cmdline('%Q%r copy(adir_path2(), adir_mark(), %D2s)', -2)
        end
    end
end

keycommand NOMETA, KEY_c,      "*",     "key_copy"
keycommand NOMETA, KEY_C,      "*",     "if is_one_dir() then cmdline('cp -Rpf %m1 %D1s', -1) else cmdline('cp -Rpf %m1 %D2s', -1) end"

def key_move()
    if is_one_dir 
        cmdline('%Q%r move(adir_path2(), adir_mark(), %D1s)', -2)
    else 
        if $option_afu_copy
            if marking
                move(adir_path2(), adir_mark(), sdir_path2())
            end
        else
            cmdline('%Q%r move(adir_path2(), adir_mark(), %D2s)', -2)
        end
    end
end

keycommand NOMETA, KEY_m,      "*",     "key_move"
keycommand NOMETA, KEY_M,      "*",     "if is_one_dir() then cmdline('mv -f %m1 %D1s', -1) else cmdline('mv -f %m1 %D2s', -1) end"

def key_trashbox()
    if !$option_afu_copy || $option_afu_copy && marking
        trashbox(adir_path2(), adir_mark())
    end
end

keycommand NOMETA, KEY_d,      "*",     "key_trashbox"

def key_delete()
    if !$option_afu_copy || $option_afu_copy && marking
        remove(adir_path2(), adir_mark())
    end
end

keycommand NOMETA, KEY_D,      "*",     "key_delete"
keycommand NOMETA, KEY_e,      "*",     "shell('%q $EDITOR %f', '%f')"
keycommand NOMETA, KEY_E,      "*",     "cmdline(\"%q $EDITOR ''\", -1)"
keycommand NOMETA, KEY_v,      "*",     "shell('%q $PAGER %f', '%f')"
keycommand NOMETA, KEY_r,      "*",     "cmdline('%Q mv %f %f', -1)"
keycommand NOMETA, KEY_b,      ".mark", "cmdline('for i in %m1; do cp -Rpf $i $i; done', -6)"
keycommand NOMETA, KEY_b,      "*",     "cmdline('%Q%r copy(adir_path2(), adir_mark(), %f)', -2)"
keycommand NOMETA, KEY_p,      "*",     "cmdline('tar cvfz %X.tgz %m1', -9)"
keycommand NOMETA, KEY_k,      "*",     "cmdline(\"%Q mkdir -p ''\", -1)"
keycommand NOMETA, KEY_n,      "*",     "cmdline(\"%Q touch ''\", -1)"
keycommand NOMETA, KEY_l,      "*",     "if is_one_dir() then cmdline('%Q ln -s %F %D1s', -1) else cmdline('%Q ln -s %F %D2s', -1) end"

defmenu("gz-menu",
    "(t)ar xvfz", KEY_t, "if is_one_dir then cmdline('tar xvfz %f -C %D1s', -1) else cmdline('tar xvfz %f -C %D2s', -1) end",
    "(g)zip -d", KEY_g, "shell('%Q gzip -d %F', '%f')");

defmenu("bz2-menu",
    "(t)ar xvfj", KEY_t, "if is_one_dir then cmdline('tar xvfj %f -C %D1s', -1) else cmdline('tar xvfj %f -C %D2s', -1) end",
    "(b)zip2 -d", KEY_b, "shell('%Q bzip2 -d %f', '%f')");

keycommand NOMETA, KEY_u, ".gz",      "menu('gz-menu')"
keycommand NOMETA, KEY_u, ".bz2",     "menu('bz2-menu')"
keycommand NOMETA, KEY_u, ".tar",     "if is_one_dir then cmdline('tar xvf %f -C %D1s', -1) else cmdline('tar xvf %f -C %D2s', -1) end"
keycommand NOMETA, KEY_u, ".tgz",     "if is_one_dir then cmdline('tar xvfz %f -C %D1s', -1) else cmdline('tar xvfz %f -C %D2s', -1) end"
keycommand NOMETA, KEY_u, ".lzh",     "if is_one_dir then cmdline('cd %D1s; lha x %F', adir_path2.size() + 5) else cmdline('cd %D2s; lha x %F', sdir_path2.size() + 5) end"
keycommand NOMETA, KEY_u, ".zip",     "if is_one_dir then cmdline('unzip %f -d %D1s', -1) else cmdline('unzip %f -d %D2s', -1) end"

keycommand NOMETA, KEY_g,      "*",     "cmdline(\"%q grep '' * -n 2> /dev/null | $PAGER\", 10)"
keycommand NOMETA, KEY_G,      "*",     "cmdline(\"%q mgrep \\\"grep -n '' *\\\"\", -4)"
keycommand NOMETA, KEY_STAR,   "*",     "cmdline(\"%r%Q%M glob_mark('')\", -2)"
keycommand NOMETA, KEY_i,      ".dir",  "cmdline('du -sk %f', 7)"
keycommand NOMETA, KEY_i,      "*",     "cmdline('file %m1', 0)"
keycommand NOMETA, KEY_j,      "*",     "cmdline(\"%r%Q dir_move %D1s\", -1)"
keycommand NOMETA, KEY_o,      "*",     "if !is_one_dir then dir_move(sdir_path2()) end"
keycommand NOMETA, KEY_O,      "*",     "if !is_one_dir then sdir_move(adir_path2()) end"
keycommand NOMETA, KEY_w,      "*",     "if !is_one_dir then tmp = adir_path2(); dir_move(sdir_path2()); sdir_move(tmp) end"
keycommand NOMETA, KEY_q,      "*",     "mf_exit()"

keycommand NOMETA, KEY_f,            "*",        "isearch()"
keycommand NOMETA, KEY_F,            "*",        "cmdline(\"%q find . -name '' 2> /dev/null | $PAGER\", 18)"

defmenu("jump",
   "(1) ~/mp3", KEY_1, "dir_move('~/mp3')",
   "(2) ~/public_html", KEY_2, "dir_move('~/public_html')",
   "(3) /usr/include", KEY_3, "dir_move('/usr/include')");

keycommand NOMETA, KEY_J,      "*",     "menu('jump')"

defmenu("sort",
   "sort (n)ame", KEY_n, "sort_name()",
   "sort (N)ame reverse", KEY_N, "sort_name_reverse()",
   "sort (e)xtension", KEY_e, "sort_ext()",
   "sort (E)xtension reverse", KEY_E, "sort_ext_reverse()",
   "sort (s)ize", KEY_s, "sort_size()",
   "sort (S)ize reverse", KEY_S, "sort_size_reverse()",
   "sort (t)ime", KEY_t, "sort_time()",
   "sort (T)ime reverse", KEY_T, "sort_time_reverse()",
   "sort (u)ser", KEY_u, "sort_user()",
   "sort (U)ser reverse", KEY_U, "sort_user_reverse()",
   "sort (g)roup", KEY_g, "sort_group()",
   "sort (G)roup reverse", KEY_G, "sort_group_reverse()",
   "sort toggle (d)ir up", KEY_d, "sort_toggle_dir_up()",
   "view 2dir(a)ll", KEY_a, "view_all()",
   "view 1dir(1)", KEY_1, "view_onedir()",
   "view 1dir(2)", KEY_2, "view_onedir2()",
   "view 1dir(3)", KEY_3, "view_onedir3()",
   "view 1dir(5)", KEY_5, "view_onedir5()",
   "view toggle name(o)nly", KEY_o, "view_nameonly()",
   "view toggle (c)olor", KEY_c, "view_color()",
   "view (m)ask", KEY_m, "if is_remain_marks() then cmdline(\"%Q%r set_mask('{*,.*}')\", -2); else cmdline(\"%Q%r%M set_mask('{*,.*}')\", -2); end");

keycommand NOMETA, KEY_s,      "*",     "menu('sort')"

defmenu("file_attr",
   "ch(m)od (permission)", KEY_m, "cmdline('%Q chmod  %m1', 10)",
   "ch(o)wn (owner)", KEY_o, "cmdline('%Q chown  %m1', 10)",
   "ch(g)rp (group)", KEY_g, "cmdline('%Q chgrp  %m1', 10)",
   "m(a)ttr (permission and date)", KEY_a, "shell('%q mattr %m1', 'mattr')");

keycommand NOMETA, KEY_a,      "*",     "menu('file_attr')"

defmenu("file_attr_sudo",
   "sudo ch(m)od (permission)", KEY_m, "cmdline('sudo chmod  %m1', 12)",
   "sudo ch(o)wn (owner)", KEY_o, "cmdline('sudo chown  %m1', 12)",
   "sudo ch(g)rp (group)", KEY_g, "cmdline('sudo chgrp  %m1', 12)",
   "sudo m(a)ttr (permission and date)", KEY_a, "shell('%q sudo mattr %m1', 'mattr')");

defmenu("sudo-menu",
   "sudo (c)opy", KEY_c,   "if is_one_dir() then cmdline('sudo cp -Rpf %m1 %D1s', -1) else cmdline('sudo cp -Rpf %m1 %D2s', -1) end",
   "sudo (m)v", KEY_m,      "if is_one_dir() then cmdline('sudo mv -f %m1 %D1s', -1) else cmdline('sudo mv -f %m1 %D2s', -1) end",
   "sudo (d)elete",  KEY_d, "cmdline('sudo rm -R %m1', 0)",
   "sudo (a)ttr menu",  KEY_a, "menu('file_attr_sudo')",
   "sudo (e)dit", KEY_e,   "shell('%q sudo $EDITOR %f', '%f')",
   "sudo (v)iewer", KEY_v,     "shell('%q sudo $PAGER %f', '%f')",
   "sudo (p)ack", KEY_p,     "cmdline('sudo tar cvfz %X.tgz %m1', -9)",
   "sudo (r)ename", KEY_r,   "cmdline('sudo mv %f %f', -1)",
   "sudo ma(k)e dir", KEY_k,   "cmdline(\"sudo mkdir -p ''\", -1)", 
   "sudo (n)ew file", KEY_n,   "cmdline(\"sudo touch ''\", -1)",
   "sudo make (l)ink", KEY_l,  "if is_one_dir() then cmdline('sudo ln -s %F %D1s', -1) else cmdline('sudo ln -s %F %D2s', -1) end");

keycommand NOMETA, KEY_ATMARK,       "*",     "menu('sudo-menu')"

defmenu("extra-menu",
   "(n)ew shell script", KEY_n, "cmdline(\"%Q echo '#!/bin/sh' > /tmp/sscript; chmod 755 /tmp/sscript; mv /tmp/sscript '.sh'\", -4)",
   "re(h)ash",  KEY_h, "rehash", 
   "c(o)mpile", KEY_o, "cmdline(\"%q mcompile 'make -k '\", -1)",
   "(k)ill pty", KEY_k, "kill_pty(select_pty('kill_pty'))",
   "m(a)rk_all_files", KEY_a, "mark_all_files()",
   "m(A)rk_all", KEY_A, "mark_all()",
   "mark_all_cl(e)ar", KEY_e, "mark_all_clear()",
   "(b)ack to previous direcotry", KEY_b, "dir_back()");

keycommand NOMETA, KEY_UNDERBAR,     "*",     "menu('extra-menu')"

keycommand NOMETA, KEY_h,            "*",        "cmdline('', 0)"
keycommand NOMETA, KEY_x,            "*",        "cmdline(' ./%f', 1)"
keycommand NOMETA, KEY_x,            ".mark",    "cmdline(' %m1', 1)"
keycommand NOMETA, KEY_COLON,        "*",        "shell('%q echo \"-+- \"%D1\" -+-\"; ls -aFG; $SHELL', \"#{ENV['SHELL']}\")"
keycommand NOMETA, KEY_z,            "*",        "xterm_next()"

keycommand NOMETA, KEY_CTRL_C,       "*",        "copy2()"
keycommand NOMETA, KEY_CTRL_X,       "*",        "cut()"
keycommand NOMETA, KEY_CTRL_V,       "*",        "past()"
keycommand NOMETA, KEY_CTRL_Z,       "*",        "undo()"

keycommand NOMETA, KEY_0,            "*",        "restore_pty(select_pty('select pty'))"
keycommand NOMETA, KEY_1,            "*",        "restore_pty(1)"
keycommand NOMETA, KEY_2,            "*",        "restore_pty(2)"
keycommand NOMETA, KEY_3,            "*",        "restore_pty(3)"
keycommand NOMETA, KEY_4,            "*",        "restore_pty(4)"
keycommand NOMETA, KEY_5,            "*",        "restore_pty(5)"
keycommand NOMETA, KEY_6,            "*",        "restore_pty(6)"
keycommand NOMETA, KEY_7,            "*",        "restore_pty(7)"
keycommand NOMETA, KEY_8,            "*",        "restore_pty(8)"
keycommand NOMETA, KEY_9,            "*",        "restore_pty(9)"

###############################################################################
# extension settings
###############################################################################
keycommand NOMETA, KEY_ENTER, ".html",    "shell('%q w3m %f', '%f')"
keycommand NOMETA, KEY_ENTER, ".jpg",     "shell('%q display %f &', '%f')"
keycommand NOMETA, KEY_ENTER, ".jpeg",    "shell('%q display %f &', '%f')"
keycommand NOMETA, KEY_ENTER, ".gif",     "shell('%q display %f &', '%f')"
keycommand NOMETA, KEY_ENTER, ".bmp",     "shell('%q display %f &', '%f')"
keycommand NOMETA, KEY_ENTER, ".pnm",     "shell('%q display %f &', '%f')"
keycommand NOMETA, KEY_ENTER, ".png",     "shell('%q display %f &', '%f')"
keycommand NOMETA, KEY_ENTER, ".tif",     "shell('%q display %f &', '%f')"
keycommand NOMETA, KEY_ENTER, ".eps",     "shell('%q display %f &', '%f')"
keycommand NOMETA, KEY_ENTER, ".mp3",     "shell('mpg123 %f', '%f')"
keycommand NOMETA, KEY_ENTER, ".wav",     "shell('%q esdplay %f', '%f')"
keycommand NOMETA, KEY_ENTER, ".WAV",     "shell('%q esdplay %f', '%f')"
keycommand NOMETA, KEY_ENTER, ".mpg",     "shell('%q mplayer %f', '%f')"
keycommand NOMETA, KEY_ENTER, ".mpeg",    "shell('%q mplayer %f', '%f')"
keycommand NOMETA, KEY_ENTER, ".avi",     "shell('%q mplayer %f', '%f')"
keycommand NOMETA, KEY_ENTER, ".mid",     "shell('timidity %f', '%f')"
keycommand NOMETA, KEY_ENTER, ".MID",     "shell('timidity %f', '%f')"
keycommand NOMETA, KEY_ENTER, "makefile", "cmdline('%q make -f %f  2>&1| $PAGER', -13)"
keycommand NOMETA, KEY_ENTER, "Makefile", "cmdline('%q make -f %f  2>&1| $PAGER', -13)"
keycommand NOMETA, KEY_ENTER, ".pdf",     "cmdline('%q acroread %f &', 0)"
keycommand NOMETA, KEY_ENTER, ".dvi",     "cmdline('xdvi %f &', 0)"
keycommand NOMETA, KEY_ENTER, ".ps",      "cmdline('%q lpr %f -P', 0)"
keycommand NOMETA, KEY_ENTER, ".a",       "cmdline('%q nm %f 2>&1 | $PAGER', 0)"
keycommand NOMETA, KEY_ENTER, ".so",      "cmdline('%q nm -D %f 2>&1 | $PAGER', 0)"
keycommand NOMETA, KEY_ENTER, ".o",       "cmdline('%q nm %f 2>&1 | $PAGER', 0)"
keycommand NOMETA, KEY_ENTER, ".dir",     "dir_move(cursor_name())"
keycommand NOMETA, KEY_ENTER, ".execute", "cmdline('./%f ', 0)"
keycommand NOMETA, KEY_ENTER, ".mark",    "cmdline('for i in %m1; do  $i; done', 18)"
keycommand NOMETA, KEY_ENTER, "*",        "shell('%q $PAGER %f', '%f')"

###############################################################################
# alias
###############################################################################

malias "L", 0, "| $PAGER"
malias "CD", 1, "%r%Q dir_move('#0')"
malias "&", 0, "&%s"
malias "pkg_search", 1, "%q locate #0 | grep ports | less"
malias "PSG", 1, "ps aux | grep #0 | grep -v grep"

###############################################################################
# option settings
###############################################################################
$option_afu_copy = false

option_individual_cursor true
#option_isearch_decision_way "mismatch_finish"
option_isearch_decision_way "enter_decision"
#option_isearch_decision_way "slash_toggle"
option_check_delete_file true
option_check_copy_file false
option_check_exit true
option_shift_isearch false
option_trashbox_name ENV["HOME"] + "/mtrashbox"
option_gnu_screen false
option_pty true
option_remain_cursor true
option_auto_rehash false

option_remain_marks false
option_read_dir_history true

option_bold_exe true
option_bold_dir true
option_color_mark MA_YELLOW
option_color_dir MA_CYAN
option_color_exe MA_RED
option_color_link MA_MAGENTA

# MA_WHITE, MA_BLUE, MA_CYAN, MA_GREEN, MA_YELLOW, MA_MAGENTA, MA_RED

if `uname -s`.index("CYGWIN")
    option_kanjicode "sjis"
elsif ENV['LANG'] == "ja_JP.eucJP"
    option_kanjicode "euc"
else
    option_kanjicode "utf8"
end

set_shell(ENV['SHELL'], `which #{ENV['SHELL']}`.chomp, "-c")

history_size 10000

option_xterm false

if `uname -s`.index("CYGWIN")
    set_xterm("ck", "-title", "-e", "")
    option_select false
else
    set_xterm("xterm", "-T", "-e", "")
    option_select true
end

#set_xterm("Eterm", "-T", "-e", "--mencoding eucj --scrollbar false -F 7x14 -M k14 --cmod 100 --trans")

###############################################################################
# keymap
###############################################################################
keymap   KEY_UP,        27,   91,   65,   0,       0,     0, 0,0,0,0
keymap   KEY_DOWN,      27,   91,   66,   0,       0,     0, 0,0,0,0
keymap   KEY_RIGHT,     27,   91,   67,   0,       0,     0, 0,0,0,0
keymap   KEY_LEFT,      27,   91,   68,   0,       0,     0, 0,0,0,0
keymap   KEY_INSERT,    27,   91,   50,   126,     0,     0, 0,0,0,0
keymap   KEY_DELETE,    127,  0,    0,    0,       0,     0, 0,0,0,0
keymap   KEY_HOME,      27,   79,   72,   0,       0,     0, 0,0,0,0
keymap   KEY_END,       27,   79,   70,   0,       0,     0, 0,0,0,0
keymap   KEY_PAGEUP,    27,   91,   53,   126,     0,     0, 0,0,0,0
keymap   KEY_PAGEDOWN,  27,   91,   54,   126,     0,     0, 0,0,0,0
keymap   KEY_F1,        27,   91,   49,   49,      126,   0, 0,0,0,0
keymap   KEY_F2,        27,   91,   49,   50,      126,   0, 0,0,0,0
keymap   KEY_F3,        27,   91,   49,   51,      126,   0, 0,0,0,0
keymap   KEY_F4,        27,   91,   49,   52,      126,   0, 0,0,0,0
keymap   KEY_F5,        27,   91,   49,   53,      126,   0, 0,0,0,0
keymap   KEY_F6,        27,   91,   49,   55,      126,   0, 0,0,0,0
keymap   KEY_F7,        27,   91,   49,   56,      126,   0, 0,0,0,0
keymap   KEY_F8,        27,   91,   49,   57,      126,   0, 0,0,0,0
keymap   KEY_F9,        27,   91,   50,   48,      126,   0, 0,0,0,0
keymap   KEY_F10,       27,   91,   50,   49,      126,   0, 0,0,0,0
keymap   KEY_F11,       27,   91,   50,   51,      126,   0, 0,0,0,0
keymap   KEY_F12,       27,   91,   50,   52,      126,   0, 0,0,0,0

keymap   KEY_UP,        27,   79,   65,   0,       0,     0, 0,0,0,0
keymap   KEY_DOWN,      27,   79,   66,   0,       0,     0, 0,0,0,0
keymap   KEY_RIGHT,     27,   79,   67,   0,       0,     0, 0,0,0,0
keymap   KEY_LEFT,      27,   79,   68,   0,       0,     0, 0,0,0,0
keymap   KEY_HOME,      27,   91,   49,   126,       0,   0, 0,0,0,0
keymap   KEY_END,       27,   91,   52,   126,       0,   0, 0,0,0,0

###############################################################################
# user definition
###############################################################################
defmenu("iso-menu",
   "d(v)d", KEY_v, "cmdline('growisofs -Z /dev/dvd=%f', 0)",
   "(c)d", KEY_c, "cmdline('cdrecord -v dev=0,1,0 speed=8 %f', 0)"
);

keycommand NOMETA, KEY_ENTER, ".iso",     "menu('iso-menu')"

defmenu("my_commands",
   "g(e)dit",  KEY_e, "shell('%q gedit %f &', '%f')",
   "mk(i)sofs", KEY_i, "cmdline('mkisofs -r -iso-level=4 -o %f.iso %f', 0)",
   "(c)dparanoia", KEY_c, "cmdline('cdparanoia -B 1-; for i in *; do gogo $i; done; rm *wav', 0)",
   "(f)tp", KEY_f, "cmdline(\"cd /home/daisuke/public_html/geocities; lftp -u daisuke530221jp ftp.geocities.jp -e 'mirror -R .'\", 0)",
   "/var/(l)og/message", KEY_l, "cmdline('tail -f /var/log/messages', 0)"
);

keycommand NOMETA, KEY_y, "*", "menu('my_commands')"
