Module: PryFkeys

Defined in:
lib/pry-fkeys.rb,
lib/pry-fkeys/version.rb

Constant Summary collapse

THE_WHOLE_POINT =
<<-EOT
$if Ruby
  $if mode=vi
      set keymap vi-command
      "[14~":   "Ils -l\\n"        # <F4>
      "[15~":   "\\C-lIwhereami\\n" # <F5>
      "[28~":   "Iedit -c\\n"      # <Shift+F5>
      "[17~":   "Iup\\n"           # <F6>
      "[18~":   "Idown\\n"         # <F7>
      "[19~":   "Icontinue\\n"     # <F8>
      "[32~":   "Itry-again\\n"    # <Shift-F8>
      "[21~":   "Inext\\n"         # <F10>
      "[23~":   "Istep\\n"         # <F11>
      "[23$":   "Ifinish\\n"       # Shift+<F11>
      # Cross-terminal compatibility:
      "[19;2~": "Itry-again\\n"    # <Shift-F8> (xterm/gnome-terminal)
      "[23;2~": "Ifinish\\n"       # Shift+<F11> (xterm/gnome-terminal)
      "OS": "Ils -l\\n"            # <F4>
      "OA": "kA"
      "[A": "kA"
      "OB": "jA"
      "[B": "jA"
  $else
      # Emacs Bindings:
      "\\e[14~":   "ls -l\\n"
      "\\eOS":     "ls -l\\n"
      "\\e[15~":   "\\C-lwhereami\\n"
      "\\e[28~":   "edit -c\\n"
      "\\e[17~":   "up\\n"
      "\\e[18~":   "down\\n"
      "\\e[19~":   "continue\\n"
      "\\e[32~":   "try-again\\n"
      "\\e[19;2~": "try-again\\n"
      "\\e[21~":   "next\\n"
      "\\e[23~":   "step\\n"
      "\\e[23$":   "finish\\n"
      "\\e[23;2~": "finish\\n"
  $endif
$endif
EOT
VERSION =
'0.2.3'

Class Method Summary collapse

Class Method Details

.append!Object



62
63
64
65
66
67
68
69
70
# File 'lib/pry-fkeys.rb', line 62

def append!
  warning = "\e[31mFound '$if Ruby' block, but running anyway...\e[0m\n" \
    if inputrc_customized_for_ruby?
  Pry.output.puts "#{warning}Saving F-keys bindings to #{inputrc_path}"
  File.open inputrc_path, 'a' do |f|
    f.write THE_WHOLE_POINT
  end
  'Done - Restart pry to see the effects'
end

.explainObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/pry-fkeys.rb', line 44

def explain
  Pry.output.puts <<-EOT
\e[32mThese are the current bindings:\e[0m

#{THE_WHOLE_POINT}

If you:
- Paste that into ~/.inputrc (or run inputrc! from Pry)
- Restart pry
Then it should be fully functional; if it isn't, please file an issue:
https://github.com/rking/pry-fkeys/issues

Or, if you just want to suppress the warning, you can put '$if Ruby' anywhere in
~/.inputrc and it'll stop bothering you.
  EOT
  'tl;dr: run inputrc!'
end

.inputrc_customized_for_ruby?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/pry-fkeys.rb', line 11

def inputrc_customized_for_ruby?
  File.exists? inputrc_path and File.read(inputrc_path)[/\$if\s*Ruby/]
end

.inputrc_pathObject



5
# File 'lib/pry-fkeys.rb', line 5

def inputrc_path; File.expand_path '~/.inputrc' end

.install_comma_debugging_aliasesObject



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
# File 'lib/pry-fkeys.rb', line 15

def install_comma_debugging_aliases
  psuedo_alias ',s', 'step'
  psuedo_alias ',n', 'next'
  psuedo_alias ',c', 'continue'
  psuedo_alias ',f', 'finish'

  psuedo_alias ',w', 'whereami'

  # ,, aliases all the ",cmd"s to "cmd". Undo with a second ",,"
  command ',,',
    'toggle ,-prefixes off/on commands, for terse input' do
    abbreviations = []
    commands.keys.reject do |cmd|
      cmd.class != String or cmd[0] != ',' or cmd == ',,'
    end.each do |e|
      terse = e[1..-1]
      # TODO: check to see if you're stomping on something, first.
      Pry.commands.alias_command terse, e
      abbreviations << terse
    end
    Pry.commands.command ',,', 'unsplat all ,-commands' do
      abbreviations.each do |too_terse|
        Pry.commands.delete too_terse
      end
    end
    Pry.output.puts "Added commands: #{abbreviations.join ' '}"
  end
end

.on_clunky_readline?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/pry-fkeys.rb', line 7

def on_clunky_readline?
  Readline::VERSION[/edit/i]
end