Chain Commands #266
-
|
Dear all, is there a way to pick one command with pet, do a pipe and then select another one with pet? Thank you in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
|
If you're using |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @jaroslawhartman , didn't even know this was possible! Do you mind if we add your GIF to the README? @Raf1312 Your question is answered :) |
Beta Was this translation helpful? Give feedback.
-
|
For me, the bash solution from README.md doesn't work as expected. I changed the function to: function pet-select() {
BUFFER=$(pet search)
READLINE_LINE+="$BUFFER "
READLINE_POINT=${#READLINE_LINE}
}This works fine here. Feedback appreciated! @RamiAwar |
Beta Was this translation helpful? Give feedback.
-
|
Assuming each command has all snipppets with a tag - e.g.: ... the search is pre-filtered for the specific command: function pet-select() {
local pre post command result
pre=${READLINE_LINE:0:$READLINE_POINT} # left from cursor
post=${READLINE_LINE:$READLINE_POINT} # right from cursor
command=$(echo "${pre//*|/}" | awk '{print $1}') # real current cmd
test "${pre: -1}" = " " || pre+=" " # append blank if cursor is directly after cmd
if [ ${#command} -gt 0 ]; then
# pet for the specific cmd and remove unneeded "command | sudo mycmd"
result="$(pet search -t "$command" | sed "s/^\([^|]*|\s*\)\{0,1\}\(sudo\s\s*\)\{0,1\}\s*\b$command\b\s*//")"
else
result="$(pet search)" # global search if no cmd before cursor
fi
READLINE_LINE="$pre$result"
READLINE_POINT=${#READLINE_LINE}
READLINE_LINE+="$post"
} |
Beta Was this translation helpful? Give feedback.

If you're using
zshyou would need to set this widget definition in.zshrc: