Module: Kernel
- Defined in:
- lib/pryx/looksee_hack.rb,
lib/pryx/pry_hack.rb
Overview
ls1 支持的参数有:
-
String 或 Regexp,包含字符串或匹配正则过滤.
-
:nopublic :noprotected, :noprivate, :noundefined, :nooverridden 显示指定类型方法.
颜色方案模块 白色 37 公开方法 绿色 32 保护方法 黄色 33 私有方法 红色 31 取消定义的方法 蓝色 34 被覆写的方法 灰色 30
Instance Method Summary collapse
-
#background?(pid = $$) ⇒ Boolean
如果是前台进程,则这个进程的组ID(pgid)一定会等于当前 terminal 的gid (tpgid) 否则,如果不等,那么就是后台进程。 system(“ps -e -o pid,pgid,tpgid |grep ‘^s*#pid’ |awk ‘$2==$3 1’”) system(“\cat /proc/#pid/stat |awk ‘$5==$8 1’”).
- #foreground?(pid = $$) ⇒ Boolean
- #irb! ⇒ Object
- #irb1 ⇒ Object
- #irb2(caller = 1, remote: nil, port: 9876) ⇒ Object
- #load_looksee ⇒ Object
- #ls1(*args) ⇒ Object
- #ls2(*args) ⇒ Object
- #notify_send(msg) ⇒ Object
-
#pry!(caller = 2, remote: nil, port: 9876) ⇒ Object
运行 pry! 会被拦截, 且只会被拦截一次.
- #pry1 ⇒ Object
-
#pry2(caller = 1, remote: nil, port: 9876) ⇒ Object
1.
-
#pry3(caller = 1, remote: nil, port: 9876) ⇒ Object
等价于默认的 binding.pry, 会反复被拦截。 起成 pry3 这个名字,也是为了方便直接使用。.
-
#pry?(caller = 2, remote: nil, port: 9876) ⇒ Boolean
和 pry! 的差别就是,pry? 使用 pry-state 插件输出当前 context 的很多变量内容。 注意:不需要总是开启 pry-state,因为有时候会输出太多内容,造成刷屏。.
-
#pryr ⇒ Object
注意:pryr 总是会被拦截。.
- #reirb! ⇒ Object
-
#repry! ⇒ Object
在 pry! 之前如果输入这个,会让下次执行的 pry! 被拦截一次, 而不管之前是否有执行过 pry!.
Instance Method Details
#background?(pid = $$) ⇒ Boolean
如果是前台进程,则这个进程的组ID(pgid)一定会等于当前 terminal 的gid (tpgid)否则,如果不等,那么就是后台进程。system(“ps -e -o pid,pgid,tpgid |grep ‘^s*#pid’ |awk ‘$2==$3 1’”) system(“\cat /proc/#pid/stat |awk ‘$5==$8 1’”)
131 132 133 134 135 136 |
# File 'lib/pryx/pry_hack.rb', line 131 def background?(pid=$$) # 考虑是否需要验证 ary = File.read("/proc/#{pid}/stat").split(' ').reverse # 执行 reverse 再处理,是因为要考虑文件名包含空格因素。例如:‘hello) (world’ (ary[46] != ary[48]) && !$stdout.tty? end |
#foreground?(pid = $$) ⇒ Boolean
138 139 140 |
# File 'lib/pryx/pry_hack.rb', line 138 def foreground?(pid=$$) not background?(pid) end |
#irb! ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/pryx/pry_hack.rb', line 107 def irb! return unless ENV['IRB_was_started'].nil? ENV['IRB_was_started'] = 'true' binding.of_caller(1)._irb end |
#irb1 ⇒ Object
115 116 117 |
# File 'lib/pryx/pry_hack.rb', line 115 def irb1 ENV['IRB2_should_start'] = 'true' end |
#irb2(caller = 1, remote: nil, port: 9876) ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/pryx/pry_hack.rb', line 119 def irb2(caller=1, remote: nil, port: 9876) if ENV['IRB2_should_start'] == 'true' # 首先恢复 Pry2_is_start 为未启动, 避免稍后的 pry2 再次被拦截. ENV['IRB2_should_start'] = nil binding.of_caller(caller)._irb end end |
#load_looksee ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pryx/looksee_hack.rb', line 13 def load_looksee case RbConfig::CONFIG['ruby_version'] when '1.9.0'...'2.1.0' require 'old_looksee' when '2.1.0'...'3.2.0' require 'looksee' end Looksee.rename :ls_looksee Looksee.editor = '.emacsclient +%l %f' # e.g. [].ls1.edit :to_set end |
#ls1(*args) ⇒ Object
25 26 27 28 |
# File 'lib/pryx/looksee_hack.rb', line 25 def ls1(*args) load_looksee unless defined? Looksee Looksee[self, *args, :noprivate] end |
#ls2(*args) ⇒ Object
30 31 32 33 |
# File 'lib/pryx/looksee_hack.rb', line 30 def ls2(*args) load_looksee unless defined? Looksee Looksee[self, *args] end |
#notify_send(msg) ⇒ Object
142 143 144 145 146 147 |
# File 'lib/pryx/pry_hack.rb', line 142 def notify_send(msg) system("notify-send \"#{msg}\"") if system 'which notify-send &>/dev/null' system('aplay "#{__dir__}/drip.wav" &>/dev/null') if system 'which aplay &>/dev/null' warn "[1m[33m#{msg}[0m" end |
#pry!(caller = 2, remote: nil, port: 9876) ⇒ Object
运行 pry! 会被拦截, 且只会被拦截一次.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pryx/pry_hack.rb', line 44 def pry!(caller=2, remote: nil, port: 9876) return unless ENV['Pry_was_started'].nil? ENV['Pry_was_started'] = 'true' if background? remote = '0.0.0.0' port = 9876 end pry3(caller, remote: remote, port: port) # 这里如果有代码, 将会让 pry! 进入这个方法, 因此保持为空. end |
#pry1 ⇒ Object
88 89 90 |
# File 'lib/pryx/pry_hack.rb', line 88 def pry1 ENV['Pry2_should_start'] = 'true' end |
#pry2(caller = 1, remote: nil, port: 9876) ⇒ Object
-
单独运行 pry2, 永远不会被拦截,
-
如果之前运行过 pry1, 此时 pry2 将被拦截, 且只会被拦截一次.
95 96 97 98 99 100 101 |
# File 'lib/pryx/pry_hack.rb', line 95 def pry2(caller=1, remote: nil, port: 9876) if ENV['Pry2_should_start'] == 'true' # 首先恢复 Pry2_is_start 为未启动, 避免稍后的 pry2 再次被拦截. ENV['Pry2_should_start'] = nil binding.of_caller(caller)._pry(remote, port) end end |
#pry3(caller = 1, remote: nil, port: 9876) ⇒ Object
等价于默认的 binding.pry, 会反复被拦截。起成 pry3 这个名字,也是为了方便直接使用。
84 85 86 |
# File 'lib/pryx/pry_hack.rb', line 84 def pry3(caller=1, remote: nil, port: 9876) binding.of_caller(caller)._pry(remote, port) end |
#pry?(caller = 2, remote: nil, port: 9876) ⇒ Boolean
和 pry! 的差别就是,pry? 使用 pry-state 插件输出当前 context 的很多变量内容。注意:不需要总是开启 pry-state,因为有时候会输出太多内容,造成刷屏。
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pryx/pry_hack.rb', line 71 def pry?(caller=2, remote: nil, port: 9876) return unless ENV['Pry_was_started'].nil? require 'pry-state' ENV['Pry_was_started'] = 'true' pry3(caller, remote: remote, port: port) # 这里如果有代码, 将会让 pry! 进入这个方法, 因此保持为空. end |
#pryr ⇒ Object
注意:pryr 总是会被拦截。
60 61 62 |
# File 'lib/pryx/pry_hack.rb', line 60 def pryr pry3(caller=2, remote: '0.0.0.0', port: 9876) end |
#reirb! ⇒ Object
103 104 105 |
# File 'lib/pryx/pry_hack.rb', line 103 def reirb! ENV['IRB_was_started'] = nil end |
#repry! ⇒ Object
在 pry! 之前如果输入这个,会让下次执行的 pry! 被拦截一次, 而不管之前是否有执行过 pry!
65 66 67 |
# File 'lib/pryx/pry_hack.rb', line 65 def repry! ENV['Pry_was_started'] = nil end |