Code Monkey home page Code Monkey logo

Comments (9)

nvbn avatar nvbn commented on May 17, 2024

Thanks.

from thefuck.

zenoamaro avatar zenoamaro commented on May 17, 2024

@kballard, the bits about waste, quoting and sourcing instead of evaling are spot-on, but are you sure about history also including the currently running command?

$ echo foo
foo
$ echo (history | head -n1)
echo foo

Conversely, I find that history[2] yields the second-to-last command:

$ echo foo
foo
$ echo bar
bar
$ echo $history[2]
echo foo

This is with fish v2.1.1,

from thefuck.

lilyball avatar lilyball commented on May 17, 2024

That's odd. My several-months-old dev version of Fish 2.1.1, and my just-installed tip-of-master version of Fish 2.1.2, both behave as I described:

> echo foo
foo
> echo (history | head -n1)
echo (history | head -n1)
> echo foo
foo
> echo bar
bar
> echo $history[2]
echo bar

from thefuck.

zenoamaro avatar zenoamaro commented on May 17, 2024

I can see mentions of $history[1] in various threads:

Where ridiculousfish themself agree that it should return the last
executed command.

May be a difference in arch/plugins/etc? For comparison, this is Fish
v2.1.1 installed with Homebrew on OSX.

from thefuck.

lilyball avatar lilyball commented on May 17, 2024

I'm also running OS X.

I'm wondering now if maybe master has a bug where it's adding the command to history too eagerly. Note that master actually has a lot of changes from 2.1.2 (I believe master has been considered to be equivalent to at least 2.2 for a long time, and 2.1.1 / 2.1.2 were just minor changes from 2.1.0).

Given the state of things at the moment, I guess the install instructions should be changed to use $history[1] instead of $history[2] until this can be tracked down.

from thefuck.

lilyball avatar lilyball commented on May 17, 2024

Yep, the commit referenced in that issue fish-shell/fish-shell#984 (aa1b065dd1c03f7c0867d002badcf0dc88feb3c4) is the culprit. Building fish from before that commit expands $history[1] to the previous command instead of the current one. That commit is only on master, it's not in v2.1.2.

from thefuck.

zenoamaro avatar zenoamaro commented on May 17, 2024

Here is a repeatable test on a completely pristine machine from instantcloud.io with even older fish 2.1.0:

screen shot 2015-04-18 at 1 17 40 m

from thefuck.

lilyball avatar lilyball commented on May 17, 2024

I've filed fish-shell/fish-shell#2028 about this issue.

In the meantime, @nvbn, it seems clear that the instructions need to be changed to say $history[1] instead of $history[2] (but other than that, the new function is better than the old).

from thefuck.

zenoamaro avatar zenoamaro commented on May 17, 2024

I agree, if not only for the quoting and eval issues.

Performance is also (predictably) way better:

$ time -p fish -c 'for a in (seq 1000); history | head -n1 > /dev/null; end'
real         3.25
user         2.06
sys          1.58

$ time -p fish -c 'for a in (seq 1000); echo $history[1] > /dev/null; end'
real         1.32
user         0.65
sys          0.84

from thefuck.

Related Issues (20)

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.