-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stop pasting leading spaces #4327
Comments
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.
This is also by design and expected behavior.
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 |
@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)
I have no idea if the history file and the list of commands accessed with up arrow are the same. 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.
|
From the documentation:
Suggestions on how to make this more discoverable are welcome. The fish behavior is based on this section of the bash man page:
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 |
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. |
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 ( 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? |
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 |
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 |
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 ? |
@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 |
@faho In my version the bla1 line looks exactly the same as bla0. So you're losing this virtual bet. :) |
@obfuscated: What I mean is: After executing those commands, start typing |
@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. |
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? |
@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. |
@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 |
Not for me and I suspect not for anyone else. So the question is what is going on in your case. Unless, of course, you're running commands that have at least one leading space. In which case we know what the reason is. |
This isn't about the case where you've cancelled something. That's different, but not what I'm talking about right now. When the command runs to completion, the behavior on an empty line is that up-arrow gives you the command. But once you type a prefix of it, it'll be selected for the suggestion and then up-arrow will give you something different. The idea is that you can use right-arrow to accept the suggestion, so you don't need another way to do the same. Now, a command that just "fails" (i.e. returns a status != 0) still seems to be included in the history. If you're saying something different, I'd love to have a way to reproduce it. If a command has a syntax error, it won't even allow you to execute it, and the commandline will stay as it is. So it's never entered into history, but there's no need to navigate to it because it's still there. What I suspect is one of your pain points is that our ctrl-c binding doesn't enter the command into history - it just abandons the commandline. That is something we could change. |
Most but not all of them. It happens very infrequently but I have inadvertently ended up with a leading space. Also, it's not just pasting with the mouse. It's also pasting with [ctrl-V] (or [cmd-V]) that can result in a leading space. I guess the main problem with this behavior is that it is mystifying till you learn why it's happening. And that's hard to do because it's hard to discover. |
I'd actually be happier if we had something explicit like a Update: Obviously it's possible to have something short like |
Except that it is configurable and off by default unless the distro has enabled it. For example, bash on macOS does not enable this as default behavior. |
I often miss a command to forget the last history entry, because it was a mistake, and I don't want it suggested again. My command line often looks like this:
I'm also a heavy user of the space prefix. I don't know if I'm paranoid, but I always put a space before |
@anordal, Try |
In GNU bash, version 4.4.12(1) on Debian stretch a leading space or an error still keeps the corresponding input line in the history but the default /etc/skel/.bashrc now contains
CentOS 7 only sets The upstream package of bash 4.4 does not set HISTCONTROL at all, not even in an example file. So fish's current behaviour is surprising to many people, including me. |
I think any behavior fish chooses here will be surprising to many people. |
Yes, but the problem with the leading space solution is that it is hard to recognize and discover. Using something more explicit will annoy bash refugees who expect to be able to just preface their command with a space to keep it from ending up in the history. But it will be considerably more friendly to people who are not aware of that behavior. Especially since it is not the bash default behavior unless you're on a distro which enables it by default. And with our command abbreviation and key binding facilities people can define a single letter prefix even if we implement a more verbose "nohist" like command. That seems like the better trade-off to me. |
Those are valid points, however the leading space trick is more commonly known and easier to remember than some new invented syntax. Also TBH I am skeptical that "I accidentally added a leading space and then I tried to up-arrow that command" is common - seems like an unlikely set of factors. How about having leading space act as a "don't write this to disk" modifier? Said commands would still be in your current session, but only in memory - once the session is closed they will be forgotten. This seems like it would address the "can't up-arrow" issue, while also providing a simple and familiar mechanism to retain secrets. |
@ridiculousfish This (if it is enabled by default) will make it even harder to discover why entries to the history aren't saved. Just add an option to disable it and consider making it disabled by default. I don't think this is so serious problem which requires the invention of new syntax and other complex solutions... |
For me the spaces don't appear by accident, but from copy&paste from our internal documentation, which has all commands indented by two spaces. So when I want to do the same thing e.g. on the next day, I have to consult the documentation again. Having the option to disable it would be good enough for me. |
Options for this sort of thing is against the fish design philosophy - see Configurability is the root of all evil. The question is whether we keep, modify, or remove the behavior. One question I have is how do people keep stumbling onto this? I understand the pasting commands from docs issue and agree it's annoying, but that can't be a common source of leading spaces - I think? |
Then I'd vote to remove the feature.
I must admit that I don't know any other situation that happens to me. |
@ridiculousfish As I've previous said this happened to me after I've removed the beginning of a command. In this particular case I think I've removed the env part in the command "env BLA=bla2 somecommand", but I forgot to remove the space, because of sloppiness or habit. Your options at the moment are:
|
for me: copying and pasting indented fish code from within fish scripts and functions edit: and just to clarify: like others, I also run into this when I forget or deliberately take the shortcut of (and later regret) not removing a leading space I've accidentally left while editing a command |
Please keep this behavior or find a better alternative, nohist is worse in my opinion.
As it stands now I'm for a visual clue and maybe printing a message about what is happening when first used. This would be a short message just like when auto completing directories (vanishes when the command is executed). I think that nohist only adds complexity and is even more inconvenient. Adding the whitespace is already inconvenient, especially when the commandline to be executed had already been written and contains newlines. Another point I can make is that I sometimes copy with whitespace by purpose and expect the whitespace to show up, so trimming is probably also not too good. |
Just got an Idea, don't know if its good or bad: |
This was my motivation for implementing the new |
Proposal: whether you change it or not, display a hint after executing a command with leading space, ideally explaining how to achieve the opposite:
or:
(both @madblobfish's proposal of vanishing message while typing is I think even cooler, avoids need to explain how to undo. |
What would be nice is to have it as a config option, so we could disable that feature. |
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 :'( |
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. |
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. |
Similar to the last commit, only for the in-terminal-paste stuff. Also cleans up the comments on bracketed paste a bit - nobody has stepped forward to report problems with old emacsen or windows, so there's no need for a TODO comment. See #4327.
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:
The text was updated successfully, but these errors were encountered: