Skip to content

stop pasting leading spaces #4327

Closed
Closed

Description

@obfuscated

Fish 2.6.0 on Gentoo linux, Terminology, no customizations.

The problem is that fish doesn't place every command in the history buffer. The last case happened when I had leading spaces in my commands. But most often this happens when there is some error in the parsing of the command or something that fish doesn't like.
I want and I'm used to that every time I press enter to execute something it enters the history butter, and I can bring it back pressing up arrow.

The simplest example is this one:

> echo "bla0"
bla0
> echo "bla1"
bla1
> echo "bla0" <-- this is what happens if I press the up-arrow key

Activity

  1. krader1961 commented on Aug 13, 2017

    @krader1961
    Contributor

    ... happened when I had leading spaces in my commands.

    This is expected behavior. It's borrowed from bash. Personally I don't like it. Also, fish has a way to switch to different history files and even disable history completely if you're doing something like a demo and don't want sensitive info from your normal command history to be visible.

    But most often this happens when there is some error in the parsing of the command or something that fish doesn't like.

    This is also by design and expected behavior.

    The simplest example is this one:

    I can't reproduce that behavior. And if that happened even infrequently I'm pretty confident we would know about it. If you run a few commands (including your echo examples) then run builtin history search -15 --show-time="%a %m-%d %R " does it show every command you ran?

  2. obfuscated commented on Aug 13, 2017

    @obfuscated
    Author

    @krader1961 The shell I'm using most of the time is bash, so I'm used to its behaviour and I'm complaining here because fish does unexpected and strange things that hinder my productivity.

    Here is the same example done in bash 4.4.12(1)

    $ echo "test0"
    test0
    $ echo "test1" <-- there are two spaces after the $
    test1
    $ echo "test1" <-- this is what happens if I press the up-arrow key

    I have no idea if the history file and the list of commands accessed with up arrow are the same.
    I don't see a reason why an executed command which has leading spaces in its string is not added to the list accessed with up-arrow. It should enter the history file, too, I don't know if it has to be trimmed or not, but I don't care.

    FIY: I get these leading spaces by accident after I've remove something at the start of the command, but I've forgotten to remove the spaces. So this behaviour is 100% non-intentional and 100% surprising.

    dir > echo "bla0"
    bla0
    dir > echo "bla1"
    bla1
    dir > echo "bla2" <-- leading space before echo
    bla2
    dir > echo "bla3" <-- leading space before echo
    bla3
    dir > builtin history search -4 --show-time="%a %m-%d %R "
    Sun 08-13 21:42 echo "bla1"
    Sun 08-13 21:42 echo "bla0"
    Sun 08-13 21:42 builtin history search -3 --show-time="%a %m-%d %R "
    Sun 08-13 21:41 builtin history search -e --show-time="%a %m-%d %R "

  3. krader1961 commented on Aug 13, 2017

    @krader1961
    Contributor

    From the documentation:

    Prefixing the commandline with a space will prevent the entire line from being stored in the history.

    Suggestions on how to make this more discoverable are welcome. The fish behavior is based on this section of the bash man page:

       HISTCONTROL
             A colon-separated list of values controlling how commands are saved  on  the
             history list.  If the list of values includes ignorespace, lines which begin
             with a space character are not saved  in  the  history  list.
    

    Apparently enough people converting from bash like this feature it convinced the fish devs to make it the default. It's been discussed a couple of times in the past 1.5 years that I've been contributing to the fish project. And each time the outcome was to retain the current behavior. Having said that I agree with you that it is surprising and hard to discover why it occurs. It can't be changed in our next, and final, 2.x release. But we can discuss changing it for the upcoming 3.0.0 release. Especially since we now have the FISH_HISTORY mechanism which is a more robust and easier method of ensuring sensitive commands aren't inadvertently disclosed.

  4. obfuscated commented on Aug 13, 2017

    @obfuscated
    Author

    Interesting. It seems this is the default on Ubuntu. In Gentoo it is not. I'm not 100% sure about CentOS, but I'll check as soon as I get to my work machine.

  5. mqudsi commented on Aug 14, 2017

    @mqudsi
    Contributor

    I would be very against changing this behavior, there's a valid use case (though questionable practice) for this in keeping secrets out of your history file. For example, when setting an environment variable access key or, more often, specifying the password for a connection as an argument (mysql -p, I'm looking at you!).

    It's one of those things that you almost never use, almost never hurt you, but when you need it, you're glad it's there. How many complaints about this have we had over the years?

  6. krader1961 commented on Aug 14, 2017

    @krader1961
    Contributor

    How many complaints about this have we had over the years?

    Probably impossible to get even a SWAG that's within an order of magnitude of the actual number. But I know that I was surprised by it the first time I encountered it and continue to be surprised for the same reason @obfuscated mentioned: If I accidentally leave leading whitespace as an artifact of editing a command the command doesn't get saved. Too, there have been a few discussions about this in the 1.9 years I've been using fish because others have noticed the same surprising behavior.

    How many people know that this feature exists? I'm willing to bet real money that if we could survey our user base it would be single digit percentages. Very likely less that 5%. The main problem is that it is both obscure (hard to discover), surprising, and hard to debug. It is very much a "power" feature used by an insignificant percentage of our user base.

    It is true that until recently, see issues #102 and #1504, there wasn't a viable alternative to not storing sensitive information in the command history. But as of the upcoming fish 2.7.0 release we have the FISH_HISTORY variable which you can change on the fly, or before launching a fish shell, to control where command history is written. If you're going to be running commands you don't want saved in the history just launch a fish subshell with it set to the empty string to not save any commands you type in that shell or a special prefix to use a history file that contains only sensitive command history. Then exit that subshell to get back to normal command history.

  7. krader1961 commented on Aug 14, 2017

    @krader1961
    Contributor

    Also, you might be wondering how to know if you're not using the normal command history. After all, if I do something to enter that special history logging subshell I might forget that I have done so and find that non-sensitive commands are no longer being retrieved from, or saved to, my usual history. Much to my annoyance.

    The answer is simple, use a custom fish_prompt function which provides an indication when FISH_HISTORY is not set to the default (fish) value. Then you'll be reminded when you're in a special subshell that isn't logging commands to your normal history file. This might even be something we want to do by default. Like we do for the fish Vi mode indicator via the fish_mode_prompt function to let the user know whether they are in Vi insert or command mode.

  8. mqudsi commented on Aug 14, 2017

    @mqudsi
    Contributor

    I just feel like that's such a complicated solution to that question. Maybe I'm mistaken, but part of what makes me firm in my resolve is that I don't see a missing history as a big deal (when there exists an explanation for it, so it's not some phantom bug). So you trade the minor irritation of not having a whitespace-artifacted command in your history for the ability to just prefix with a single space anything you don't want in the history buffer.

    A suggestion that might mitigate the problem: bracketed paste can trim leading and trailing whitespace.

    I've had accidental whitespace artifacts mean my terminal history was incomplete myself, and off the top of my head, I think it's never happened except as a result of copy-and-paste (it's not like I accidentally typed a leading space). Would that take care of your accidental whitespace scenarios too, @krader1961 ?

  9. faho commented on Aug 14, 2017

    @faho
    Member

    @obfuscated: Note that, in this example:

    > echo "bla0"
    bla0
    > echo "bla1"
    bla1
    > echo "bla0" <-- this is what happens if I press the up-arrow key

    I'm willing to bet that echo "bla1" appears as a suggestion (greyed-out in the commandline), which stops it from appearing in history navigation. See #405.

  10. obfuscated commented on Aug 14, 2017

    @obfuscated
    Author

    @faho In my version the bla1 line looks exactly the same as bla0. So you're losing this virtual bet. :)

  11. faho commented on Aug 14, 2017

    @faho
    Member

    @obfuscated: What I mean is: After executing those commands, start typing echo "b. It should show a greyed out la1" after that, in the commandline. Press up-arrow. It should directly jump to echo "bla0". Clear the commandline and start typing echo "b. When the suggestion is shown press right-arrow, it should accept the la1".

  12. obfuscated commented on Aug 14, 2017

    @obfuscated
    Author

    @faho OK, You're correct, but I think it is unrelated to the issue. I'm not typing echo, I'm pressing up arrow and I'm surprised by the behaviour.

  13. faho commented on Aug 14, 2017

    @faho
    Member

    Yes, but as soon as something from history is selected for the suggestion, it is excluded from history-navigation.

    Or are you pressing up-arrow before that shows up?

  14. obfuscated commented on Aug 14, 2017

    @obfuscated
    Author

    @faho I execute a command. It fails or I cancel it, because I want to change something. The command produces tons of output. I press up-arrow (on an empty) line and I get a command I'm not expecting. This is very common behaviour of fish.

  15. mqudsi commented on Aug 14, 2017

    @mqudsi
    Contributor

    @obfuscated I think you meant "I execute a command that has leading whitespace..." as it is a very specific case.

    Like mentioned before, this is also how bash (the most popular and ubiquitous shell apart from sh) behaves.

  16. 20 remaining items

  17. mqudsi commented on Oct 18, 2017

    @mqudsi
    Contributor

    This was my motivation for implementing the new read command syntax. You can simply use (read -i) anywhere you need to securely enter a password.

  18. cben commented on Dec 17, 2017

    @cben
    Contributor

    Proposal: whether you change it or not, display a hint after executing a command with leading space, ideally explaining how to achieve the opposite:

    fish>   accidentally indented
    ...output...
    Note: command started with space, will be omitted from history.  Run 'history add-last-omitted' if you want it.
    

    or:

    fish>   secret command
    ...output...
    Note: command started with space, fish now saves such command in history!  Run `history delete -n 1` if undesired.
    

    (both history syntaxes fictional, delete doesn't currently allow -n 1 / --max 1 flag.)

    @madblobfish's proposal of vanishing message while typing is I think even cooler, avoids need to explain how to undo.

  19. modified the milestones: , fish-future on Feb 28, 2018
  20. BarbzYHOOL commented on Jul 19, 2018

    @BarbzYHOOL

    What would be nice is to have it as a config option, so we could disable that feature.

  21. BarbzYHOOL commented on Jul 28, 2018

    @BarbzYHOOL

    Also I have written tons of tutorials for myself when I used bash, and I indented all the commands (a bit like we do in markdown on github)

    and now everytime i copy them into fish, i deal with this issue :'(

  22. floam commented on Dec 11, 2018

    @floam
    Member

    I think only ignoring commands with exactly one leading space would be a reasonable change. The accidental stuff from bad pastes tends to be a few spaces for me.

  23. ThomasAH commented on Dec 11, 2018

    @ThomasAH

    I think only ignoring commands with exactly one leading space would be a reasonable change. The accidental stuff from bad pastes tends to be a few spaces for me.

    This would be fine for me (as written above, our internal documentation has two leading spaces), but still sounds quite magic/surprising.

  24. mqudsi commented on Dec 11, 2018

    @mqudsi
    Contributor

    That is probably even more confusing. I think ignoring leading whitespace on paste is the correct approach, it seems to be the biggest cause of consternation.

  25. modified the milestones: fish-future, fish 3.1.0 on Mar 26, 2019
  26. changed the title [-]stop treating leading spaces as an indicator not to save a command in the history file[/-] [+]stop pasting leading spaces[/+] on Mar 26, 2019
  27. locked as resolved and limited conversation to collaborators on Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions