You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
... 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?
@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 "
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.
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 (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?
Reacted by Andreas Nordal, George Christou, Nicolas Grilly, madblobfish, Vladimir Matveev and Marigold VanEseltine
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.
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.
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 ?
Reacted by Aaron Gyes, Fabian Boehm, George Christou, zx8, madblobfish and Vladimir Matveev
>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.
@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".
@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.
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.
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.
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.
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
Activity
krader1961 commentedon Aug 13, 2017
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
echoexamples) then runbuiltin history search -15 --show-time="%a %m-%d %R "does it show every command you ran?obfuscated commentedon Aug 13, 2017
@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.
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.
krader1961 commentedon Aug 13, 2017
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
FISH_HISTORYmechanism which is a more robust and easier method of ensuring sensitive commands aren't inadvertently disclosed.obfuscated commentedon Aug 13, 2017
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.
mqudsi commentedon Aug 14, 2017
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?
krader1961 commentedon Aug 14, 2017
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_HISTORYvariable 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.krader1961 commentedon Aug 14, 2017
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_promptfunction which provides an indication whenFISH_HISTORYis 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 thefish_mode_promptfunction to let the user know whether they are in Vi insert or command mode.mqudsi commentedon Aug 14, 2017
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 ?
faho commentedon Aug 14, 2017
@obfuscated: Note that, in this example:
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.obfuscated commentedon Aug 14, 2017
@faho In my version the bla1 line looks exactly the same as bla0. So you're losing this virtual bet. :)
faho commentedon Aug 14, 2017
@obfuscated: What I mean is: After executing those commands, start typing
echo "b. It should show a greyed outla1"after that, in the commandline. Press up-arrow. It should directly jump toecho "bla0". Clear the commandline and start typingecho "b. When the suggestion is shown press right-arrow, it should accept thela1".obfuscated commentedon Aug 14, 2017
@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.
faho commentedon Aug 14, 2017
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?
obfuscated commentedon Aug 14, 2017
@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.
mqudsi commentedon Aug 14, 2017
@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.20 remaining items
mqudsi commentedon Oct 18, 2017
This was my motivation for implementing the new
readcommand syntax. You can simply use(read -i)anywhere you need to securely enter a password.cben commentedon Dec 17, 2017
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
historysyntaxes fictional, delete doesn't currently allow-n 1/--max 1flag.)@madblobfish's proposal of vanishing message while typing is I think even cooler, avoids need to explain how to undo.
BarbzYHOOL commentedon Jul 19, 2018
What would be nice is to have it as a config option, so we could disable that feature.
BarbzYHOOL commentedon Jul 28, 2018
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 :'(
floam commentedon Dec 11, 2018
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.
ThomasAH commentedon Dec 11, 2018
This would be fine for me (as written above, our internal documentation has two leading spaces), but still sounds quite magic/surprising.
mqudsi commentedon Dec 11, 2018
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.
Bracketed paste: Strip leading spaces if they'd trigger histignore
[-]stop treating leading spaces as an indicator not to save a command in the history file[/-][+]stop pasting leading spaces[/+]