diff options
-rw-r--r-- | code/runcontext.rb | 1 | ||||
-rw-r--r-- | data/apps.rb | 115 | ||||
-rw-r--r-- | data/types.rb | 17 |
3 files changed, 67 insertions, 66 deletions
diff --git a/code/runcontext.rb b/code/runcontext.rb index ce62e60f..d3a0b9d1 100644 --- a/code/runcontext.rb +++ b/code/runcontext.rb @@ -156,6 +156,7 @@ class RunContext ~@paths.first end end + alias to_s ~ ## escape one (the first) file for direct use in the shell. ## this is a shortcut for: diff --git a/data/apps.rb b/data/apps.rb index a1db1da7..cc16574f 100644 --- a/data/apps.rb +++ b/data/apps.rb @@ -1,109 +1,104 @@ module Application - def aunpack(rc) - case rc.mode - when 0; "aunpack #{~rc}" - when 1; "aunpack -l #{~rc} | less" + def aunpack(files) + case files.mode + when 0; "aunpack #{files}" + when 1; "aunpack -l #{files} | less" end end - def mplayer(rc) - check rc + def gedit(files) + "gedit #{files}" + end -# if rc.no_mode? -# rc.mode = (rc.name =~ /720p/) ? 2 : 1 -# end + def totem(files) + case files.mode + when 0; "totem --fullscreen #{files}" + when 1; "totem #{files}" + end + end - case rc.mode - when 0; "mplayer -fs -sid 0 #{~rc}" - when 1; "mplayer -sid 0 #{~rc}" - when 2; "mplayer -vm sdl -sid 0 #{~rc}" + def mplayer(files) + case files.mode + when 0; "mplayer -fs -sid 0 #{files}" + when 1; "mplayer -sid 0 #{files}" + when 2; "mplayer -vm sdl -sid 0 #{files}" else nil end end - def mplayer_detached(rc) - rc.base_flags = 'd' - mplayer(rc) + def mplayer_detached(files) + files.base_flags = 'd' + mplayer(files) end - def evince(rc) - check rc - "evince #{~rc}" + def evince(files) + "evince #{files}" end - def feh(rc) - check rc - case rc.mode - when 0; "feh #{~rc}" - when 1; "feh --bg-scale #{rc.one}" - when 2; "feh --bg-tile #{rc.one}" - when 3; "feh --bg-center #{rc.one}" - when 4; "gimp #{~rc}" - when 5; "feh -F #{~rc}" + def feh(files) + case files.mode + when 0; "feh #{files}" + when 1; "feh --bg-scale #{files.one}" + when 2; "feh --bg-tile #{files.one}" + when 3; "feh --bg-center #{files.one}" + when 4; "gimp #{files}" + when 5; "feh -F #{files}" else nil end end - def interpreted_language(rc) - check rc - case rc.mode - when 1; run(rc) - when 0; vi(rc) + def interpreted_language(files) + case files.mode + when 1; run(files) + when 0; vi(files) else nil end end - def zsnes(rc) - check rc - "zsnes #{~rc.first}" + def zsnes(files) + "zsnes #{files.first}" end - def run(rc) - rc.first.executable? ? "#{rc.one}" : nil + def run(files) + files.first.executable? ? "#{files.one}" : nil end - def vi_or_run(rc) - check rc - case rc.mode - when 1; run(rc) - when 0; vi(rc) + def vi_or_run(files) + case files.mode + when 1; run(files) + when 0; vi(files) else nil end end - def vi(rc) - check rc + def vi(files) commands = [ 'map h :quit<cr>', 'map q h', 'map H :unmap h<CR>:unmap H<CR>:unmap q<CR>', ].map {|x| "+'#{x}'"}.join(' ') - "vi #{commands} #{~rc}" + "vi #{commands} #{files}" end - def javac(rc) - check rc - "javac #{~rc}" + def javac(files) + check files + "javac #{files}" end - def java(rc) - check rc - "java #{rc.files.map{|x| ~x.before_last('.')}.join(' ')}" + def java(files) + "java #{files.files.map{|x| ~x.before_last('.')}.join(' ')}" end - def firefox(rc) - check rc - "firefox #{~rc}" + def firefox(files) + "firefox #{files}" end - def make(rc) - check rc - case rc.mode + def make(files) + case files.mode when 0; "make" when 1; "make install" when 2; "make clear" else nil end end - def rake(rc) - check rc + def rake(files) "rake" end end diff --git a/data/types.rb b/data/types.rb index d6e00a09..f1e3d24e 100644 --- a/data/types.rb +++ b/data/types.rb @@ -1,19 +1,20 @@ class Directory::Entry - INTERPRETED_LANGUAGES = %w[haskell perl python ruby sh] - MOVIE_EXTENSIONS = %w[avi mpg mpeg mp4 mp5 ogv ogm wmv mkv flv fid vob div divx] - def get_handler ## directories or sockets don't have any handler use.no_handler if dir? or socket? + + ## first look at the basename case @basename when 'Makefile' - log "i use make" use.make + when /^[Rr]akefile(.rb)?$/ use.rake end + + ## then look at the mime-type case @mimetype when /^video/ use.mplayer_detached @@ -38,18 +39,20 @@ class Directory::Entry when 'text/html', 'application/x-shockwave-flash' use.firefox - end + + ## then at the extension case @ext when 'swc', 'smc' use.zsnes when 'rar', 'zip', 'tar', 'gz', '7z', 'jar', 'bz', 'bz2' use.aunpack - end + + ## is it executable? if executable? use.vi_or_run end @@ -57,5 +60,7 @@ class Directory::Entry ## otherwise use vi use.vi end + + INTERPRETED_LANGUAGES = %w[haskell perl python ruby sh] end |