So after months of fighting with gf not going to template files, I finally decided to put in some effort to make it work.
This was the dumbest keybind in my config, that I copied from someone else without understanding it.
What I am trying to do #
I have jinja templates in a directory called templates. I want to bind gf to
open a template file, but it is trying to open a new file ./base.html
{% extends "base.html" %}
{% if request.state.user %}
{% block title %}Fokais - {{ request.state.user.full_name }} {% endblock %}
{% else %}
{% block title %}Fokais {% endblock %}
{% endif %}
{% block content %}
{% if request.state.user %}
<h1 id="title"
class="inline-block mx-auto text-5xl font-black leading-loose
text-transparent bg-clip-text bg-gradient-to-r from-red-600
via-pink-500 to-yellow-400 ring-red-500 text-shadow-xl
text-shadow-zinc-950 ring-5">
{{ request.state.user.full_name }}
</h1>
{% endif %}
{% include "me_partial.html" %}
{% endblock %}
What did not work #
I tried all sorts of changes to my path, but it still didn’t work.
vim.api.nvim_command("set path+=templates/**")
What I found #
after digging into my keymap I found that I had remaped gf to edit years
ago. This works great if the file is in your current directory, and if it’s not
it makes the file. This bind completely breaks vim’s ability to :find files
and was a terrible keybind that I added probably from someone else years ago
and have literally never used this feature. If gf opens an empty file I
always close it and assume that vim failed to :find the file.
-- Allow gf to open non-existent files
set("", "gf", ":edit <cfile><CR>")
Yes, after that fix I still needed to adjust my path #
I ended up with the following in my options.lua.
-- look for jinja templates in the templates directory
vim.opt.path:append("templates/**")
thoughts on unit tests
Authentication from cli tools can be a bit of a bear, and I have to look it up every time. This is my reference guide for future me to remember how to easily do it.
I set up a fastapi server running on port 8000, it uses a basic auth with
waylonwalker as the username and asdf as the password. The server follows
along with what comes out of the docs. I have it setup to take basic auth,
form username and password, or a bearer token for authentication.
curl #
The og of command line url tools.
# basic auth
curl -u 'waylonwalker:asdf' -X POST localhost:8000/token
# basic auth with password prompt
curl -u 'waylonwalker' -X POST localhost:8000/token
# token
curl -H 'Authorization: bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ3YXlsb253YWxrZXIiLCJleHAiOjE3MDI5NTI2MDJ9.GeYNt7DNal6LTiPoavJnqypaMt4vYeriXdq5lqu1ILg' -X POST localhost:8000/token
wget #
My go to if I want the result to go into a file.
# basic auth
wget -q -O - --auth-no-challenge --http-user=waylonwalker --http-password=asdf --post-data '' localhost:8000/token
# token
wget -q -O - --header="Authorization: bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ3YXlsb253YWxrZXIiLCJleHAiOjE3MDI5NTI2MDJ9.GeYNt7DNal6LTiPoavJnqypaMt4vYeriXdq5lqu1ILg" -O - --post-data '' localhost:8000/token
httpx #
An http client written in python, primarilty used with the python api, but has a nice cli.
# install
python3 -m pip install httpx
# basic auth
httpx -m POST --auth waylonwalker asdf http://localhost:8000/token
# basic auth with password prompt
httpx -m POST --auth waylonwalker - http://localhost:8000/token
# token
httpx -m POST --headers="Authorization" "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ3YXlsb253YWxrZXIiLCJleHAiOjE3MDI5NTI2MDJ9.GeYNt7DNal6LTiPoavJnqypaMt4vYeriXdq5lqu1ILg" http://localhost:8000/token
httpie #
A modern http client written in python.
# install
python3 -m pip install httpie
# basic auth
http POST localhost:8000/token -a waylonwalker:asdf
# basic auth with password prompt
http POST localhost:8000/token -a waylonwalker
# token
http POST localhost:8000/token -A bearer -a eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ3YXlsb253YWxrZXIiLCJleHAiOjE3MDI5NTI2MDJ9.GeYNt7DNal6LTiPoavJnqypaMt4vYeriXdq5lqu1ILg
httpie with plugin #
# install
python3 -m pip install httpie-credential-store
# usage
http POST localhost:8000/token -A creds
httpie prompt #
http-prompt comes from the httpie org, and has an interactive cli interface
into apis. You can even specify a spec file to autocomplete on api methods.
http-prompt localhost:8000 --auth waylonwalker:asdf --spec openapi.json