###############################################################################
# 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'] = ''

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

###############################################################################
# extension settings
###############################################################################
keycommand NOMETA, KEY_ENTER, ".gz",       "cmdline('%q zcat %f | $PAGER', 0)"
keycommand NOMETA, KEY_ENTER, ".html",    "cmdline('%q w3m %f', 0)"
keycommand NOMETA, KEY_ENTER, ".htm",     "cmdline('%q w3m %f', 0)"
keycommand NOMETA, KEY_ENTER, ".jpg",     "cmdline('%q display %f &', 0)"
keycommand NOMETA, KEY_ENTER, ".JPG",     "cmdline('%q display %f &', 0)"
keycommand NOMETA, KEY_ENTER, ".jpeg",    "cmdline('%q display %f &', 0)"
keycommand NOMETA, KEY_ENTER, ".gif",     "cmdline('%q display %f &', 0)"
keycommand NOMETA, KEY_ENTER, ".bmp",     "cmdline('%q display %f &', 0)"
keycommand NOMETA, KEY_ENTER, ".pnm",     "cmdline('%q display %f &', 0)"
keycommand NOMETA, KEY_ENTER, ".png",     "cmdline('%q display %f &', 0)"
keycommand NOMETA, KEY_ENTER, ".tif",     "cmdline('%q display %f &', 0)"
keycommand NOMETA, KEY_ENTER, ".eps",     "cmdline('%q display %f &', 0)"
keycommand NOMETA, KEY_ENTER, ".mp3",     "cmdline('mpg123 %f', 0)"
keycommand NOMETA, KEY_ENTER, ".wav",     "cmdline('%q esdplay %f', 0)"
keycommand NOMETA, KEY_ENTER, ".WAV",     "cmdline('%q esdplay %f', 0)"
keycommand NOMETA, KEY_ENTER, ".mpg",     "cmdline('mplayer %f', 0)"
keycommand NOMETA, KEY_ENTER, ".mpeg",    "cmdline('mplayer %f', 0)"
keycommand NOMETA, KEY_ENTER, ".rm",      "cmdline('realplay %f', 0)"
keycommand NOMETA, KEY_ENTER, ".avi",     "cmdline('mplayer %f', 0)"
keycommand NOMETA, KEY_ENTER, ".mid",     "cmdline('timidity %f', 0)"
keycommand NOMETA, KEY_ENTER, ".MID",     "cmdline('timidity %f', 0)"
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, ".class",   "cmdline('%q java %X', '%X')"
keycommand NOMETA, KEY_ENTER, ".o",       "cmdline('%q nm %f 2>&1 | $PAGER', 0)"
defmenu("iso-menu",
   "d(v)d", KEY_v, "cmdline('growisofs -Z /dev/dvd=%f', 0)",
   "(c)d", KEY_c, "cmdline('cdrecord -v dev=0,0,0 speed=8 %f', 0)");

keycommand NOMETA, KEY_ENTER, ".iso",     "menu('iso-menu')"
keycommand NOMETA, KEY_ENTER, ".smc",    "cmdline('zsnes %f', 0)"

keycommand NOMETA, KEY_ENTER, ".mark",    "cmdline(' %m1', 1)"
keycommand NOMETA, KEY_ENTER, ".dir",     "dir_move(cursor_name())"
keycommand NOMETA, KEY_ENTER, ".execute", "cmdline('./%f ', 0)"

keycommand NOMETA, KEY_ENTER, "*",        "shell('%q $PAGER %f', '%f')"

###############################################################################
# option settings
###############################################################################
$option_afu_copy = true
$option_left_right_dir_up = 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 false
option_remain_cursor false
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

if `uname -s`.index("CYGWIN")
    option_color_exe MA_WHITE
else
    option_color_exe MA_RED
end

option_color_link MA_MAGENTA

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

if `uname -s`.index("CYGWIN") || ENV['LANG'] == "ja_JP.SJIS" || ENV['LANG'] == "ja_JP.sjis"
    option_kanjicode "sjis"
elsif ENV['LANG'] != nil && (ENV['LANG'].index("utf") || ENV['LANG'].index("UTF"))
    option_kanjicode "utf8"
else
    option_kanjicode "euc"
end

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

history_size 10000

option_xterm false

if `uname -s`.index("CYGWIN")
    option_refresh false
else
    option_refresh true
end

if `uname -s`.index("CYGWIN")
    set_xterm("ck", "-title", "-e", "", 0)
elsif `which gnome-terminal 2> /dev/null` != ""
    set_xterm("gnome-terminal", "-t", "-e", "", 1)
elsif `which konsole 2> /dev/null` != ""
    set_xterm("konsole", "-T", "-e", "", 0)
elsif `which mlterm 2> /dev/null` != ""
    set_xterm("mlterm", "-T", "-e", "", 0)
elsif `which rxvt 2> /dev/null` != ""
    set_xterm("rxvt", "-T", "-e", "", 0)
elsif `which Eterm 2> /dev/null` != ""
    set_xterm("Eterm", "-T", "-e", "", 0)
elsif `which aterm 2> /dev/null` != ""
    set_xterm("aterm", "-T", "-e", "", 0)
elsif `which kterm 2> /dev/null` != ""
    set_xterm("kterm", "-T", "-e", "", 0)
else
    set_xterm("xterm", "-T", "-e", "", 0)
end

###############################################################################
# my commands
###############################################################################
def make_new_shell_script(fname)
    if !File.exist?(adir_path2 + fname)
        begin 
            f = File.new(adir_path2 + fname,File::CREAT|File::TRUNC|File::WRONLY)
            f.chmod(0755)
            f.print("#!/bin/sh\n\n")
            f.close
        rescue
        end
    end
end

def make_new_html(fname)
    if !File.exist?(adir_path2 + fname)
        begin 
            f = File.new(adir_path2 + fname,File::CREAT|File::TRUNC|File::WRONLY)
            f.print <<EOS
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
</body>
</html>
EOS
            f.close
        rescue
        end
    end
end

def make_new_perl_script(fname)
    if !File.exist?(adir_path2 + fname)
        begin
            f = File.new(adir_path2 + fname,File::CREAT|File::TRUNC|File::WRONLY)
            f.chmod(0755)
            f.print("#!/usr/bin/env perl\n\n")
            f.close
        rescue
        end
    end
end

def make_new_python_script(fname)
    if !File.exist?(adir_path2 + fname)
        begin
            f = File.new(adir_path2 + fname,File::CREAT|File::TRUNC|File::WRONLY)
            f.chmod(0755)
            f.print("#!/usr/bin/env python\n\n")
            f.close
        rescue
        end
    end
end

def make_new_ruby_script(fname)
    if !File.exist?(adir_path2 + fname)
        begin
            f = File.new(adir_path2 + fname,File::CREAT|File::TRUNC|File::WRONLY)
            f.chmod(0755)
            f.print("#!/usr/bin/env ruby\n\n")
            f.close
        rescue
        end
    end
end

defmenu("new-file",
    "(s)h script", KEY_s, "cmdline('%r%Q make_new_shell_script(\\'.sh\\')', -5)",
    "(h)tml", KEY_h, "cmdline('%r%Q make_new_html(\\'.html\\')', -7)",
    "(p)erl script", KEY_p, "cmdline('%r%Q make_new_perl_script(\\'.pl\\')', -5)",
    "p(y)thon script", KEY_y, "cmdline('%r%Q make_new_python_script(\\'.py\\')', -5)",
    "(r)uby script", KEY_r, "cmdline('%r%Q make_new_ruby_script(\\'.rb\\')', -5)");

keycommand NOMETA, KEY_N,      "*",     "menu('new-file')"

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

keycommand META, KEY_j,      "*",     "menu('jump')"

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 %D2s%f.iso %f', 0)",
   "mk(I)sofs", KEY_I, "cmdline('mkisofs -r -iso-level=4 -o %f.iso %f', 0)",
   "/var/(l)og/messages", KEY_l, "shell('%q sudo $PAGER /var/log/messages', '/var/log/messages')",
   "(m)ount cdrom", KEY_m, "shell('%q sudo mount /mnt/cdrom', 'cdrom')",
   "(u)mount cdrom", KEY_u, "shell('%q sudo umount /mnt/cdrom', 'cdrom')",
   "(c)dparanoia", KEY_c, "cmdline('sudo cdparanoia -B 1-; for i in *; do gogo $i; done; sudo rm *wav', 0)",
   "(f)tp", KEY_f, "cmdline(\"cd /home/daisuke/public_html/geocities; lftp -u daisuke530221jp ftp.geocities.jp -e 'mirror -R .'\", 0)");

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