7 ms·
Show HN: McFly, a smart Bash history search CLI in Rust with a neural network
- tectonic 8y agoAlso, my first Rust project!
- bhargav_ 8y agoThis 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 8y agoThanks! It is written in Rust. It's a very simple NN with one hidden layer and back propagation.
- bhargav_ 8y agoJust 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 8y agoI 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 8y agoare the default weights I see in the code the result of your own local training?
- tectonic 8y agoYup
- the_jeremy 8y agoMinor nitpick: probably better to append to PROMPT_COMMAND, rather than overwriting it.
- tectonic 8y agoI do actually append to it: PROMPT_COMMAND="__last_exit=\$?;history -a \$MCFLY_HISTORY;mcfly add --exit \$__last_exit --append-to-histfile;history -cr \$MCFLY_HISTORY;${PROMPT_COMMAND}"
- faitswulff 8y agoWhat made you choose Rust? And what were your impressions of it for this project?
- tectonic 8y agoI wanted a fast, safe systems language. I enjoyed it! The learning curve is steep but then you start to get it.
- darkjedi_emacs 8y agohaha Feels same. My first program in rust was https://github.com/AkshayIyer12/advent-of-code/blob/master/2018/aoc1/src/main.rs https://github.com/AkshayIyer12/advent-of-code/blob/master/2... . Felt good finally writing some code in Rust after the rust lang book.
- xxpor 8y agoHow does this compare with fzf?
- tectonic 8y agoI think fzf is just for finding files?
- ykevinator 8y agoGreat name
- tectonic 8y agoThanks!
- fenrisbear 8y agoWould 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 8y agoIt 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
- qwerty456127 8y agoSame thing.
- tinchox5 8y agoIt's fantastic and very useful! Good work!!
- tectonic 8y agoThanks :)
- gojomo 8y agoNifty! 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 8y agoGood 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 8y agothis 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 8y agoI 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.
- 0db532a0 8y agoI’m still quite new to neural networks. Can you explain the material benefit to using a neural network over a priority queue with a similar weighting system? Are you giving any other input to the neural network than simply the metrics you listed? P.S. e.g. a polynomial over the metrics. P.P.S. I imagine you’re using the neural network to tune the weights?
- 8y ago
- akhilcacharya 8y agoIs 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 8y agoYou 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.
- Wowfunhappy 8y agoTIL I can use ctrl+R to search bash history! This is going to save me a lot of time going forward!
- jaster 8y agoAdditional tip: if you overshoot and miss the command you wanted by hitting ctrl+R too much times (as it happens sometime when looking for an older command), you can go forward with ctrl+S. [EDIT: As Hikikomori pointed (thanks!), I got my shortcuts mixed up, ctrl+S is the shortcut for zsh, and the equivalent for bash is ctrl+shift+R] (ctrl+S and ctrl+R are based on emacs shortcuts, where ctrl+S is search and ctrl+R is reverse search)
- Hikikomori 8y agoDoesn't work on GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18) ctrl+shift+r works though.
- jaster 8y agoYep you're right, I got my shortcuts between bash and zsh mixed-up. I edited my post, thanks for the correction. (Not sure why bash did not go the obvious route here, I guess they already had something on ctrl+S when they implemented forward search...) EDIT: actually, you can activate ctrl+S for search-foward on bash by using `stty -ixon`. See more info about why here https://unix.stackexchange.com/questions/141422/searching-history-in-bash-forward-after-backward https://unix.stackexchange.com/questions/141422/searching-hi...
- fnord123 8y agoctrl-s is usually for pausing the terminal (where ctrl-q resumes it). https://en.wikipedia.org/wiki/Software_flow_control https://en.wikipedia.org/wiki/Software_flow_control
- 0db532a0 8y agoNote that your terminal emulator needs to pass the ctrl+S through. ctrl+S won’t work by default in a lot of cases from personal experience.
- infradig 8y agoI did virtually the same thing in about 1991. Was really into NNs back then. Apparently that was the dark ages for NNs.
- jacobush 8y agoI 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 8y agoFor 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
- heyleo 8y agoneat 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.
- president 8y agoCool 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.