fish

Add `where:` field to fish_history?


enter image description here

Fish history search (ctrl+R) currently only displays time and commands.

I think it would be useful to add a "- where: {path when executing the command}" field here.

- cmd: cat -n ~/.local/share/fish/fish_history | tail -n 10
  when: 1707253522
+  where: /home/user/projects/example
  paths:
    - ~/.local/share/fish/fish_history

Conceptual code:

set custom_history_file ~/.config/fish/custom_history

function add_where_field
    set when (date +%s)
    
    set cwd (pwd)
    set cmd "echo 'Hello, World!'"

    set entry "$cmd │ $when │ $cwd"
    echo $entry >> $custom_history_file
    
    eval $cmd
end

Another idea is to keep separate history files in each directory, zsh has a plugin.

Do you think which is better approach?


Solution

  • I think it would be useful to add a "- where: {path when executing the command}" field here.

    You cannot just add new fields to fish's history file and expect fish to understand it.

    This requires a change to fish, and you have already found the issue tracking it (or rather another issue asking for it that was closed as a duplicate).