bashhub-client icon indicating copy to clipboard operation
bashhub-client copied to clipboard

Feature Request: Select command but do not execute it.

Open Gibby opened this issue 4 years ago • 10 comments

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

Gibby avatar Jul 28 '20 17:07 Gibby

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 avatar Jul 30 '20 01:07 rcaloras

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

rcaloras avatar Aug 02 '20 00:08 rcaloras

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 avatar Aug 03 '20 20:08 Gibby

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

Gibby avatar Aug 03 '20 20:08 Gibby

@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.

rcaloras avatar Aug 03 '20 20:08 rcaloras

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

I'll see if I can figure it out

Gibby avatar Aug 03 '20 20:08 Gibby

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

  • https://unix.stackexchange.com/questions/213799/can-bash-write-to-its-own-input-stream/217390
  • https://unix.stackexchange.com/questions/391679/how-to-automatically-insert-a-string-after-the-prompt

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.

rcaloras avatar Aug 28 '20 19:08 rcaloras

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

weeebdev avatar Aug 26 '22 04:08 weeebdev

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

rcaloras avatar Aug 26 '22 12:08 rcaloras

@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

weeebdev avatar Nov 02 '22 11:11 weeebdev