# HG changeset patch # User Augie Fackler <raf@durin42.com> # Date 1616378889 14400 # Node ID ea947b2b04a08147ce54936b5519459f08e2dfba # Parent a6d9af3fdc5056ecce9482baeb026ef7b2caf678 zsh: update mcfly support to 1d1d5892b0c8 diff --git a/.shell.d/99.mcfly.zsh b/.shell.d/99.mcfly.zsh --- a/.shell.d/99.mcfly.zsh +++ b/.shell.d/99.mcfly.zsh @@ -28,6 +28,10 @@ export MCFLY_SESSION_ID=$(dd if=/dev/ura # Find the binary MCFLY_PATH=${MCFLY_PATH:-$(which mcfly)} +if [[ -z "$MCFLY_PATH" || "$MCFLY_PATH" == "mcfly not found" ]]; then + echo "Cannot find the mcfly binary, please make sure that mcfly is in your path before sourcing mcfly.bash." + return 1 +fi # Required for commented out mcfly search commands to work. setopt interactive_comments # allow comments in interactive shells (like Bash does) @@ -52,7 +56,7 @@ function mcfly_prompt_command { # Run mcfly with the saved code. It fill find the text of the last command in $MCFLY_HISTORY and save it to the database. [ -n "$MCFLY_DEBUG" ] && echo "mcfly.zsh: Run mcfly add --exit ${exit_code}" - $MCFLY_PATH add --exit ${exit_code} + $MCFLY_PATH --history_format zsh add --exit ${exit_code} return ${exit_code} # Restore the original exit code by returning it. } precmd_functions+=(mcfly_prompt_command) @@ -71,14 +75,19 @@ if [[ $- =~ .*i.* ]]; then echoti rmkx exec </dev/tty local mcfly_output=$(mktemp -t mcfly.output.XXXXXXXX) - $MCFLY_PATH search -o "${mcfly_output}" "${LBUFFER}" - local mode=$(sed -n 1p $mcfly_output) - local selected=$(sed 1d $mcfly_output) - rm -f $mcfly_output + $MCFLY_PATH --history_format zsh search -o "${mcfly_output}" "${LBUFFER}" echoti smkx - if [[ -n $selected ]]; then + + # Interpret commandline/run requests from McFly + while read -r key val; do + if [[ "$key" = "mode" ]]; then local mode="$val"; fi + if [[ "$key" = "commandline" ]]; then local commandline="$val"; fi + done < "${mcfly_output}" + rm -f $mcfly_output + + if [[ -n $commandline ]]; then RBUFFER="" - LBUFFER="${selected}" + LBUFFER="${commandline}" fi if [[ "${mode}" == "run" ]]; then zle accept-line