GithubHelp home page GithubHelp logo

cantino / mcfly Goto Github PK

View Code? Open in Web Editor NEW
6.8K 33.0 176.0 10.56 MB

Fly through your shell history. Great Scott!

License: MIT License

Rust 88.48% Shell 9.18% Ruby 0.47% PowerShell 1.86%
rust shell history search

mcfly's Introduction

Seeking co-maintainers: I don't have much time to maintain this project these days. If someone would like to jump in and become a co-maintainer, it would be appreciated!

Build Status

McFly - fly through your shell history

screenshot

McFly replaces your default ctrl-r shell history search with an intelligent search engine that takes into account your working directory and the context of recently executed commands. McFly's suggestions are prioritized in real time with a small neural network.

TL;DR: an upgraded ctrl-r where history results make sense for what you're working on right now.

Features

  • Rebinds ctrl-r to bring up a full-screen reverse history search prioritized with a small neural network.
  • Augments your shell history to track command exit status, timestamp, and execution directory in a SQLite database.
  • Maintains your normal shell history file as well so that you can stop using McFly whenever you want.
  • Unicode support throughout.
  • Includes a simple action to scrub any history item from the McFly database and your shell history files.
  • Designed to be extensible for other shells in the future.
  • Written in Rust, so it's fast and safe.
  • You can type % to match any number of characters when searching.

Prioritization

The key feature of McFly is smart command prioritization powered by a small neural network that runs in real time. The goal is for the command you want to run to always be one of the top suggestions.

