Skip to content

grimdork/name

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

name

CI

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.

Install

  • From source (recommended):
go install github.com/grimdork/name@latest
  • Build locally:
make build

Usage

name [OPTIONS]... [FILENAME]
  • name -h shows help
  • name -v prints 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.

Flags

  • -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 to xargs -0.

Examples

# 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: {}"

Behavior notes and edge cases

  • The -S (only suffix) flag takes precedence and returns immediately; other flags are not applied when -S is 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. For archive.tar.gz the suffix is gz and -s removes 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 call name once per file.

Exit codes

  • 0 — success
  • 1 — user/input/usage errors (missing filename, parse error)
  • 2 — runtime/program errors (I/O failure, processing error)

Development

  • 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 lint target.

Contributing

Open issues and PRs are welcome. Please run the test suite and include a short description of your change.

License

MIT — see LICENSE

About

Merges functionality of the dirname and basename shell commands with a few extra features.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors