Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

8 Commits

Repository files navigation

nix_utils

A collection of common command-line tools rebuilt in Spinel — a compiled Ruby language. Each tool works the same way as the classic Unix versions you already know, but runs as a fast native binary produced by the Spinel compiler.

What is this?

If you have ever typed ls, grep, cat, or sort in a terminal, you have used tools like these. This project rebuilds 71 of them in Spinel so you can study how they work, learn Spinel by reading real programs, or use them on systems where the usual tools are not available.

What tools are included?

ToolWhat it does
base64Convert files to safe text and back
basenameGet just the file name from a full path
catPrint files to the screen
cksumCreate a checksum fingerprint for a file
columnLine up text into neat columns
commCompare two sorted files
cpCopy files and directories
cutPull out selected columns from each line
dateShow the current date and time
dirnameGet the folder part of a file path
duFind out how much disk space files are using
echoPrint words to the screen
envShow environment variables
expandChange tab characters into spaces
factorBreak a number into its prime factors
falseDo nothing and report failure
findSearch for files and folders
fmtReformat text paragraphs to a target width
foldWrap long lines to fit a certain width
grepSearch for lines that match a pattern
headShow the first few lines of a file
hexdumpShow the raw bytes of a file in hex
hostnameShow the name of this computer
idShow who you are logged in as
joinCombine two files by matching a shared field
lnCreate a link (shortcut) to a file
lognamePrint your login name
lsList files and folders in a directory
md5sumCalculate or check MD5 fingerprints
mkdirCreate a new folder
mktempCreate a temporary file with a unique name
mvMove or rename a file
nlAdd line numbers to a file
nprocPrint how many processor cores are available
numfmtConvert numbers to and from human-readable form
odDump file contents in octal or other formats
pasteCombine lines from multiple files side by side
printenvPrint the value of environment variables
printfFormat and print text with precise control
pwdPrint the current working directory
readlinkShow where a symbolic link points
realpathPrint the full, real path of a file
rmDelete files and directories
rmdirRemove an empty directory
sedFind and replace text in a stream
seqPrint a sequence of numbers
sha1sumCalculate or check SHA-1 fingerprints
sha224sumCalculate or check SHA-224 fingerprints
sha256sumCalculate or check SHA-256 fingerprints
sha384sumCalculate or check SHA-384 fingerprints
sha512sumCalculate or check SHA-512 fingerprints
shufRandomly shuffle lines
sleepPause for a set amount of time
sortArrange lines in order
splitChop a big file into smaller pieces
statShow detailed information about a file
stringsFind readable text hidden inside any file
tacPrint a file in reverse order
tailShow the last few lines of a file
teeSend output to both the screen and a file
touchUpdate a file's timestamp or create an empty file
trTranslate or delete characters
trueDo nothing and report success
tsortSort a list where some items must come before others
unamePrint information about the operating system
unexpandConvert spaces back into tab characters
uniqRemove or report duplicate lines
wcCount lines, words, and characters in a file
whoamiPrint your current username
xargsBuild and run commands using a list of items
yesRepeatedly print the same text over and over

Install Spinel

With asdf:

asdf plugin add spinel https://github.com/jockofcode/asdf-spinel
asdf install spinel master
asdf set -u spinel master # make it the default (~/.tool-versions)

Or build it from source:

git clone https://github.com/matz/spinel.git
cd spinel
make
export PATH="$PWD/bin:$PATH"cd -

How to build

You need the Spinel compiler installed. Building the whole repo produces bin/spin alongside the compiler.

Build a single tool:

spin build bin/cat.rb

Run a tool without building first:

spin run bin/cat.rb -- myfile.txt

Build all tools:

spin build

Compiled binaries land in build/bin/. Install them to ~/.local/bin so you can use them anywhere:

spin install

Project layout

nix_utils/
spin.toml Project settings
nix_utils/
nix_helpers.rb Shared helper functions used by many tools
file_ext.rb Bindings to native C file operations
sp_file_ext.c Native C code for file operations not in Spinel yet
proc_ext.rb Bindings to native C process operations
sp_proc_ext.c Native C code for process operations not in Spinel yet
checksum_tool.rb Shared code for all the checksum tools (md5sum, sha*sum)
bin/
cat.rb Each file here is one tool
grep.rb
ls.rb
...
test/
test_file_ext.rb Tests for the native C file extension
man/
cat.1.txt Plain-text manual page for each tool
grep.1.txt
...
build/ Compiled binaries go here (do not commit this folder)

Reading the manual pages

Each tool has a plain-text manual page in the man/ folder written in simple language. To read one, open it in any text viewer:

cat man/grep.1.txt

Or pipe it through a pager:

cat man/sort.1.txt | less

Running the tests

spin test

License

MIT — see LICENSE.

About

Unix Utility programs rewritten in ruby for use with Matz's Spinel: https://github.com/matz/spinel

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages