@@ -14,7 +14,7 @@ def fzf_history(debugger, cmdstr, ctx, result, _):
14
14
if not os .path .exists (history_file ):
15
15
result .SetError ("history file does not exist" )
16
16
return
17
- history = _load_history (history_file )
17
+ history = _load_history (debugger , history_file )
18
18
19
19
if sys .platform != "darwin" :
20
20
# The ability to integrate fzf's result into lldb uses copy and paste.
@@ -79,16 +79,49 @@ def _handle_command(debugger, command):
79
79
debugger .HandleCommand (command )
80
80
81
81
82
- def _load_history (history_file ):
83
- """Load, decode, parse, and prepare an lldb history file for fzf."""
82
+ # `session history` example formatting:
83
+ # 1: first command
84
+ # 2: penultimate command
85
+ # 3: latest command
86
+ _HISTORY_PREFIX = re .compile (r"^\s+\d+:\s+" )
87
+
88
+
89
+ def _load_session_history (debugger ):
90
+ """Load and parse lldb session history."""
91
+ result = lldb .SBCommandReturnObject ()
92
+ interp = debugger .GetCommandInterpreter ()
93
+ interp .HandleCommand ("session history" , result )
94
+ history = result .GetOutput ()
95
+ commands = []
96
+ for line in history .splitlines ():
97
+ # Strip the prefix.
98
+ command = _HISTORY_PREFIX .sub ("" , line )
99
+ commands .append (command )
100
+ return commands
101
+
102
+
103
+ def _load_persisted_history (history_file ):
104
+ """Load and decode lldb persisted history."""
84
105
with open (history_file ) as f :
85
106
history_contents = f .read ()
86
107
108
+ # Some characters (ex spaces and newlines) are encoded as octal values, but
109
+ # as _characters_ (not bytes). Space is the string r"\\040".
87
110
history_decoded = re .sub (r"\\0([0-7][0-7])" , _decode_char , history_contents )
88
111
history_lines = history_decoded .splitlines ()
89
112
90
113
# Skip the header line (_HiStOrY_V2_)
91
114
del history_lines [0 ]
115
+ return history_lines
116
+
117
+
118
+ def _load_history (debugger , history_file ):
119
+ """Load, decode, parse, and prepare lldb history for fzf."""
120
+ # Persisted history is older (earlier).
121
+ history_lines = _load_persisted_history (history_file )
122
+ # Session history is newer (later).
123
+ history_lines .extend (_load_session_history (debugger ))
124
+
92
125
# Reverse to show latest first.
93
126
history_lines .reverse ()
94
127
0 commit comments