about summary refs log tree commit diff stats
path: root/ranger
blob: 6c961c920cd76c76d20fee7ad80115ec0491c791 (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/ruby -Ku
##--------------------------------------------------
# these lines allow the use of "source ranger"
# to change to the last directory after exiting ranger

if false; then
=begin
fi
cd "`$1 --workaround $@ 3>&1 1>&2`"
return
=end
end

##--------------------------------------------------
# Ranger

version = '0.2.4'

require 'pathname'
$: << MYDIR = File.dirname(Pathname(__FILE__).realpath)

##--------------------------------------------------
# parse arguments

if ARGV[1] == '--workaround'
	ARGV.shift(2)
	ARGV.unshift('--cd')
end

ARGV.delete('--cd') if cd = ARGV.include?('--cd')
if ARGV.size > 0
	case ARGV.first
	when '-k'
		exec "killall -9 #{File.basename($0)}"
	end
	pwd = ARGV.first
	if pwd =~ /^file:\/\//
		pwd = $'
	end

	unless File.exists?(pwd)
		pwd = nil
	end

else
	pwd = nil
end

##--------------------------------------------------
# require files

for file in Dir.glob "#{MYDIR}/code/**/*.rb"
	require file [MYDIR.size + 1 ... -3]
end

##--------------------------------------------------
# default options

opt = {
	:show_hidden            => false,
	:sort                   => :name,
	:list_dir_first         => true,
	:sort_reverse           => false,
	:bookmark_file          => '~/.ranger_bookmarks',
	:ascii_only             => true,
	:wide_bar               => true,
	:confirm_string         => "yes I am!",
	:confirm                => true,
	:file_preview           => true,
	:preview                => true,
	:mouse                  => true,
	:mouse_interval         => 200,
	:debug_level            => 0,
	:debug_file             => '/tmp/errorlog',
	:colorscheme            => 'default',
	:cd                     => cd,
	:evil                   => false
}

##--------------------------------------------------
# initialization

class OptionClass < Struct.new(*opt.keys)
	def confirm_string; confirm ? super : "" end
end

Option = OptionClass.new(*opt.values)
opt = nil

load 'ranger.conf'
load 'data/colorscheme/' + Option.colorscheme + '.rb'
load 'data/screensaver/clock.rb'

include Debug

Debug.setup( :name   => 'ranger',
             :file   => Option.debug_file,
             :level  => Option.debug_level )

if pwd and !ARGV.empty? and !File.directory?(pwd)
	Fm.reload_types
	file = Directory::Entry.new(pwd)
	file.get_data
	Action.run(RunContext.new(file, 0, 'ca'))
	exit
end

include CLI

Signal.trap(Scheduler::UPDATE_SIGNAL) do
	Fm.refresh
end

CLI.init_mouse( Option.mouse_interval )

##--------------------------------------------------
# run the shit & clean up afterwards

begin
	Fm.initialize( pwd )
	Fm.main_loop
ensure
	log "exiting!\n\n"

	closei if CLI.running?
	CLI.stop_mouse
	Fm.dump

	Fm.dump_pwd_to_3 if Option.cd rescue nil

	# Kill all other threads
	for thr in Thread.list
		unless thr == Thread.current
			thr.kill
		end
	end
end