A thought that occurred to me while making my “sometimes trigger on up arrow” hook (atuin-up-search-if-prefix
zle widget)¹
was "how do I want to handle the situation where ↑ is the first keystroke in a brand new shell?"²
which in turn made me think about the probably slightly more common variations of that and their “potentially likeliest” answers.
It seems to my mind like—regardless of what someone’s preference for a default/“steady state” filter_mode
is:
(out of global
, host
, and session
, at least):
-
if they trigger atuin immediately (or indeed shortly) after changing working directories (first/next thing after running
cd
,j
,z
, etc.):there’s a good chance it would be helpful for the next invocation(s)³ to take on
directory
scope. -
likewise, if atuin is invoked immediately⁴ after entering a (login) shell [via
ssh
(/mosh
/et
, not sure about direct on a tty or pty]:there’s a good chance it would be helpful for the next invocation(s)³ to take on
host
scope
That is, generalized, I am suggesting the principle
if a user runs a command that changes the evaluation of a
filter_mode
shortly before invokingatuin search
,then that
filter_mode
is most likely to provide the next command they want to run
while there are definitely exceptions to that principle, it seems to me like it might hold enough to be a reasonable option or even a reasonable default
One can also go one further and say broadly:
whenever execution context changes, the next command [with side effects*] to run is very likely to be a function of that change in context
[*this is to exclude merely “context checking” commands like
ls
,git status
, other things that might be understood to replace or elaborate on a rich prompt]
as such one could imagine further versions of this contextual triggering on the basis of e.g.:
-
recently run
git
/[other vcs] commands (in particular likecheckout
,switch
, or other movement ofHEAD
;and in a ~different way
rebase -i
ormerge
), -
invocations like
eval "$(x)"
,source y.sh
, [various things that use the wordactivate
, like virtualenv] -
(specific) recently changed/initialized environment variables (
$PATH
being the main one which leaps to mind; but if you were watching any, watching$PWD
,$HOST
, maybe some of the prompt-related vars -
as well as the deeper rabbit holes of simply ~clustering of prefixes of recently run commands, or e.g. what commands are frequently run after certain files are edited (whether that knowledge was derived ~only by previous command being of the form
$editor $file
or more involved fs watching)
¹ in the bottom section of Atuin "off the bottom" of local history (i.e. bound on ⬇️)
² I decided for now just trigger atuin same as for ↑-after-return-to-end-of-line and ↓-at-end-of-history; but really the right answer might be something else entirely like firing a “project picker” menu of some sort (in the simplest case maybe zoxide’s zi
)
³ perhaps up to the point that they start typing commands without using history, and/or perchance on some actual cooldown timer from cd
or equivalent, and/or a “warmup counter” on length of session history.
⁴ as above there are various ways to interpret/scope “immediately after” - it seems worth pointing out that if making this decision, moreso than for working dir, time-based is well-provided for by external native data sources such as:
- the
$SECONDS
variable provided by at least bash and zsh , - the recorded session start times you’d get from
who
,w
,finger
, or directly from whateverutmp
files