Created
December 19, 2022 23:11
-
-
Save varenc/a4dde5088182f987377dea599f29e9b6 to your computer and use it in GitHub Desktop.
Use Warp's AI Command generator via curl from outside of Warp (Requires you have a Warp account)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Manually call Warp's AI Command generator | |
# It's no where near as smart as something like Copilot, but I find it pretty handy sometimes. Sadly the Warp terminal itself is often lacking but I like this feature. | |
# | |
# To use, get your long lasting Warp account refresh token. (managed by Firebase/Google) | |
# How to do this is left as an excercise to the reader. Hint: MITM traffic or look in the Keychain | |
export WARP_REFRESH_TOKEN="<set yours here>" | |
# Now copy/paste or source this file to define the `ai_command` function | |
# | |
# With it defined, just call `ai_command` like this: | |
# $ ai_command "on macOS set a proxy with networksetup" | |
# networksetup -setwebproxy 'Wi-Fi' 127.0.0.1 8080 | |
export WARP_FIREBASE_ID='AIzaSyBdy3O3S9hrdayLJxJ7mriBR4qgUaUygAs' # This just Warp's app id. Same for everyone. | |
function __warp_get_token() { | |
curl -s --show-error -H "content-type: application/x-www-form-urlencoded" -H "accept: */*" -H "host: securetoken.googleapis.com" --data-binary "grant_type=refresh_token&refresh_token=$WARP_REFRESH_TOKEN" --compressed "https://securetoken.googleapis.com/v1/token?key=$WARP_FIREBASE_ID" | jq -r '.access_token' | |
} | |
function ai_command() { | |
[ -z "$1" ] && echo "Usage: ai_command <command>" && return 1 | |
local auth_token="$(__warp_get_token)" ## Note: this get a new access token every time. Not ideal. | |
# local auth_token="$(runcached --ignore-env --ttl 600 __warp_get_token)" # If you install `runcached` this will ensure you only get a new token every 10 minutes: https://gist.github.com/akorn/51ee2fe7d36fa139723c851d87e56096 | |
curl -s --show-error -H "content-type: application/json" -H "content-type: application/json" -H "authorization: Bearer $WARP_AUTH_TOKEN" -H "accept: */*" -H "host: app.warp.dev" --data-binary '{"prompt":"'"$1"'"}' --compressed "https://app.warp.dev/generate_command_with_natural_language" | jq -r '.response' | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment