diff options
author | hut <hut@lavabit.com> | 2009-05-09 00:00:00 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2009-05-09 00:00:00 +0200 |
commit | a0de7f95bc7525b99b2c2e16f566e0ee367e9c3c (patch) | |
tree | 62d1cdf9523f4e8fad28ca7df0e1d696c991d2db /code/action.rb | |
parent | 34bfb32ecf2cea5e5de95980beedb681139d9c01 (diff) | |
download | ranger-a0de7f95bc7525b99b2c2e16f566e0ee367e9c3c.tar.gz |
lots of changes. version 0.2.1 v0.2.1
Diffstat (limited to 'code/action.rb')
-rw-r--r-- | code/action.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/code/action.rb b/code/action.rb new file mode 100644 index 00000000..e463e852 --- /dev/null +++ b/code/action.rb @@ -0,0 +1,69 @@ +module Action + def self.copy(files, path) + files = [files] unless files.is_a? Array + unless files.empty? + CopyBar2.new(files, path) + end + end + + def self.move(files, path) + files = [files] unless files.is_a? Array + unless files.empty? + MoveBar2.new(files, path) + end + end + + def self.run(hash = {}) + unless OpenStruct === hash + hash = OpenStruct.new(hash) + end + + cf = Fm.currentfile + + all = hash.all.or true + files = hash.files.or(all ? Fm.selection : [cf]) + mode = hash.mode.or 0 + newway = hash.newway.or false + + return false if files.nil? + + if newway + hash = Fm.filehandler(files, hash) + handler = hash.exec + else + handler, wait = Fm.getfilehandler(*files) + end + + return false unless handler + + wait = hash.wait.or wait + new_term = hash.new_term.or false + detach = hash.detach.or false + + log handler + if detach + run_detached(handler, new_term) + else + run_inside(handler, wait) + end + return true + end + + def self.run_detached(what, new_term) + if new_term + p = fork { exec('x-terminal-emulator', '-e', 'bash', '-c', what) } +# Process.detach(p) + else + p = fork { exec "#{what} 2>> /dev/null >> /dev/null" } + Process.detach(p) + end + end + + def self.run_inside(what, wait) + closei + system(*what) + gets if wait + starti + end +end + |