
Show HN: McFly, a smart Bash history search CLI in Rust with a neural network - tectonic
https://github.com/cantino/mcfly
======
Wowfunhappy
TIL I can use ctrl+R to search bash history! This is going to save me a lot of
time going forward!

~~~
0db532a0
This is actually a general feature of the GNU readline library, which a lot of
programmes including bash use. For instance, a lot of REPLs like ghci use it.

[https://linux.die.net/man/3/readline](https://linux.die.net/man/3/readline)

[https://tiswww.cwru.edu/php/chet/readline/rltop.html](https://tiswww.cwru.edu/php/chet/readline/rltop.html)

~~~
majewsky
As does my favorite underappreciated Unix CLI tool, units(1).

    
    
      $ units --verbose
      You have: 1 mile * 20 pounds force
      You want: joule
              1 mile * 20 pounds force = 143174.38 joule
              1 mile * 20 pounds force = (1 / 6.98449e-06) joule

~~~
0db532a0
I had no idea of that command. Thanks.

------
infradig
I did virtually the same thing in about 1991. Was really into NNs back then.
Apparently that was the dark ages for NNs.

~~~
jacobush
I learned about them too back then. Programmed simple neurons in BASIC. 1993 a
friend of mine wrote back-propagation networks in C on his Amiga.

------
rane
For zsh, zaw[1]'s history is insanely useful. I don't really think a neural
network is needed. Usually I get to the exact line I wanted with a few
keystrokes.

[1]: [https://github.com/zsh-users/zaw](https://github.com/zsh-users/zaw)

------
fenrisbear
Would it be much work to make this work with other shells? Personally I use
fish, and would love to give this a spin with fzf.

~~~
tectonic
It shouldn't be too hard if someone wants to work on it.
[https://github.com/cantino/mcfly/issues/3](https://github.com/cantino/mcfly/issues/3)

------
tectonic
Also, my first Rust project!

~~~
bhargav_
This is such a cool project! Plus a pretty awesome example of using Rust for
CLI's. I'm curious about the neural network though. Is that also written in
Rust? Or are you embedding something else?

~~~
tectonic
Thanks! It is written in Rust. It's a very simple NN with one hidden layer and
back propagation.

~~~
bhargav_
Just saw the implementation. It's goes a little over my head unfortunately,
but I am curious about the affects of it. Did you compare the non-neural net
version with the neural net version? If so what differences did you find?

~~~
tectonic
I found that the neural network does a little better than a simple linear
regression function for weighting the parameters. I train it on a few months
of my own shell history to predict, based on the last commands, what I'll type
next.

~~~
2bitencryption
are the default weights I see in the code the result of your own local
training?

~~~
tectonic
Yup

------
xxpor
How does this compare with fzf?

~~~
tectonic
I think fzf is just for finding files?

~~~
kh_hk
no, fzf also does history, it uses `fc`. I think it should be doable to
integrate fzf with McFly.

~~~
tectonic
Good to know, thanks!

------
president
Cool project and well executed. My only complaints are:

1\. The GUI should display at the bottom of the screen rather than at the top.
I found myself constantly having to jump my eyes from the bottom of the
terminal where my command was, to the top of the screen.

2\. Show the full commands in the search results. Maybe they could be wrapped?
Long commands with changes towards the end of the string get chopped off
making it hard to know the differences between them in the display.

------
gojomo
Nifty! Is the neural network constantly being adjusted from the user's own
patterns of history re-use?

This also reminds me of one of my dream features for a shell: full dataflow
input/output/provenance histories, on a per-file(-version) basis.

For example: show all the commands a certain file has been read from, show the
command(s) that wrote to a file, show true steps by which a certain file was
constructed from predecessor files/commands, etc.

~~~
tectonic
Good question. At the moment it's static. I plan to make it do online learning
at some point where it updates the weights as you use it.

~~~
2bitencryption
this is a really nice example of a simple, practical, "non-deep" NN. I'm
wondering, are there any good learning resources you could recommend to start
a project like this?

It makes me want to try a personal project that makes use of a tiny light-
weight NN as well. I see giant AlphaGo neural nets mentioned so frequently
that I forgot they could be lean :)

~~~
tectonic
I read some tutorials on back propagation for this, but if you want to get
into ML in general, I highly recommend fast.ai and Andrew Ng's free Stanford
ML course.

------
akhilcacharya
Is there any reason that you hardcoded the model? I think its the right
decision for a small model, I was just sort of surprised.

~~~
tectonic
You can retrain it once you have a bunch of data with the train command. But
I'll probably make it do online learning at some point too.

------
ykevinator
Great name

~~~
tectonic
Thanks!

------
heyleo
neat application! I was curious if the Rust community has existing machine
learning/neural net libraries and found this:

[http://www.arewelearningyet.com/](http://www.arewelearningyet.com/)

thought I'd share in case you/others wanted to avoid coding their own or
experiment quickly with other types of models.

------
tinchox5
It's fantastic and very useful! Good work!!

~~~
tectonic
Thanks :)

