https://github.com/piotrmurach/tty-which
Cross-platform implementation of Unix `which` command
https://github.com/piotrmurach/tty-which
cli cross-platform ruby-gem tty tty-components which
Last synced: 4 months ago
JSON representation
Cross-platform implementation of Unix `which` command
- Host: GitHub
- URL: https://github.com/piotrmurach/tty-which
- Owner: piotrmurach
- License: mit
- Created: 2015-05-30T22:30:43.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2024-03-08T23:28:29.000Z (over 2 years ago)
- Last Synced: 2026-02-20T07:47:33.731Z (4 months ago)
- Topics: cli, cross-platform, ruby-gem, tty, tty-components, which
- Language: Ruby
- Homepage: https://ttytoolkit.org
- Size: 70.3 KB
- Stars: 22
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# TTY::Which [][gitter]
[][gem]
[][gh_actions_ci]
[][appveyor]
[][codeclimate]
[][coveralls]
[][inchpages]
[gitter]: https://gitter.im/piotrmurach/tty
[gem]: https://badge.fury.io/rb/tty-which
[gh_actions_ci]: https://github.com/piotrmurach/tty-which/actions?query=workflow%3ACI
[appveyor]: https://ci.appveyor.com/project/piotrmurach/tty-which
[codeclimate]: https://codeclimate.com/github/piotrmurach/tty-which
[coveralls]: https://coveralls.io/github/piotrmurach/tty-which
[inchpages]: https://inch-ci.org/github/piotrmurach/tty-which
> Platform independent implementation of Unix `which` utility that searches for executable file in the path variable.
**TTY::Which** provides cross-platform executables search component for [TTY](https://github.com/piotrmurach/tty) toolkit.
## Installation
Add this line to your application's Gemfile:
gem "tty-which"
And then execute:
$ bundle
Or install it yourself as:
$ gem install tty-which
## Usage
**TTY::Which** has `which` method that searches set of directories for an executable file based on the `PATH` environment variable.
When the path to an executable program exists, an absolute path is returned, otherwise `nil`.
For example, to find location for an executable program do:
```ruby
TTY::Which.which("less") # => "/usr/bin/less"
TTY::Which.which("git") # => "C:\Program Files\Git\bin\git"
```
You can also check an absolute path to executable:
```ruby
TTY::Which.which("/usr/bin/ruby") # => "/usr/bin/ruby"
```
You can also specify directly the paths to search using `:paths` keyword:
```ruby
TTY::Which.which("ruby", paths: ["/usr/local/bin", "/usr/bin", "/bin"])
# => "/usr/local/bin/ruby"
```
When you're only interesting in knowing that an executable exists on the system use the `exist?` call:
```ruby
TTY::Which.exist?("ruby") # => true
```
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/piotrmurach/tty-which. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
1. Fork it ( https://github.com/piotrmurach/tty-which/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
## Copyright
Copyright (c) 2015 Piotr Murach. See LICENSE for further details.
