Just and Fzf for Common Tasks
just
just is a command runner, great to simplify build commands on a project or shortcuts to regular commands.
It works with a file .justfile
with a set of commands, like:
server:
LOGLEVEL=INFO AWS_PROFILE=dev CONFIG=configs/dev.json poetry run uvicorn app.main:app --reload --use-colors --port 6011 --host 0.0.0.0
Done, with just server
it will run the command.
Fzf
fzf is a well-known command-line fuzzy finder, on a default install offers a handy way to find commands on history and navigate through file-system.
It works on all popular shells.
Combining both
With fzf you can fuzzy find history for a previous command, but on a heavy terminal use sometimes isn’t easy to find a specific command, i usually running docker images to several tasks, for instance, run a nginx instance on a specific path with ssl, for this i have on $HOME/.justfile
:
docker:
docker run --rm -p 443:443 -v $HOME/Project/dist:/usr/share/nginx/html -v $HOME/Project/letsencrypt/archive/domain/:/cert/ -v $HOME/Project/letscert/nginx:/etc/nginx nginx:latest
To have a shortcut on fish
shell, i create a file $HOME/.config/fish/conf.d/picker.fish
function run_pick_just_command
set result_line (just -f ~/.justfile | nl | fzf | awk '{ print $2 }')
commandline --replace -- "just $result_line"
commandline --function repaint
end
function fish_user_key_bindings
for mode in default insert
bind --mode $mode \co run_pick_just_command
end
end
Now, whenever i use CTRL+O, it will show me a list of commands on justfile where i can fuzzy find, on select it will fill a just command to use it.