intelli_search_key="${INTELLI_SEARCH_HOTKEY:-^@}"
intelli_bookmark_key="${INTELLI_BOOKMARK_HOTKEY:-^b}"
intelli_variable_key="${INTELLI_VARIABLE_HOTKEY:-^l}"
intelli_fix_key="${INTELLI_FIX_HOTKEY:-^x}"
function _intelli_exec {
local temp_result_file=$(mktemp)
BUFFER=""
zle -I
intelli-shell --skip-execution --file-output "$temp_result_file" "$@"
local exit_status=$?
if [[ ! -s "$temp_result_file" ]]; then
rm -f "$temp_result_file" 2>/dev/null
return $exit_status
fi
local -a lines
lines=("${(f)$(<"$temp_result_file")}")
rm -f "$temp_result_file" 2>/dev/null
local out_status="${lines[1]}"
local action=""
local command=""
if ((${#lines[@]} > 1)); then
action="${lines[2]}"
fi
if ((${#lines[@]} > 2)); then
command="${(F)lines[3,-1]}"
fi
if [[ "$out_status" == "DIRTY" || $exit_status -ne 0 ]]; then
else
zle .redisplay
fi
if [[ "$action" == "REPLACE" ]]; then
BUFFER="$command"
zle .end-of-line
elif [[ "$action" == "EXECUTE" ]]; then
BUFFER="$command"
zle .accept-line
fi
}
function _intelli_search {
_intelli_exec search -i "$BUFFER"
}
function _intelli_save {
_intelli_exec new -i "$BUFFER"
}
function _intelli_variable {
_intelli_exec replace -i "$BUFFER"
}
function _intelli_fix {
local hist
hist=$(fc -l -n -5)
_intelli_exec fix --history "$hist" "$BUFFER"
}
if [[ "${INTELLI_SKIP_ESC_BIND:-0}" == "0" ]]; then
bindkey '\e' kill-whole-line
fi
zle -N _intelli_search
zle -N _intelli_save
zle -N _intelli_variable
zle -N _intelli_fix
bindkey "$intelli_search_key" _intelli_search
bindkey "$intelli_bookmark_key" _intelli_save
bindkey "$intelli_variable_key" _intelli_variable
bindkey "$intelli_fix_key" _intelli_fix
export INTELLI_EXEC_PROMPT=$(print -r -- "$PS2" | sed 's/%{//g; s/%}//g')