rcaloras / bashhub-client

:cloud: Bash history in the cloud. Indexed and searchable.
https://bashhub.com
Apache License 2.0
1.25k stars 80 forks source link

Feature Request: Select command but do not execute it. #85

Open Gibby opened 4 years ago

Gibby commented 4 years ago

It would be nice to be able to select a command and have it filled on the cli but not be executed right away.

rcaloras commented 4 years ago

Hey @Gibby, thanks for the feedback. This is actually the default behavior for bashhub with Zsh. In Bash this is unfortunately not possible as far as I'm aware.

I originally tried to build this and actually asked about it on Stackoverflow years back: https://stackoverflow.com/questions/22951608/python-or-bash-print-output-to-command-line-ready-to-be-executed

rcaloras commented 4 years ago

closing as I don't believe this is possible in bash. This is the default behavior in Zsh.

Gibby commented 4 years ago

I got this working on both Ubuntu and Mac in bash by adding the following function.

_bh_inject() {
  perl -e 'ioctl(STDIN, 0x5412, $_) for split "", join " ", @ARGV' "$@"
}

Then I changed these lines.

    #echo "$command"
    #eval "$command"
    __bh_precmd
    _bh_inject "$command"
Gibby commented 4 years ago

I think I got the inspiration from https://github.com/dvorka/hstr

rcaloras commented 4 years ago

@Gibby thanks for sharing! any idea if this possible using python? wondering to avoid adding a dependency on perl.

Feel free to submit a PR as well if you're interested :) Would be happy to make this the default experience.

Gibby commented 4 years ago

I think so - https://docs.python.org/3.8/library/fcntl.html

I'll see if I can figure it out

rcaloras commented 4 years ago

Looking into this a bit more, found a few other threads with similar or other ways of approaching this.

Hacking at it a bit and haven't been able to get anything to work quite yet. Tried the python solution mentioned here and also tried using autopy.

@Gibby, please share if you find something viable on Python or just bash.

weeebdev commented 2 years ago

Any news? In my case, on mac the selected entry is just printed and not filled or executed

rcaloras commented 2 years ago

@weeebdev what do you mean by 'just printed and not filled or executed'? Also what shell are you running?

weeebdev commented 1 year ago

@weeebdev what do you mean by 'just printed and not filled or executed'? Also what shell are you running?

fish shell. I meant, that when I pick a command from the history, it's just being printed in the console but not actually executed