comparison .shell.d/99.mcfly.zsh @ 512:ea947b2b04a0

zsh: update mcfly support to 1d1d5892b0c8
author Augie Fackler <raf@durin42.com>
date Sun, 21 Mar 2021 22:08:09 -0400
parents 55aa151f3567
children
comparison
equal deleted inserted replaced
511:a6d9af3fdc50 512:ea947b2b04a0
26 # MCFLY_SESSION_ID is used by McFly internally to keep track of the commands from a particular terminal session. 26 # MCFLY_SESSION_ID is used by McFly internally to keep track of the commands from a particular terminal session.
27 export MCFLY_SESSION_ID=$(dd if=/dev/urandom bs=256 count=1 2> /dev/null | env LC_ALL=C tr -dc 'a-zA-Z0-9' | head -c 24) 27 export MCFLY_SESSION_ID=$(dd if=/dev/urandom bs=256 count=1 2> /dev/null | env LC_ALL=C tr -dc 'a-zA-Z0-9' | head -c 24)
28 28
29 # Find the binary 29 # Find the binary
30 MCFLY_PATH=${MCFLY_PATH:-$(which mcfly)} 30 MCFLY_PATH=${MCFLY_PATH:-$(which mcfly)}
31 if [[ -z "$MCFLY_PATH" || "$MCFLY_PATH" == "mcfly not found" ]]; then
32 echo "Cannot find the mcfly binary, please make sure that mcfly is in your path before sourcing mcfly.bash."
33 return 1
34 fi
31 35
32 # Required for commented out mcfly search commands to work. 36 # Required for commented out mcfly search commands to work.
33 setopt interactive_comments # allow comments in interactive shells (like Bash does) 37 setopt interactive_comments # allow comments in interactive shells (like Bash does)
34 38
35 # McFly's temporary, per-session history file. 39 # McFly's temporary, per-session history file.
50 # Write history to $MCFLY_HISTORY. 54 # Write history to $MCFLY_HISTORY.
51 fc -W "${MCFLY_HISTORY}" 55 fc -W "${MCFLY_HISTORY}"
52 56
53 # Run mcfly with the saved code. It fill find the text of the last command in $MCFLY_HISTORY and save it to the database. 57 # Run mcfly with the saved code. It fill find the text of the last command in $MCFLY_HISTORY and save it to the database.
54 [ -n "$MCFLY_DEBUG" ] && echo "mcfly.zsh: Run mcfly add --exit ${exit_code}" 58 [ -n "$MCFLY_DEBUG" ] && echo "mcfly.zsh: Run mcfly add --exit ${exit_code}"
55 $MCFLY_PATH add --exit ${exit_code} 59 $MCFLY_PATH --history_format zsh add --exit ${exit_code}
56 return ${exit_code} # Restore the original exit code by returning it. 60 return ${exit_code} # Restore the original exit code by returning it.
57 } 61 }
58 precmd_functions+=(mcfly_prompt_command) 62 precmd_functions+=(mcfly_prompt_command)
59 63
60 # Cleanup $MCFLY_HISTORY tmp files on exit. 64 # Cleanup $MCFLY_HISTORY tmp files on exit.
69 mcfly-history-widget() { 73 mcfly-history-widget() {
70 () { 74 () {
71 echoti rmkx 75 echoti rmkx
72 exec </dev/tty 76 exec </dev/tty
73 local mcfly_output=$(mktemp -t mcfly.output.XXXXXXXX) 77 local mcfly_output=$(mktemp -t mcfly.output.XXXXXXXX)
74 $MCFLY_PATH search -o "${mcfly_output}" "${LBUFFER}" 78 $MCFLY_PATH --history_format zsh search -o "${mcfly_output}" "${LBUFFER}"
75 local mode=$(sed -n 1p $mcfly_output) 79 echoti smkx
76 local selected=$(sed 1d $mcfly_output) 80
81 # Interpret commandline/run requests from McFly
82 while read -r key val; do
83 if [[ "$key" = "mode" ]]; then local mode="$val"; fi
84 if [[ "$key" = "commandline" ]]; then local commandline="$val"; fi
85 done < "${mcfly_output}"
77 rm -f $mcfly_output 86 rm -f $mcfly_output
78 echoti smkx 87
79 if [[ -n $selected ]]; then 88 if [[ -n $commandline ]]; then
80 RBUFFER="" 89 RBUFFER=""
81 LBUFFER="${selected}" 90 LBUFFER="${commandline}"
82 fi 91 fi
83 if [[ "${mode}" == "run" ]]; then 92 if [[ "${mode}" == "run" ]]; then
84 zle accept-line 93 zle accept-line
85 fi 94 fi
86 zle redisplay 95 zle redisplay