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
#!/bin/bash
# Avoid loading this file more than once
if ; then
fi
__MCFLY_LOADED="loaded"
if ;
then
|
else
|
fi
# Ignore commands with a leading space
# Append new history items to .bash_history
# Set $PROMPT_COMMAND to do the following:
# 1. record exit status of previous command
# 2. append history to $MCFLY_HISTORY
# 3. run mcfly
# a. tell mcfly the exit status
# b. tell mcfly to append commands to $HISTFILE (~/.bash_history by default) for backwards compatibility and
# to load in new terminal sessions
# c. mcfly will find the text of the last command in $MCFLY_HISTORY and save it to the database
# 4. clear the in-memory history and reload it from $MCFLY_HISTORY (to remove instances of '#mcfly: ' from the
# local session history)
# 5. run whatever was already in $PROMPT_COMMAND
PROMPT_COMMAND="__last_exit=\$?;history -a \$MCFLY_HISTORY;mcfly add --exit \$__last_exit --append-to-histfile;history -cr \$MCFLY_HISTORY;"
# If this is an interactive shell, take ownership of ctrl-r.
# The logic here is:
# 1. Jump to the beginning of the edit buffer, add 'mcfly: ', and comment out the current line. We comment out the line
# to ensure that all possible special characters, including backticks, are ignored. This commented out line will
# end up as the most recent entry in the $MCFLY_HISTORY file.
# 2. Type "mcfly search" and then run the command. McFly will pull the last line from the $MCFLY_HISTORY file,
# which should be the commented-out search from step #1. It will then remove that line from the history file and
# render the search UI pre-filled with it.
if ; then
fi