Reputation: 106
I would like to modify the history mechanism in fish shell so that all commands starting with 'apt' should (also) be stored in a separate file.
Is there a way of doing it without recompiling fish? It would be nicer if I could turn this feature on/off.
Thanks!
Upvotes: 1
Views: 229
Reputation: 15924
What you most likely want to do instead is to look in /var/log/apt/, where apt stores its logs. Those are much more authoratitive than anything you can hack together in a shell, because apt actually writes them.
Now, if you must do it in fish, you can hook into fish's events, like the fish_preexec
event that is run before a command is executed:
function saveapt --on-event fish_preexec
# The event hands the commandline over as the first argument
# This really just checks if the commandline starts with 'apt',
# so it won't e.g. detect `command apt` or calling it via functions
# or scripts.
if string match -r '^apt' -- $argv
echo (date) $argv >> ~/apt_history.txt
end
end
save in an eagerly sourced file like config.fish or conf.d/*.fish
Upvotes: 1