Work on openapi completion
Currently still a work in progress. the bin/.bin/openapi file will be a bash script for interfacing with an openapi file. Currently it does things like listing requests, servers, and viewing a request in json format. The function added to fzf.zsh adds a zsh widget so that I can press a keybinding (in my case ^o) to complete the command. It uses the above script and fzf to make the selection. Currently supports http / https / curl The widget looks for an environment variable called OPENAPI which should point to the openapi file. This is set in zshrc if a project is set.
This commit is contained in:
parent
a4b749ded5
commit
6fa3f737e2
3 changed files with 117 additions and 0 deletions
|
@ -72,6 +72,7 @@ else
|
|||
if [[ ! "$(ps -ocommand -p $PPID | grep -v 'COMMAND' | cut -d' ' -f1 )" == "$script" ]]; then
|
||||
if [ -f "$current/index.yaml" ]; then
|
||||
export repdef="$(realpath "$current/$(yq -r .repdef "$current/index.yaml")")"
|
||||
export OPENAPI="$(realpath "$current/$(yq -r .openapi "$current/index.yaml")")"
|
||||
fi
|
||||
mkdir "$current/shell-logs" 2> /dev/null
|
||||
/usr/bin/script -f "$current/shell-logs/$(date +"%d-%b-%y_%H-%M-%S")_shell.log"
|
||||
|
|
|
@ -152,4 +152,23 @@ if [ "$sourced" = "True" ]; then
|
|||
bind-git-helper f b t r h s
|
||||
unset -f bind-git-helper
|
||||
|
||||
fzf-openapi-widget(){
|
||||
if [ -n "$OPENAPI" ] && [ -f "$OPENAPI" ]; then
|
||||
server="$(openapi -j "$OPENAPI" servers | fzf -1 --prompt Server)"
|
||||
request="$(openapi -j "$OPENAPI" requests | column -t -s $'\t' | fzf -d ' +' --height 90% --preview "openapi -j \"$OPENAPI\" request {2} {1} | jq -C '.'")"
|
||||
method="$(echo -n "$request" | awk -F ' +' '{print $1}' | tr 'a-z' 'A-Z')"
|
||||
url="$(echo -n "$request" | awk -F ' +' '{print $2}')"
|
||||
|
||||
case "$LBUFFER" in
|
||||
http*|https*) LBUFFER+=" $method $server$url" ;;
|
||||
curl*) LBUFFER+=" -X $method $server$url" ;;
|
||||
esac
|
||||
LBUFFER="$(echo -n "$LBUFFER" | sed -E 's/ +/ /g')"
|
||||
zle reset-prompt
|
||||
fi
|
||||
}
|
||||
zle -N fzf-openapi-widget
|
||||
bindkey '^o' fzf-openapi-widget
|
||||
|
||||
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue