-
Notifications
You must be signed in to change notification settings - Fork 5
/
irbrc
68 lines (60 loc) · 2.2 KB
/
irbrc
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
# $IRBRC - irb startup script
# vim: ft=ruby:ts=4:sw=4:noet
require 'irb/completion'
#require 'irb/ext/save-history'
require 'pp'
Proc.new{
# By default irb saves history alongside the irbrc -- so if $IRBRC is
# set, then we get ~/.dotfiles/irbrc_history and we don't want that.
# (Meanwhile if $IRBRC is *not* set, irb will create ~/.config/irb.)
xdg_state_home = ENV["XDG_STATE_HOME"] || ENV["HOME"] + "/.local/state"
IRB.conf[:HISTORY_FILE] = "#{xdg_state_home}/irb_history"
IRB.conf[:SAVE_HISTORY] = 5000
def _rl_fmt(fmt, text)
"\001#{fmt}\002#{text}\001\e[m\002"
end
def _prompt(prefmt, charfmt, char)
_rl_fmt(prefmt, "%N") + " " + _rl_fmt(charfmt, char) + " "
end
IRB.conf[:PROMPT][:my] = {
PROMPT_I: _prompt("\e[m\e[38;5;2m", "\e[;1m\e[38;5;10m", ">"),
PROMPT_N: _prompt("\e[m\e[38;5;8m", "\e[;1m\e[38;5;10m", "·"),
PROMPT_S: _prompt("\e[m\e[38;5;8m", "\e[;0m\e[38;5;14m", "%l"),
PROMPT_C: _prompt("\e[m\e[38;5;8m", "\e[;1m\e[38;5;10m", "·"),
RETURN: "\e[38;5;11m" + "=>" + "\e[m" + " %s\n",
}
IRB.conf[:PROMPT_MODE] = :my
#IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT] = false
# Switch back to IRB::ReadlineInputMethod, as Reline has dynamic prompt
# switching (based on context at the end of the input line) which is very
# disorienting. (This unfortunately disables the auto-complete list but
# that's still worth it.)
IRB.conf[:USE_MULTILINE] = false
}.call
# Temporary until https://github.com/ruby/irb/issues/330 is fuxed
Proc.new{
require "reline/ansi"
if defined?(Reline::ANSI::CAPNAME_KEY_BINDINGS)
# Fix insert, delete, pgup, and pgdown.
Reline::ANSI::CAPNAME_KEY_BINDINGS.merge!({
"kich1" => :ed_ignore,
"kdch1" => :key_delete,
"kpp" => :ed_ignore,
"knp" => :ed_ignore
})
Reline::ANSI.singleton_class.prepend(
Module.new do
def set_default_key_bindings(config)
# Fix home and end.
set_default_key_bindings_comprehensive_list(config)
# Fix iTerm2 insert.
key = [239, 157, 134]
config.add_default_key_binding_by_keymap(:emacs, key, :ed_ignore)
config.add_default_key_binding_by_keymap(:vi_insert, key, :ed_ignore)
config.add_default_key_binding_by_keymap(:vi_command, key, :ed_ignore)
super
end
end
)
end
}.call