Add .build-var zle widget

Press Ctrl-B to fuzzy find all configuration CMake variables for the
current build directory. Once a variable is selected, rewrite the
command-line to set the selected CMake variable.
This commit is contained in:
Kenneth Benzie 2024-05-03 22:39:11 +01:00
parent 766ac3c5bf
commit dcacb1de42

View File

@ -207,3 +207,23 @@ build-debug() {
local target=$1; shift 1
eval build $target && debug ~build/bin/$target "$@"
}
# Fuzzy find CMake variables, select one to set the variable via a command.
.build-var() {
if [[ ! -n $build_dir ]]; then
build-dir
fi
local var=$(
cat $build_dir/CMakeCache.txt |
grep --color=never -Ex '^\w+:\w+=.*$' |
fzf --layout=reverse --info=hidden --border=rounded \
--cycle --height=50%
)
if [[ -n "$var" ]]; then
BUFFER="cmake -B\$build_dir -D$var"
zle end-of-line
fi
zle reset-prompt
}
zle -N .build-var
bindkey '^B' .build-var