When suggesting a command, McFly takes into consideration:

  • The directory where you ran the command. You're likely to run that command in the same directory in the future.
  • What commands you typed before the command (e.g., the command's execution context).
  • How often you run the command.
  • When you last ran the command.
  • If you've selected the command in McFly before.
  • The command's historical exit status. You probably don't want to run old failed commands.

Installation

Install with Homebrew (on macOS or Linux)

  1. Install mcfly:

    brew install mcfly
  2. Add the following to the end of your ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish file:

    Bash:

    eval "$(mcfly init bash)"

    Zsh:

    eval "$(mcfly init zsh)"

    Fish:

    mcfly init fish | source
  3. Run . ~/.bashrc / . ~/.zshrc / source ~/.config/fish/config.fish or restart your terminal emulator.

Uninstalling with Homebrew

  1. Remove mcfly:
    brew uninstall mcfly
  2. Remove the lines you added to ~/.bashrc / ~/.zshrc / ~/.config/fish/config.fish.

Install with MacPorts (on macOS)

  1. Update the ports tree

    sudo port selfupdate
  2. Install mcfly:

    sudo port install mcfly
  3. Add the following to the end of your ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish file, as appropriate:

    Bash:

    eval "$(mcfly init bash)"

    Zsh:

    eval "$(mcfly init zsh)"

    Fish:

    mcfly init fish | source
  4. Run . ~/.bashrc / . ~/.zshrc / source ~/.config/fish/config.fish or restart your terminal emulator.

Uninstalling with MacPorts

  1. Remove mcfly:
    sudo port uninstall mcfly
  2. Remove the lines you added to ~/.bashrc / ~/.zshrc / ~/.config/fish/config.fish.

Installing using our install script (macOS or Linux)

  1. curl -LSfs https://raw.githubusercontent.com/cantino/mcfly/master/ci/install.sh | sh -s -- --git cantino/mcfly (or, if the current user doesn't have permissions to edit /usr/local/bin, then use sudo sh -s.)

  2. Add the following to the end of your ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish file, respectively:

    Bash:

    eval "$(mcfly init bash)"

    Zsh:

    eval "$(mcfly init zsh)"

    Fish:

    mcfly init fish | source
  3. Run . ~/.bashrc / . ~/.zshrc / source ~/.config/fish/config.fish or restart your terminal emulator.

Installing manually from GitHub (macOS or Linux)

  1. Download the latest release from GitHub.

  2. Install to a location in your $PATH. (For example, you could create a directory at ~/bin, copy mcfly to this location, and add export PATH="$PATH:$HOME/bin" to your .bashrc / .zshrc, or run set -Ua fish_user_paths "$HOME/bin" for fish.)

  3. Add the following to the end of your ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish, respectively:

    Bash:

    eval "$(mcfly init bash)"

    Zsh:

    eval "$(mcfly init zsh)"

    Fish:

    mcfly init fish | source
  4. Run . ~/.bashrc / . ~/.zshrc / source ~/.config/fish/config.fish or restart your terminal emulator.

Install manually from source (macOS, Linux, or Windows)

  1. Install Rust 1.40 or later

  2. Run git clone https://github.com/cantino/mcfly and cd mcfly

  3. Run cargo install --path .

  4. Ensure ~/.cargo/bin is in your $PATH.

  5. Add the following to the end of your ~/.bashrc, ~/.zshrc, ~/.config/fish/config.fish, or powershell $PROFILE, respectively:

    Bash:

    eval "$(mcfly init bash)"

    Zsh:

    eval "$(mcfly init zsh)"

    Fish:

    mcfly init fish | source

    Powershell Core (pwsh)

    Invoke-Expression -Command $(mcfly init powershell | out-string)
  6. Run . ~/.bashrc / . ~/.zshrc / source ~/.config/fish/config.fish / . $PROFILE or restart your terminal emulator.

Install by Zinit

  • Add below code to your zshrc.

    zinit ice lucid wait"0a" from"gh-r" as"program" atload'eval "$(mcfly init zsh)"'
    zinit light cantino/mcfly
  • It will download mcfly and install for you.

  • $(mcfly init zsh) will be executed after prompt

iTerm2

To avoid McFly's UI messing up your scrollback history in iTerm2, make sure this option is unchecked:

iterm2 UI instructions

Dump history

McFly can dump the command history into stdout.

For example:

mcfly dump --since '2023-01-01' --before '2023-09-12 09:15:30'

will dump the command run between 2023-01-01 00:00:00.0 to 2023-09-12 09:15:30(exclusive) as json. You can specify csv as dump format via --format csv as well.

Each item in dumped commands has the following fields:

  • cmd: The run command.
  • when_run: The time when the command ran in your local timezone.

You can dump all the commands history without any arguments:

mcfly dump

Timestamp format

McFly use chrono-systemd-time-ng parsing timestamp.

chrono-systemd-time-ng is a non-strict implementation of systemd.time, with the following exceptions:

  • time units must accompany all time span values.
  • time zone suffixes are not supported.
  • weekday prefixes are not supported.

Users of McFly simply need to understand specifying timezone in timestamp isn't allowed. McFly will always use your local timezone.

For more details, please refer to the document of chrono-systemd-time-ng.

Regex

Dump supports filtering commands with regex. The regex syntax follows crate regex.

For example:

mcfly dump -r '^cargo run'

will dump all command prefixes with cargo run.

You can use -r/--regex and time options at the same time.

For example:

mcfly dump -r '^cargo run' --since '2023-09-12 09:15:30'

will dump all command prefixes with cargo run ran since 2023-09-12 09:15:30.

Settings

A number of settings can be set via environment variables. To set a setting you should add the following snippets to your ~/.bashrc / ~/.zshrc / ~/.config/fish/config.fish.

Light Mode

To swap the color scheme for use in a light terminal, set the environment variable MCFLY_LIGHT.

bash / zsh:

export MCFLY_LIGHT=TRUE

fish:

set -gx MCFLY_LIGHT TRUE

powershell:

$env:MCFLY_LIGHT = "TRUE"

Tip: on macOS you can use the following snippet for color scheme to be configured based on system-wide settings:

bash / zsh:

if [[ "$(defaults read -g AppleInterfaceStyle 2&>/dev/null)" != "Dark" ]]; then
    export MCFLY_LIGHT=TRUE
fi

VIM Key Scheme

By default Mcfly uses an emacs inspired key scheme. If you would like to switch to the vim inspired key scheme, set the environment variable MCFLY_KEY_SCHEME.

bash / zsh:

export MCFLY_KEY_SCHEME=vim

fish:

set -gx MCFLY_KEY_SCHEME vim

powershell:

$env:MCFLY_KEY_SCHEME="vim"

Fuzzy Searching

To enable fuzzy searching, set MCFLY_FUZZY to an integer. 0 is off; higher numbers weight toward shorter matches. Values in the 2-5 range get good results so far; try a few and report what works best for you!

bash / zsh:

export MCFLY_FUZZY=2

fish:

set -gx MCFLY_FUZZY 2

powershell:

$env:MCFLY_FUZZY=2

Results Count

To change the maximum number of results shown, set MCFLY_RESULTS (default: 10).

bash / zsh:

export MCFLY_RESULTS=50

fish:

set -gx MCFLY_RESULTS 50

powershell:

$env:MCFLY_RESULTS=50

Delete without confirmation

To delete without confirmation, set MCFLY_DELETE_WITHOUT_CONFIRM to true.

bash / zsh:

export MCFLY_DELETE_WITHOUT_CONFIRM=true

fish:

set -gx MCFLY_DELETE_WITHOUT_CONFIRM true

powershell:

$env:MCFLY_DELETE_WITHOUT_CONFIRM="true"

Interface view

To change interface view, set MCFLY_INTERFACE_VIEW (default: TOP). Available options: TOP and BOTTOM

bash / zsh:

export MCFLY_INTERFACE_VIEW=BOTTOM

fish:

set -gx MCFLY_INTERFACE_VIEW BOTTOM

powershell:

$env:MCFLY_INTERFACE_VIEW="BOTTOM"

Disable menu interface

To disable the menu interface, set the environment variable MCFLY_DISABLE_MENU.

bash / zsh:

export MCFLY_DISABLE_MENU=TRUE

fish:

set -gx MCFLY_DISABLE_MENU TRUE

powershell:

$env:MCFLY_DISABLE_MENU=true

Results sorting

To change the sorting of results shown, set MCFLY_RESULTS_SORT (default: RANK). Possible values RANK and LAST_RUN

bash / zsh:

export MCFLY_RESULTS_SORT=LAST_RUN

fish:

set -gx MCFLY_RESULTS_SORT LAST_RUN

powershell:

$env:MCFLY_RESULTS_SORT="LAST_RUN"

Custom Prompt

To change the prompt, set MCFLY_PROMPT (default: $).

bash / zsh:

export MCFLY_PROMPT=""

fish:

set -gx MCFLY_PROMPT ""

powershell:

$env:MCFLY_PROMPT=">"

Note that only single-character-prompts are allowed. setting MCFLY_PROMPT to "<str>" will reset it to the default prompt.

Database Location

McFly stores its SQLite database in the standard location for the OS. On OS X, this is in ~/Library/Application Support/McFly, on Linux it is in $XDG_DATA_DIR/mcfly/history.db (default would be ~/.local/share/mcfly/history.db), and on Windows, it is %LOCALAPPDATA%\McFly\data\history.db. For legacy support, if ~/.mcfly/ exists, it is used instead.

Slow startup

If you have a very large history database and you notice that McFly launches slowly, you can set MCFLY_HISTORY_LIMIT to something like 10000 to limit how many records are considered when searching. In this example, McFly would search only the latest 10,000 entries.

Bash TIOCSTI

Starting with Linux kernel version 6.2, some systems have disabled TIOCSTI (which McFly previously used to write the selected command). McFly works around this issue by using two "dummy" keybindings, which default to ctrl-x 1 and ctrl-x 2. If you are using either of these for another purpose, you can set the MCFLY_BASH_SEARCH_KEYBINDING and MCFLY_BASH_ACCEPT_LINE_KEYBINDING, respectively, to something you are not using. If you would prefer to use the legacy TIOCSTI behavior, you can enable it by setting the sysctl variable dev.tty.legacy_tiocsti to 1 on your system and set the MCFLY_BASH_USE_TIOCSTI bash variable to 1.

HISTTIMEFORMAT

McFly currently doesn't parse or use HISTTIMEFORMAT.

Possible Future Features

  • Add a screencast to README.
  • Learn common command options and autocomplete them in the suggestion UI?
  • Sort command line args when coming up with the template matching string.
  • Possible prioritization improvements:
    • Cross validation & explicit training set selection.
    • Learn command embeddings

Development

Contributing

Contributions and bug fixes are encouraged! However, we may not merge PRs that increase complexity significantly beyond what is already required to maintain the project. If you're in doubt, feel free to open an issue and ask.

Running tests

cargo test

Releasing (notes for @cantino)

  1. Edit Cargo.toml and bump the version.
  2. Edit CHANGELOG.txt
  3. Run cargo clippy and cargo fmt.
  4. Recompile (cargo build) and test (cargo test)
  5. git add -p
  6. git ci -m 'Bumping to vx.x.x'
  7. git tag vx.x.x
  8. git push origin head --tags
  9. Let the build finish.
  10. Edit the new Release on Github.
  11. cargo publish
  12. TBD: update homebrew-core Formula at https://github.com/Homebrew/homebrew-core/blob/master/Formula/m/mcfly.rb

Old:

  1. Edit pkg/brew/mcfly.rb and update the version and SHAs. (shasum -a 256 ...)
  2. Edit ../homebrew-mcfly/pkg/brew/mcfly.rb too.
  3. cp pkg/brew/mcfly.rb ../homebrew-mcfly/pkg/brew/mcfly.rb
  4. Compare with diff ../homebrew-mcfly/pkg/brew/mcfly.rb ../mcfly/pkg/brew/mcfly.rb ; diff ../homebrew-mcfly/HomebrewFormula/mcfly.rb ../mcfly/HomebrewFormula/mcfly.rb
  5. git add -p && git ci -m 'Update homebrew' && git push
  6. cd ../homebrew-mcfly && git add -p && git ci -m 'Update homebrew' && git push && cd ../mcfly

mcfly's People

Contributors

agrism avatar akinomyoga avatar b3nj5m1n avatar bnprks avatar cantino avatar dmfay avatar domoritz avatar f355 avatar federicotdn avatar freamon avatar goddade avatar jamjar00 avatar jirutka avatar jtschuster avatar kothavade avatar lukaspietzschmann avatar manfredlotz avatar markusjevringgoeuro avatar marshall avatar melkor333 avatar namorzyny avatar navazjm avatar nicokosi avatar otherjl0 avatar praveenperera avatar rawkode avatar safarimonkey avatar td-sky avatar vmax avatar zampierilucas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mcfly's Issues

Support zsh

/usr/local/opt/mcfly/mcfly.bash:23: command not found: shopt
/usr/local/opt/mcfly/mcfly.bash:47: command not found: bind

change other bash history env?

This has been in my .bashrc for many years:

export HISTSIZE=100000
export HISTTIMEFORMAT=': %Y-%m-%d_%H:%M:%S; '
export HISTIGNORE="&:ls:ll:[bf]g:w:who:exit:history"
export HISTCONTROL="ignoreboth"

I'm looking at swapping in mcfly. Do I need to modify these in any way? Does mcfly's database honor HISTSIZE or does it store/remember forever?

Temp file creation issue on start

When attempt to make temp file in mcfly.bash is made it ends up with this error:

mktemp: cannot create temp file /tmp/mcfly.XXXX: Invalid argument

Googling a bit showed, that adding more X to the temp file creation command solves the problem.

I'm using Slackware Linux x64.

Highlight search string in a case-insensitive way

Right now search is done in a case-insensitive way, but in found commands matched fragments are highlighted in respect for case. In this situation it becomes hard to spot in a command why it was found at all.

I'm proposing to use approach from PhpStorm IDE: highlight what's being searched for. As for implementation:

  1. lowercase found data to get string offset to highlight
  2. apply highlighting based on above found offset, but use original (non-lowercased) found data

Example when command is found, but not highlighted:
2019-02-11_1722

Example when command is found and is highlighted:
2019-02-11_1722-1

Fish support

This looks awesome, and admittedly this is more of a question than an issue per se. 😄

Any plans to add support for Fish shell?

crates.io upload

Would it be possible to put mcfly on crates.io so that installation works with "cargo install"?
As a Linux user i don't even know what "brew" is ;)

Case sensitive match

Just a feature request: Similar to what some editor's autocomplete does, when the user types in all lowercase letters, behaves case insensitively by default. But if the input contains any uppercase letters, switches to case sensitive mode by giving each exactly matched character some extra points so those candidates rank higher on the list.

This is useful when the command starts with an environment variable, e.g., RUST_LOG=....

Stray messages are shown in the bash scrollback

If I run a command in bash:

$ echo goodbye world
goodbye world

I then press Ctrl-r goodbye Ctrl-c, and I see this in my bash session:

$ echo goodbye world
goodbye world
$ #mcfly: 
$  mcfly search
$ 

Unable to find all recent commands.

Unable to find all recent commands.

Some recently ran commands do not show up in mcfly at all.
Also the list of suggested commands is quite short.

In my case it would also be useful to retrieve a command that was executed in a different working directory.

Consider to add loading progress to first time run message

McFly: Importing Bash history for the first time. This may take a minute or two...

This is misleading. My .bash_history is about 5MB big and I keep seeing this message for at least 15 minutes on a quad core CPU. Another ugly side effect that no terminal windows can be spawned meanwhile - they stay locked (the workaround is simple, use a shell in a terminal that was already started before enabling mcfly, but this can be a problem if there's none). Perhaps you need to add some import progress like "x out of y lines from .bash_history are imported"?

cat /dev/urandom never closes

I'm trying to build a package for Nixos, but when I source the macfly.bash file, it hangs on the following line:

export MCFLY_SESSION_ID=$(cat /dev/urandom | env LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w 24 | head -n 1)

It's maybe due to the problem described in this forum. Cat is never stopped...

What seems to stop the command is using head -c 24 instead of the fold ... | head -n 1:

[sam@Waluigi:~/projects/mcfly]$ x=$(cat /dev/urandom | env LC_ALL=C tr -dc 'a-zA-Z0-9' | head -c 24)
tr: write error: Broken pipe
tr: write error
cat: write error: Broken pipe
[sam@Waluigi:~/projects/mcfly]$ echo $x
ktgQD1V2qVWbvuLUnFTEhwGg

But then the broken pipe errors appear as you can see. I think they could be discarded with

x=$(cat /dev/urandom 2>/dev/null| env LC_ALL=C tr -dc 'a-zA-Z0-9' 2>/dev/null | head -c 24)

Delete item from history interactively

When I am in the history viewer, I would like to be able to select an item in the list with the arrow keys, hit the delete key, and have it removed from history.

Unable to get desired command suggested

As far as I understand:

  1. the McFly is only able to suggest commands that were previously executed
  2. new commands are executed outside of McFly and therefore are never added to it's database as being executed from a particular folder (because current folder isn't logged in analyzed .bash_history file)
  3. since suggestions are given for current folder only, then new commands are never suggested
  4. only commands initially found in .bash_history file are suggested

At least it happens like this for me. Any idea why I'm experiencing such behavior?

Zsh

Awesome!! Any plan on making it available for zsh?

Bash crashes

Hi,

Everything was working and suddenly i got:

Warning: Program '/bin/bash' crashed.

I tried reinstalling a new version v0.2.4 (downloading zip etc). But to no avail. I have also removed the history.db and which also did not help.

My history settings:

export HISTFILESIZE=
export HISTSIZE=
export HISTTIMEFORMAT="[%F %T] "
export HISTFILE=~/.bash_eternal_history
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"

When removing source "/home/me/opt/mcfly/mcfly.bash" line from my .bashrc bash works again.

Below is an error that is generated in journald when starting bash with myfly:

Dec 09 10:34:59 hprp audit[14797]: ANOM_ABEND auid=1000 uid=1000 gid=1000 ses=2 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 pid=14797 comm="bash" exe="/usr/bin/bash" sig=11 res=1
Dec 09 10:34:59 hprp systemd[1]: Started Process Core Dump (PID 15455/UID 0).
Dec 09 10:34:59 hprp audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=systemd-coredump@39-15455-0 comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
Dec 09 10:34:59 hprp systemd-coredump[15456]: Process 14797 (bash) of user 1000 dumped core.
                                              
                                              Stack trace of thread 14797:
                                              #0  0x000055c474b2161f _hs_append_history_line (bash)
                                              #1  0x000055c474b24e13 read_history_range (bash)
                                              #2  0x000055c474ae86bc history_builtin (bash)
                                              #3  0x000055c474a97275 n/a (bash)
                                              #4  0x000055c474a99e12 n/a (bash)
                                              #5  0x000055c474a9b0d4 execute_command_internal (bash)
                                              #6  0x000055c474a9bc63 execute_command_internal (bash)
                                              #7  0x000055c474a9c9b6 execute_command (bash)
                                              #8  0x000055c474a9bc30 execute_command_internal (bash)
                                              #9  0x000055c474a9c9b6 execute_command (bash)
                                              #10 0x000055c474a9bc30 execute_command_internal (bash)
                                              #11 0x000055c474ae4cf4 parse_and_execute (bash)
                                              #12 0x000055c474a9068a execute_variable_command (bash)
                                              #13 0x000055c474a84109 parse_command (bash)
                                              #14 0x000055c474a841d8 read_command (bash)
                                              #15 0x000055c474a84460 reader_loop (bash)
                                              #16 0x000055c474a82b69 main (bash)
                                              #17 0x00007f2516aff413 __libc_start_main (libc.so.6)
                                              #18 0x000055c474a8330e _start (bash)
Dec 09 10:34:59 hprp audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=systemd-coredump@39-15455-0 comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? te

Thanks

Last exit code return 1 - mcfly.bash

Seems return exit code 1 when . ./{path to mcfly.bash} execute in .bashrc
The last exit code 1 disappear if I comment this line in mcfly.bash :

...
PROMPT_COMMAND="__last_exit=\$?;history -a \$MCFLY_HISTORY;mcfly add -
-exit \$__last_exit --append-to-histfile;history -cr \$MCFLY_HISTORY;$
{PROMPT_COMMAND}"
...

...but It does affect the program, myfly can;t save lastest history

Unable to add cmd_tpl to commands: SqliteFailure

On Linux/Debian i have the following problem:

# RUST_BACKTRACE=1 mcfly -d search

McFly: Upgrading McFly DB to version 3, please wait...thread 'main' panicked at 'Unable to add cmd_tpl to commands: SqliteFailure(Error { code: Unknown, extended_code: 1 }, Some("duplicate column name: cmd_tpl"))', libcore/result.rs:1009:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::panicking::default_hook::{{closure}}
             at libstd/sys_common/backtrace.rs:71
   2: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:227
             at libstd/panicking.rs:476
   3: std::panicking::continue_panic_fmt
             at libstd/panicking.rs:390
   4: rust_begin_unwind
             at libstd/panicking.rs:325
   5: core::panicking::panic_fmt
             at libcore/panicking.rs:77
   6: core::result::unwrap_failed
   7: mcfly::main
   8: std::rt::lang_start::{{closure}}
   9: main
  10: __libc_start_main
  11: _start
McFly: Upgrading McFly DB to version 3, please wait...thread 'main' panicked at 'Unable to add cmd_tpl to commands: SqliteFailure(Error { code: Unknown, extended_code: 1 }, Some("duplicate column name: cmd_tpl"))', libcore/result.rs:1009:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Mac issues

Great idea! Tried it on my Mac with bash from homebrew (4.4.23(1)-release) and faced a few issues:

  1. tr fails here: https://github.com/cantino/mcfly/blob/master/mcfly.bash#L8 with tr: Illegal byte sequence. Seems like LC_CTYPE is not enough, need to set LC_ALL=C, it seems to work that way.

  2. After pressing ctrl-r and ctrl-g to get back to the shell, I see this:

    [2018-12-04 02:25:56][prod] konstantin:~
    $ #mcfly:
    [2018-12-04 02:25:59][prod] konstantin:~
    $  mcfly search
    [2018-12-04 02:26:06][prod] konstantin:~
    $
    

    Looks like in this line: https://github.com/cantino/mcfly/blob/master/mcfly.bash#L47 it is executing commands quite literally in the shell, displaying what it's doing. Not sure if it's a mac funkiness or my particular setup or what, but it's annoying.

  3. In standard bash, after pressing ctrl-r and typing something I can keep scrolling back in time by pressing ctrl-r again, and I have a spinal reflex for that. mcfly just drops me back out to the shell, rendering itself effectively unusable for me.

Thanks for your effort. I will try to keep using it, despite the third point, and report what I find.

Multiline commands are sometimes split in bash history.

Multiline commands are sometimes split in bash history.

Pasting this in the terminal and then pasting the following:

some_function () {
  printf '1\t2\t3\n' \
    | awk -F '\t' '
    {
        print $1;
        print $2;
        print $3;
    }' \
    | cat 
}

In bash without mcfly, pressing the up key, will bring back this full entry (history command):

 2006  some_function () {   printf '1\t2\t3\n'     | awk -F '\t' '
    {
        print $1;
        print $2;
        print $3;
    }'     | cat ; }

With mcfly, this entry is splitted:

 1340  some_function () {   printf '1\t2\t3\n'     | awk -F '\t' '
 1341      {
 1342          print $1;
 1343          print $2;
 1344          print $3;
 1345      }'     | cat ; }

Scroll search results according to window height

When Terminal window can't fit all 10 results, then attempt to navigate into 6+ result just moves selection cursor out of the screen.

I'm proposing to implement clever scrolling, where search results are scrolled to fit inside visible Terminal window area.

CASE1 (works currently): when 10 results fits initially (14 lines occupied):

McFly | ESC - Exit | ⏎ - Run | TAB - Edit | F2 - Delete                                                                           

$ 

result1 <--- cursor here
result2
result3
result4
result5
result6
result7
result8
result9
result10

CASE2 (works currently): When 6 results fits initially (10 lines occupied):

McFly | ESC - Exit | ⏎ - Run | TAB - Edit | F2 - Delete                                                                           

$ 

result1 <--- cursor here
result2
result3
result4
result5
result6

CASE3 (proposed): When 6 results fits and I've scrolled to 7th result (10 lines occupied):

McFly | ESC - Exit | ⏎ - Run | TAB - Edit | F2 - Delete                                                                           

$ 

result2
result3
result4
result5
result6
result7 <--- cursor here

Real use case: Terminal opened inside PhpStorm.

Put a comparisons section in the README

The tool looks great, and for users who don't use a history replacement tool already it looks like a no-brainer.

For those of us who already use one— how does mcfly compare to fzf, hstr, peco etc? What features would really make us want to jump ship?

error if running multiple commands from different shells

I'm working with multiple bash shells and ran in the following error while I ran 3 commands in different shells:
thread 'main' panicked at 'McFly error: Unable to create schema_versions db table: SqliteFailure(Error { code: DatabaseBusy, extended_code: 5 }, Some("database is locked"))', src/libcore/result.rs:1009:5
note: Run with RUST_BACKTRACE=1 for a backtrace.

I'm using McFly version 0.3.3.

Crashes when non-unicode characters are present in `.bash_history`

I happened to have created a directory a while back that is invalid in any encoding scheme available in python, for testing. The mkdir and cd are then in my bash history file, and contain invalid unicode. I was able to reduce the reproducing example down to:

$ cat ~/.bash_history
cd �abc\\uXXXX/
$ xxd ~/.bash_history
00000000: 6364 2080 6162 635c 5c75 5858 5858 2f0a  cd .abc\\uXXXX/.

which causes the following crash:

thread 'main' panicked at '"/tmp/mcfly.HE5x" file not found: Custom { kind: InvalidData, error: StringError("stream did not contain valid UTF-8") }', libcore/result.rs:1009:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::panicking::default_hook::{{closure}}
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
             at libstd/panicking.rs:211
   2: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:227
             at libstd/panicking.rs:476
   3: std::panicking::continue_panic_fmt
             at libstd/panicking.rs:390
   4: rust_begin_unwind
             at libstd/panicking.rs:325
   5: core::panicking::panic_fmt
             at libcore/panicking.rs:77
   6: core::result::unwrap_failed
   7: mcfly::bash_history::full_history
   8: mcfly::bash_history::last_history_line
   9: mcfly::settings::Settings::parse_args
  10: mcfly::main
  11: std::rt::lang_start::{{closure}}
  12: main
  13: __libc_start_main
  14: _start

I tried the following diff, and ran into further errors:

# git diff
diff --git a/src/bash_history.rs b/src/bash_history.rs
index dcbc34c..014deec 100644
--- a/src/bash_history.rs
+++ b/src/bash_history.rs
@@ -12,12 +12,12 @@ pub fn bash_history_file_path() -> PathBuf {
 }
 
 pub fn full_history(path: &PathBuf) -> Vec<String> {
-    let bash_history_contents =
-        fs::read_to_string(&path).expect(format!("{:?} file not found", &path).as_str());
+    let bash_history_contents = fs::read_to_string(&path).unwrap_or_default();
 
     let timestamp_regex = Regex::new(r"\A#\d{10}").unwrap();
 
     bash_history_contents
+        .as_str()
         .split("\n")
         .filter(|line| !timestamp_regex.is_match(line) && !line.is_empty())
         .map(String::from)

After the above diff:

thread 'main' panicked at '"/tmp/mcfly.s88g" file not found: Custom { kind: InvalidData, error: StringError("stream did not contain valid UTF-8") }', libcore/result.rs:1009:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::panicking::default_hook::{{closure}}
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
             at libstd/panicking.rs:211
   2: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:227
             at libstd/panicking.rs:476
   3: std::panicking::continue_panic_fmt
             at libstd/panicking.rs:390
   4: rust_begin_unwind
             at libstd/panicking.rs:325
   5: core::panicking::panic_fmt
             at libcore/panicking.rs:77
   6: core::result::unwrap_failed
   7: mcfly::settings::Settings::parse_args
   8: mcfly::main
   9: std::rt::lang_start::{{closure}}
  10: main
  11: __libc_start_main
  12: _start

Permissions error on startup

Hi, I just installed mcfly to try it out on macOS 10.14.2 (beta 18C52a). I opened a new shell, and saw the "reading history for the first time" message. I closed that shell and opened another, and saw this message:

-bash: /var/folders/kb/bswbcrr56ld5cv7zzhyp57gr0000gn/T/mcfly.XXXX.qqMnwGRv: cannot overwrite existing file

If I remove the file, and open another shell, I get a message with a similar file name. When I ls -l the permissions string is -rw------- for the file, and drwx------@ 254 gwk staff 8128 Dec 3 19:02 T for the parent T directory. Any ideas?

Consider to add README to binary release tarballs?

Once you learn it, it's simple: have mcfly in PATH and source the provided shell script. But a total beginner still may need to go back to the github repo to read the README after downloading the binary release. I suppose binary releases are often a choice for first time end users, since rust is still quite new and exotic / not available everywhere by default / not trivial to use to compile from source by someone who knows nothing about it. Having the README in the binary release tarball would make it self-sufficient.

Question: Is Midnight Commander supported?

In Midnight Commander:

  • current directory logically changes when you switch from one panel into another and back, but I'm not sure if Bash is able to detect that
  • PROMPT_COMMAND (that is changed by McFly) is also invoked

Have you checked that commands executed from Midnight Commander command line are tracked against proper directory?

how to get the most recent match ?

Hi, Thanks for this nice software.

Quite often, I want to recall a command I typed a few minutes ago (e.g. "git commit ..."), but mcfly proposes some much more older matching commands.
I understand that it is due to its algorithm, but I'd like to force it to output the matches ordered by "recentness".
Is that possible ?
Otherwise would it be possible to add a shortcut that will reorder the matches by recentness ?

Karl

Do not overwrite HISTFILE

I am using a custom HISTFILE name. And to keep it that way, I also make this variable readonly.

As mcfly does
export HISTFILE="${HISTFILE:-$HOME/.bash_history}"

this leads to an annoying warning:
bash: HISTFILE: readonly variable
A check like

if [ -z "${HISTFILE}" ]; then
    export HISTFILE="${HOME}/.bash_history"
fi

would prevent this warning for me.

Sqlite3 error: duplicate column name: cmd_tpl

@Lomanic wrote:

I'm trying McFly 0.3.3 (binary release x64 and manual install) on Debian 9 and I'm encountering the same error

McFly: Upgrading McFly DB to version 3, please wait...thread 'main' panicked at 'McFly error: Unable to add cmd_tpl to commands: SqliteFailure(Error { code: Unknown, extended_code: 1 }, Some("duplicate column name: cmd_tpl"))', src/libcore/result.rs:1009:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Setting export RUST_BACKTRACE=1 adds the following backtrace

stack backtrace:
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: main
  10: __libc_start_main
  11: <unknown>

For me mcfly.bash is properly sourced (MCFLY_SESSION_ID and MCFLY_HISTORY are set)

Here is the result of export RUST_BACKTRACE=1 && rm ~/.mcfly/history.db

McFly: Importing Bash history for the first time. This may take a minute or two...thread 'main' panicked at 'McFly error: Insert to work: NulError(NulError(0, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 49, 53, 51, 56, 56, 49, 51, 53, 49, 54]))', src/libcore/result.rs:1009:5
stack backtrace:
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: main
  10: __libc_start_main
  11: <unknown>

Panic when .bash_history is missing

Hi,

I started to get those messages whenever I open a new terminal:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', libcore/result.rs:1009:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

I can confirm they are coming from McFly because they disappear as soon as I remove the integration in my profile. Ie if I comment out this:

if [[ -f "$(brew --prefix)/opt/mcfly/mcfly.bash" ]]; then
  source "$(brew --prefix)/opt/mcfly/mcfly.bash"
fi

Sadly, the backtrace is not helpful:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', libcore/result.rs:1009:5
stack backtrace:
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>

I'm not 100% sure why/when it started. I'm guessing something changed on my machine but I'm not quite sure what. I upgraded to Mojave a couple weeks back but this only started a couple days ago. Aside from the message, everything else still works fine: I can use McFly and it records my commands properly.

Ideas?

Thanks!

Internal output not removed after closing

I have setup 2 line bash prompt, that looks like this (not sure if that causes issue to happen):

2019-02-09_0945

I then enable McFly by pressing Ctrl+R and immediately exit via Esc. After that I'm seeing that 2 commands were executed and are displayed on screen:

  • #mcfly:
  • mcfly search

2019-02-09_0946

Is there any reason for not to removing these commands (e.g. I'm not seeing any extra commands, when using native Ctrl+R search)?

Related #44

Doesn't work with WSL

Similarly to #22 I can open up the display, and choose my command, but in the end, all it tried to execute is mcfly search, no matter what I type or select.

[~]
$ #mcfly:
[~]
$  mcfly search
[~]
$
$ cat /etc/issue.net
Ubuntu 18.04.1 LTS

Light mode

Really enjoying mcfly, thanks for making it!

With the Solarized Light color scheme, all of the un-highlighted suggestions are invisible (see attached images).

screenshot 2018-12-04 10 01 18

screenshot 2018-12-04 10 00 59

If this isn't a priority for you, I'd be happy to hack on it some time.

I poked a bit through interface.rs and settings.rs. From a cursory examination, seems like one way to add a light mode would be for settings.rs to look for an environment variable (MCFLY_LIGHT?) around here, set a bool in settings, and then for menubar() prompt() and results() to act accordingly. Would that be your preferred way of propagating a setting like that?

Add GLIBC 2.16 compatible binary when releasing

I've downloaded mcfly-v0.3.1-x86_64-unknown-linux-gnu.tar.gz binary from a latest release and when running mcfly command I've got this error:

./mcfly: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by ./mcfly)

Doing ls -la /lib64/libc.so.6 command showed, that I have GLIBC_2.13:

lrwxrwxrwx 1 root root 12 Sep 21  2012 /lib64/libc.so.6 -> libc-2.13.so*

Would it be possible to also provide (in each release) Linux binary compiled against GLIBC 2.16?

P.S.
I was able to get McFly running by following manual compilation instructions, but was of course was a bit longer, then just using pre-compiled binary.

Question: Reason for initial completion not being empty?

When I press Ctrl+R for the first time the last command is shown automatically. This is radically different comparing to approach default Ctrl+R does, where no command is shown and I have to start typing.

Currently I have to delete suggested command first (one-by-one symbol) and start typing what I actually wanted to see.

Maybe instead it's possible to show list of suggested commands below and by pressing Down arrow people then can manually confirm, that they want 1st suggested entry to be used.

Right now I don't have a choice really.

Search is prefilled with `mcfly search`

Immediately after installation mcfly seemed to work as expected. Upon a reboot, however, pressing ctrl+r gets me a mcfly session already prefilled with mcfly search - if I type a space and then a search term, and press enter, I find myself in another mcfly session with my search results. (If I omit the space I get a complaint from mcfly about 'the subcommand 'search<term>' wasn't recognized', which seems reasonable).

I have a custom PROMPT_COMMAND but nothing else noteworthy springs to mind.

Any ideas what might be interfering? I think I initially installed 0.2.3 (cleverly I deleted the tarfile after extracting it) and have upgraded to 0.2.4 with no change in behaviour.

Question: Any issues with "HISTCONTROL=ignoreboth"?

I have HISTCONTROL=ignoreboth (acts as ignorespace;ignoredups) in my .bash_profile file to avoid seeing same command again and again, when browsing through history using Up/Down arrows when I've executed same command several times.

As I've noticed it that takes priority over HISTCONTROL=ignorespace set in mcfly.bash.

Would that cause any problems to McFly ability to detect multiple sequential same command execution attempts and therefore increase probability for suggesting that command over other commands?

Add Ctrl-j/k movement bindings

I would like to be able to use Ctrl-j and Ctrl-k to move up and down, similar to the movement keys in FZF. Would this be possible?

Automatic Bash completion inclusion with Homebrew

Homebrew is able to automatically enable completion for installed packages without need to add below code to ~/.bashrc file:

if [[ -r "$(brew --prefix)/opt/mcfly/mcfly.bash" ]]; then
  source "$(brew --prefix)/opt/mcfly/mcfly.bash"
fi

when you have this code in there already (you should have it since it's part of Homebrew installation process):

if [ -f $(brew --prefix)/etc/bash_completion ]; then
  . $(brew --prefix)/etc/bash_completion
fi

Theoretically (I'm not creating Homebrew packages usually) adding below line to installation part of Homebrew Formula should do the trick:

bash_completion.install "mcfly.bash"

Maybe above line should replace prefix.install "mcfly.bash" line.

README improvement

Hi,
Please add "Usage" section to the readme file. And especially information about using '%' symbol as a way to use multiple searching patterns.
Thanks in advance

McFly makes noise when user moves a folder.

This just happened, and seems undesirable. I moved a folder and McFly prints a pointless message.

gwk ~/work/pdfminer3/test master*%> $ mv crypto/ decrypt
McFly: Command database paths renamed from /Users/gwk/work/pdfminer3/test/crypto to /Users/gwk/work/pdfminer3/test/decrypt (affected 0 commands)

SqliteFailure

• • • source mcfly.bash
• • •
McFly: Upgrading McFly DB to version 3, please wait...thread 'main' panicked at 'McFly error: Unable to add cmd_tp
l to commands: SqliteFailure(Error { code: Unknown, extended_code: 1 }, Some("duplicate column name: cmd_tpl"))',
src/libcore/result.rs:999:5
stack backtrace:
0:
1:
2:
3:
4:
5:
6:
7:
8: main
9: __libc_start_main
10:

Remove itself from ".bash_history"

I'm seeing #mcfly: entries, when using history command.

Since McFly does regenerate .bash_history file used by history command, then it likely could remove mentions to itself from there.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.