-
Notifications
You must be signed in to change notification settings - Fork 1
/
environment.rb
50 lines (40 loc) · 1.44 KB
/
environment.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
47
48
49
50
# Copyright (c) 2010 Mark Somerville <[email protected]>
# Released under the GNU General Public License (GPL) version 3.
# See COPYING.
# Set up the runtime environment.
xdg_runtime_dir = Pathname.new(ENV["XDG_RUNTIME_DIR"] || "")
if File.writable? xdg_runtime_dir
Urchin::TMP_DIR = xdg_runtime_dir + "urchin"
else
Urchin::TMP_DIR = "/tmp/.urchin"
STDERR.puts "XDG_RUNTIME_DIR is not writable - using #{Urchin::TMP_DIR} instead."
end
begin
FileUtils.mkdir Urchin::TMP_DIR unless File.directory? Urchin::TMP_DIR
rescue Errno::EEXIST
end
# Start in the last changed to directory.
Urchin::Builtins::Cd::LAST_DIR = "#{Urchin::TMP_DIR}/lastdir"
if File.readable? Urchin::Builtins::Cd::LAST_DIR
last_dir = File.read(Urchin::Builtins::Cd::LAST_DIR).chomp
unless last_dir.empty?
begin
Dir.chdir last_dir
rescue
end
end
end
xdg_config_home = Pathname.new(ENV["XDG_CONFIG_HOME"] || "#{ENV["HOME"]}/.config")
xdg_data_home = Pathname.new(ENV["XDG_DATA_HOME"] || "#{ENV["HOME"]}/.local/share")
urchin_config_dir = xdg_config_home + "urchin"
urchin_data_dir = xdg_data_home + "urchin"
FileUtils.mkdir_p(urchin_config_dir)
FileUtils.mkdir_p(urchin_data_dir)
Urchin::URCHIN_RB = urchin_config_dir + "urchin.rb"
unless defined? Urchin::History::FILE
Urchin::History::FILE = urchin_data_dir + "urchin.history"
end
unless defined? Urchin::History::LINES_TO_STORE
Urchin::History::LINES_TO_STORE = 1000
end
ENV["URCHIN_PID"] = Process.pid.to_s