Skip to content

Commit

Permalink
Support for audio files
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubujka committed Jan 22, 2012
1 parent 4774552 commit 02ca67a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
23 changes: 23 additions & 0 deletions commands/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,26 @@ def move_to file, ddir
file_cmd :file_to_clipboard do |file|
system "cat #{file.esc} | xclip"
end

file_cmd :play_sound_file do |file|
IO.popen("mplayer #{file.esc} -loop 0 2> /dev/null ", "r+") do |io|
clear
puts "Playing #{file}"
puts "Commands: "
puts " space: pause"
puts " r: restart"
puts " q: abort"
while t = get_char
if t == "q"
io.close
goto_file_mode file
end
if t == " "
io.print " " # pause
end
if t == "r"
io.print(27.chr + 91.chr + 54.chr + 126.chr) # restart
end
end
end
end
10 changes: 10 additions & 0 deletions commands/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,13 @@

FileUtils.rm(f)
end

global_cmd :default_action do |pth, mode|
if mode == :file
ext = File.extname(pth)
if(['.mp3', '.MP3'].include? ext)
play_sound_file pth
end
end
end

2 changes: 2 additions & 0 deletions file_mode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def default_file_action file
ext = File.extname(file)
if(['.htm', '.html'].include? ext)
puts `w3m #{file.esc} | cat`.chomp
elsif(['.mp3', '.MP3'].include? ext)
puts "Sound file".blue
else
puts `cat #{file.esc} 2> /dev/null | head -20`
end
Expand Down
1 change: 0 additions & 1 deletion lib/bind.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def bindings

def get_cmd_from_user
act = char_gets

if bindings.key? act
t = bindings[act]
if t.class == Hash
Expand Down
3 changes: 2 additions & 1 deletion rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bind:
m: move_and_return_to_rnd
M: move_edit_and_return_to_rnd
q: quit
"": rnd_file_in_dir
"C-m": default_action
r: rnd_file_in_dir
R: goto_random_in_default_dir
C-r: renumerate_files
Expand All @@ -42,6 +42,7 @@ bind:
c: move_to_complete
B: run_content_in_browser
s: search_word_in_dir
v: play_sound_file
S: search_word_in_dir_r
|: pipe_file
'!': shell_command
Expand Down

0 comments on commit 02ca67a

Please sign in to comment.