99@lldb .command ()
1010def fzf_history (debugger , cmdstr , ctx , result , _ ):
1111 """Use fzf to search and select from lldb command history."""
12+ history_file = os .path .expanduser ("~/.lldb/lldb-widehistory" )
13+ if not os .path .exists (history_file ):
14+ result .SetError ("history file does not exist" )
15+ return
16+ history = _load_history (history_file )
17+
1218 if sys .platform != "darwin" :
13- result .SetError ("fzf_history supports macOS only" )
19+ # The ability to integrate fzf's result into lldb uses copy and paste.
20+ # In absense of copy and paste, do the basics and forgo features.
21+ fzf_command = ("fzf" , "--no-sort" , f"--query={ query } " )
22+ subprocess .run (fzf_command , input = history )
1423 return
1524
1625 # Capture the current pasteboard contents to restore after overwriting.
@@ -23,18 +32,10 @@ def fzf_history(debugger, cmdstr, ctx, result, _):
2332 f"--query={ cmdstr } " ,
2433 "--bind=enter:execute-silent(echo -n {} | pbcopy)+close" ,
2534 )
26-
27- history_file = os .path .expanduser ("~/.lldb/lldb-widehistory" )
28- if not os .path .exists (history_file ):
29- result .SetError ("history file does not exist" )
30- return
31-
32- history_commands = _load_history (history_file )
33- fzf_input = "\n " .join (history_commands )
34- completed = subprocess .run (fzf_command , input = fzf_input , text = True )
35+ completed = subprocess .run (fzf_command , input = history , text = True )
3536 # 130 is used for CTRL-C or ESC.
3637 if completed .returncode not in (0 , 130 ):
37- result .SetError (f "fzf failed: { completed . stderr } " )
38+ result .SetError ("fzf failed" )
3839 return
3940
4041 # Get the user's selected history entry.
@@ -70,7 +71,7 @@ def _handle_command(debugger, command):
7071
7172
7273def _load_history (history_file ):
73- """Load, decode, and parse an lldb history file."""
74+ """Load, decode, parse, and prepare an lldb history file for fzf ."""
7475 with open (history_file ) as f :
7576 history_contents = f .read ()
7677
@@ -91,7 +92,7 @@ def _load_history(history_file):
9192 history_commands .append (line )
9293 history_seen .add (line )
9394
94- return history_commands
95+ return " \n " . join ( history_commands )
9596
9697
9798def _decode_char (match ):
0 commit comments