Cross-platform implementation of Unix `which` command
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec
tasks
.gitignore Initial release. May 30, 2015
.rspec Initial release. May 30, 2015
.travis.yml
CHANGELOG.md Add release notes Oct 13, 2018
Gemfile
ISSUE_TEMPLATE.md
LICENSE.txt
PULL_REQUEST_TEMPLATE.md Add templates Oct 12, 2018
README.md Change to update docs with latest additions Oct 13, 2018
Rakefile Initial release. May 30, 2015
appveyor.yml
tty-which.gemspec Change to lock ruby version Oct 12, 2018

README.md

tty logo

TTY::Which Gitter

Gem Version Build Status Build status Code Climate Coverage Status Inline docs

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.

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:

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 knowning that an executable exists on the system use the exist? call:

TTY::Which.exist?('ruby') # => true

Contributing

  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-2018 Piotr Murach. See LICENSE for further details.