Mercurial > dotfiles
changeset 512:ea947b2b04a0
zsh: update mcfly support to 1d1d5892b0c8
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Sun, 21 Mar 2021 22:08:09 -0400 |
parents | a6d9af3fdc50 |
children | ad9ca178e094 0cb4d4ef79f4 |
files | .shell.d/99.mcfly.zsh |
diffstat | 1 files changed, 16 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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