Skip to content

frioux/leatherman

Repository files navigation

Leatherman - fREW's favorite multitool

This is a little project simply to make trivial tools in Go effortless for my personal usage. These tools are almost surely of low utility to most people, but may be instructive nonetheless.

I have CI/CD to build this into a single binary and an explode tool that builds symlinks for each tool in the busybox style.

I have automation in my dotfiles to pull the latest binary at install time and run the explode tool.

Installation

Here's a copy pasteable script to install the leatherman on OSX or Linux:

OS=$([ $(uname -s) = "Darwin" ] && echo "-osx")
LMURL="$(curl -s https://api.github.com/repos/frioux/leatherman/releases/latest |
   grep browser_download_url |
   cut -d '"' -f 4 |
   grep -F leatherman${OS}.xz )"
mkdir -p ~/bin
curl -sL "$LMURL" > ~/bin/leatherman.xz
xz -d -f ~/bin/leatherman.xz
chmod +x ~/bin/leatherman
~/bin/leatherman explode

This asssumes that ~/bin is in your path. The explode command will create a symlink for each of the tools listed below.

Usage

Each tool takes different args, but to run a tool you can either use a symlink (presumably created by explode):

$ echo "---\nfoo: 1" | yaml2json
{"foo":1}

or use it as a subcommand:

echo "---\nfoo: 1" | leatherman yaml2json
{"foo":1}

Tools

allpurpose

chat

leatherman

misc

notes

Debugging

In an effort to make debugging simpler, I've created three ways to see what leatherman is doing:

Tracing

LMTRACE=$somefile will write an execution trace to $somefile; look at that with go tool trace $somefile

Since so many of the tools are short lived my assumption is that the execution trace will be the most useful.

Profiling

LMPROF=$somefile will write a cpu profile to $somefile; look at that with go tool pprof -http localhost:10123 $somefile

If you have a long running tool, the pprof http endpoint is exposed on localhost:6060/debug/pprof but picks a random port if that port is in use; the port can be overridden by setting LMHTTPPROF=$someport.

Auxiliary Tools

Some tools are annoying to have in the main leatherman tool. Maybe they pull in deps that are huge or need cgo, but in any case I try to keep them separate. For now, these tools are under leatherman/cmd and must be built and run separately. At some point I may come up with a policy around building or naming these, but for now they are simply extra tools.