Skip to content

Implement history insert #4506

@admirabilis

Description

@admirabilis

I have created two functions that would be interesting to have ported as plugins. One is a precision calculator directly from the prompt (ex. running 3*(1/2) returns 1.5 instead of expanding globbing and command substitution), and the other corrects automatically on the fish_command_not_found event.

Now, both of them write to the history file, and would benefit greatly from a history insert command. I'm currently using the following:

if set -q XDG_DATA_HOME
    set __fish_history $XDG_DATA_HOME/fish/fish_history
else
    set __fish_history ~/.local/share/fish/fish_history
end

echo -e '- cmd: '(commandline)'\n  when: '(date +%s) >>$__fish_history
history --merge

The problem with this approach is that commandline is written to the history file as is (without considering newlines, without escaping special characters, etc.) and, of course, history --merge brings the undesired side-effect of merging history from all other sessions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions