Small, focused CLI that merges the behavior of dirname and basename with a few convenient extras. Designed for shell scripts and Makefiles where a compact, predictable filename-manipulation utility is useful.
- From source (recommended):
go install github.com/grimdork/name@latest- Build locally:
make buildname [OPTIONS]... [FILENAME]
name -hshows helpname -vprints the build version and build date (when provided via ldflags)
This tool intentionally operates on a single path per run (one input filename, one output). It's meant to be a tiny, predictable helper in shell pipelines and Makefiles.
-p,--nopath— return only the base filename (strip directory path)-s,--stripsuffix— strip the suffix (file extension) from the name-S,--onlysuffix— return only the suffix (extension) without the leading dot-n,--noname— return only the path (directory component). On bare filenames this is normalized to an empty string rather than.-a,--absolute— expand the name to an absolute path-0,--null— terminate output with a NUL (0x00) byte instead of a newline. Useful when embedding this single result into a larger NUL-separated stream or when passing toxargs -0.
# basename-like
name -p /usr/bin/env
# => env
# strip suffix
name -s main.go
# => main
# suffix only
name -S archive.tar.gz
# => gz
# dirname-like
name -n /sbin/ping6
# => /sbin
# absolute path
name -a main.go
# => /home/alice/src/name/main.go
# combined: absolute + strip suffix
name -as main.go
# => /home/alice/src/name/main
# NUL-terminated output (safe to embed or pass to xargs -0)
name -0 some/path/file.txt | xargs -0 -I{} echo "got: {}"- The
-S(only suffix) flag takes precedence and returns immediately; other flags are not applied when-Sis used. - When
-n(directory-only) is used on a bare filename (e.g.foo),filepath.Dir("foo")returns.; this tool normalises that to an empty string for scripting convenience. - Suffix handling follows
filepath.Ext: the suffix is the final.component. Forarchive.tar.gzthe suffix isgzand-sremoves only the final.gz. - This program operates on a single path per run. If you need to operate on many files, use
find,git ls-files, or a shell loop and callnameonce per file.
0— success1— user/input/usage errors (missing filename, parse error)2— runtime/program errors (I/O failure, processing error)
- Run tests:
make test- Vulnerability scan:
make govulncheck- Linting is currently disabled in CI due to a runner/tooling compatibility issue; the Makefile includes a placeholder
linttarget.
Open issues and PRs are welcome. Please run the test suite and include a short description of your change.
MIT — see LICENSE