ptools
Version, currently 0.2.02 versions
- 0.2.0latestMay 9, 2026
- 0.1.1not indexedMay 9, 2026
github.com/djberg96/crystal-ptools
Extra methods for the File class based on Unix command line tools
2 stars
0 dependents
License: MIT
Installation
# Add this to your shard.yml
dependencies:
ptools:
github: djberg96/crystal-ptools
version: ~> 0.2.0Then run:
shards installshard.yml
- Crystal
>= 1.1.0- License
- MIT
- Author
- Daniel Berger
Dependencies
This version declares no dependencies.
README
crystal-ptools
This is a Crystal port of the "ptools" library originally written for Ruby. It contains additional singleton methods for the File class.
Installation
-
Add the dependency to your
shard.yml:dependencies: crystal-ptools: github: djberg96/crystal-ptools -
Run
shards install
Usage
require "crystal-ptools"
# Simulate the "which" command:
File.which("crystal") # => "/opt/homebrew/bin/crystal"
File.which("bogus") # => nil
# Simulate the "whereis" command (minus the man pages):
File.whereis("crystal") # => ["/opt/homebrew/bin/crystal"]
File.whereis("bogus") # => []
# Test to see if a file is an image:
File.image?("/path/to/some_image.bmp") # Is the file an image
# Or check for a specific type of image:
File.bmp?("/path/to/some_file.bmp") # Is the file a bitmap file?
File.jpg?("/path/to/some_file.jpg") # Is the file a JPEG file?
File.ico?("/path/to/some_file.ico") # Is the file an ICO file?
File.png?("/path/to/some_file.png") # Is the file a PNG file?
File.tiff?("/path/to/some_file.tiff") # Is the file a TIFF file?
# Test to see if a file is a binary file:
File.binary?("/bin/ls") # true
File.binary?("/path/to/some_file.jpg") # false
# Simulate the "wc" command:
File.wc("/path/to/some_file.txt", "words")
File.wc("/path/to/some_file.txt", "chars")
File.wc("/path/to/some_file.txt", "lines")
File.wc("/path/to/some_file.txt", "bytes")
Development
To run the specs, simply clone the repo and run crystal spec.
Contributing
- Fork it (https://github.com/djberg96/crystal-ptools/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Daniel Berger - creator and maintainer
Copyright
(C) 2022-2025, Daniel J. Berger All Rights Reserved
Author
Daniel J. Berger
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.2.0- Tagged
- May 9, 2026
- Commit
289e754a2e7e- Crystal
>= 1.1.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/djberg96/crystal-ptools
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 14, 2026
- Synced
- Aug 14, 2026
- Versions
- 2