Coder Social home page Coder Social logo

piotrmurach / tty-which Goto Github PK

View Code? Open in Web Editor NEW
19.0 4.0 3.0 72 KB

Cross-platform implementation of Unix `which` command

Home Page: https://ttytoolkit.org

License: MIT License

Ruby 100.00%
which tty cli ruby-gem cross-platform tty-components

tty-which's Introduction

TTY Toolkit logo

TTY::Which Gitter

Gem Version Actions CI 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 knowing that an executable exists on the system use the exist? call:

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 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.

tty-which's People

Contributors

olleolleolle avatar piotrmurach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tty-which's Issues

Test failures

Hi,

There are some test failures:

FFF..............

Failures:

  1) TTY::Which#which with extension handles path with executable file C:\Program Files\Git\bin\git
     Failure/Error: expect(Which.which(path_with_exe_file)).to eq(expected_path)
     
     RuntimeError:
       CRITICAL: RUBYGEMS_ACTIVATION_MONITOR.owned?: before false -> after true
     # ./spec/unit/which_spec.rb:86:in `block (3 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NameError:
     #   uninitialized constant RSpec::Support::Differ
     #   ./spec/unit/which_spec.rb:86:in `block (3 levels) in <top (required)>'

  2) TTY::Which#which with extension searches path for executable git
     Failure/Error: expect(Which.which(cmd)).to eq(expected_path)
     
     NameError:
       uninitialized constant RSpec::Support::Differ
     # ./spec/unit/which_spec.rb:122:in `block (3 levels) in <top (required)>'

  3) TTY::Which#which with extension searches path for executable git.exe
     Failure/Error: expect(Which.which(cmd)).to eq(expected_path)
     
     NameError:
       uninitialized constant RSpec::Support::Differ
     # ./spec/unit/which_spec.rb:103:in `block (3 levels) in <top (required)>'

Top 2 slowest examples (0.01244 seconds, 36.8% of total time):
  TTY::Which#which with extension handles path with executable file C:\Program Files\Git\bin\git
    0.00952 seconds ./spec/unit/which_spec.rb:72
  TTY::Which#exist? fails to find executable in the path
    0.00292 seconds ./spec/unit/exist_spec.rb:11

Top 2 slowest example groups:
  TTY::Which#which
    0.00319 seconds average (0.02234 seconds / 7 examples) ./spec/unit/which_spec.rb:3
  TTY::Which#exist?
    0.00185 seconds average (0.0037 seconds / 2 examples) ./spec/unit/exist_spec.rb:3

Finished in 0.03384 seconds (files took 0.1605 seconds to load)
17 examples, 3 failures

Failed examples:

rspec ./spec/unit/which_spec.rb:72 # TTY::Which#which with extension handles path with executable file C:\Program Files\Git\bin\git
rspec ./spec/unit/which_spec.rb:107 # TTY::Which#which with extension searches path for executable git
rspec ./spec/unit/which_spec.rb:89 # TTY::Which#which with extension searches path for executable git.exe

Randomized with seed 58345

Any clue about the fix?

Fails on windows for file with custom extension

On windows you can run TTY::Which.which('something.py') for example and it will return false no matter if .py is in PATHEXT or not. It looks like File.executable? returns false in this case, possibly because it does not know how to deal with windows ACLs.

It looks like File.stat returns 0644 for a file such as this, even though I have the Read & Execute ACL. This may be a bug in ruby or in whatever ruby is using to translate windows ACLs into POSIX mode bits.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.