-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_mode.rb
46 lines (40 loc) · 1.34 KB
/
file_mode.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def show_current_file_line file
puts "= file: #{file.strip_home.green} - #{file.cdate.blue} ="
nl
end
def default_file_action file
if(File.exists?(file))
if(File.size(file) == 0)
puts "File empty".red
else
ext = File.extname(file)
if(['.htm', '.html'].include? ext)
puts `w3m #{file.esc} | cat`.chomp
elsif(['.mp3', '.MP3', '.wav', '.WAV'].include? ext)
puts "Sound file".blue + " (#{file.basename}) - #{file.cdate}"
else
puts `cat #{file.esc} 2> /dev/null | head -20`
end
end
else
puts "File not exists".red
end
end
def do_what_i_say_in_file file
nl
print_flash_messages
print "What to do:".green
dir = dirname file
if cmd = get_cmd_from_user
if is_global_cmd cmd
send cmd, file, :file
end
if is_dir_cmd cmd
send cmd, dir
end
if is_file_cmd cmd
send cmd, file
end
end
goto_file_mode file
end