[Solved] How to execute a command from 'hstr'?

I just found hstr to filter the bash history. It’s kind of like using CTRL+R to search through the bash history for past command lines. But instead of doing it blindly, you get a list that gets filtered live as you type (kinda what Clipdinger does with its latest version for the clipboard history).

Anyway, it seems very nice, but I haven’t yet managed to actually execute the selected line. Pressing RETURN will just insert it in the shell, but doesn’t execute it. What do I miss?

I don’t think that it is possible. Apparently, there’s no filtering of commands that could possibly damage the system so it wouldn’t be safe. I’d say that’s intended and if this behaviour allows users to edit the line, it mainly gives them another chance to think about what they are doing.

Maybe I’ve been not totally clear. I’d be happy if the selected line were inserted at cursor position, then could be edited and executed with RETURN. But as it is, the selected line gets just “echo’ed” out and my prompt returns below it.
Difficult to describe, here I opened hstr (aliased to “hh”) with the string “ssh”, from the filtered history list (not shown below, ofc) I picked “ssh root@libre-a”, which is the inserted, but not executed, and I’m sitting there with the empty blinking prompt:

~/Desktop> hh ssh
ssh root@libre-a

Anyone using hstr outside of Haiku and can confirm this is expected behaviour and not a bug in our port or some failure on my side?

Back-quoting the original command using the gravé quotes should work.

Nope, and it would be a huge bother if that were the way, and how would it if you just called “hstr” without an initial filtering string?
“hstr” is in HaikuDepot, everyone can give it a spin before guessing into the blue. :slight_smile:

Tried it on nightly x64, and got same behaviour. It’s indeed not very helpful. I guess that the recipe was tested before being pushed so perhaps, it’s something that changed in nightlies or a problem with the arch.

I see what you mean. It does execute the result on Manjaro Linux x64 but not on Haiku. (Tested on Beta3 x64.)

I updated the recipe before trying to find why it behaves like this on Haiku. I’ve used hstr for years on Linux, and I would love to have it working correctly on Haiku.

But as it is usual… I’m way out of my league trying to debug stuff, so… don’t wait for me! If anyone else wants to have a look at it, that would be awesome!

Edit: I mean, the original recipe behaved the same as what @humdinger sees with the updated one. I just figured it was better to have the latest code available before digging into the issue.

This may not just be related to Haiku.

See Running a previous command with hstr echoes instead of running the command · Issue #452 · dvorka/hstr · GitHub

1 Like

Thanks. Too bad the issue submitter didn’t include more info about his setup (OS / terminal / bash version),

I guess I’ll add a comment regarding the similar behavior on Haiku, and ask for more details from his side.

Would be funny/sad if he’s actually a Haiku user :smiley:

It seems the patchset is not complete. Lacking TIOCSTI, the same workaround as cygwin uses is included, but the change to the shell binding function was forgotten.
Confirmed that declaring that function in bash and binding it to a key, works.


Awesome find @madmax! Thanks a lot!

While we wait for an updated hstr package to be available, and for those wanting to try it right away…

You need to add the following to your “~/config/settings/profile”:

function hstr_haiku {
	{ READLINE_LINE=$(</dev/tty hstr ${READLINE_LINE:0:offset} 2>&1 1>&$hstrout); } {hstrout}>&1

if [[ $- =~ .*i.* ]]; then bind -x '"\C-r": "hstr_haiku"'; fi

And don’t forget to comment out the line:

if [[ $- =~ .*i.* ]]; then bind '"\C-r": "\C-a hstr -- \C-j"'; fi

That should be there if you had followed the hstr --show-configuration instructions before.

(I’ll be submitting a revised patchset as soon as possible, unless someone beats me to it).

Thanks guys for hopping into action! :slight_smile:

@BiPolar thanks, the above works for invoking CTRL+R.
Will the updated package also work when keeping the usual CTRL+R and using hstr directly?

The update I’ll propose, will only change what’s shown in the config instructions. So it should work same as it does right now.

So happy to have hstr working! Thanks again @madmax!

Edit: Just in case I misread your question (my “English” is poorly self-taught, sorry). The update will still need the above function defined in profile.


I did the original port, but i don’t recall it ever executed the commands. I haven’t spent too much time and had nochance to test it on other system (running only Haiku here), so i assumed it just doesn’t do that.

To expand on @BiPolar’s answer: the current workaround in hstr is to just spit the command to stderr. It’s the bash function that reads that and inserts it into the current readline buffer, and it seems it needs to be bound to a key to access readline. You can use a different key combo, of course.


That’s good enough for me. Frankly, I never want to go back to the bash default CTRL+R.
I wish hstr was available for LibreElec on my Raspberry… :smiley:

1 Like

Same here, hehe.

Today I’ve tried it again on Linux… And now I even prefer the way it works with the workaround method, LOL!