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 toolkit.
Add this line to your application's Gemfile:
gem "tty-which"
And then execute:
$ bundle
Or install it yourself as:
$ gem install tty-which
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:
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:
TTY::Which.which("/usr/bin/ruby") # => "/usr/bin/ruby"
You can also specify directly the paths to search using :paths
keyword:
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:
TTY::Which.exist?("ruby") # => true
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 code of conduct.
- Fork it ( https://github.com/piotrmurach/tty-which/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
Copyright (c) 2015 Piotr Murach. See LICENSE for further details.