• Stars
    star
    595
  • Rank 72,281 (Top 2 %)
  • Language
    Shell
  • License
    MIT License
  • Created about 10 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

✅ checks presence of various command line tools and their versions on the path

has

has checks presence of various command line tools on the PATH and reports their installed version.

Build Status Open Source Helpers

demo

Quick Start 🚴

Just install the has script, (there is no dependency apart from bash itself). From the command line, pass the list of commands you want to check as arguments to has, for example:

$ has node npm java git gradle
✔ node 8.2.1
✔ npm 5.3.0
✔ java 1.8.0
✔ git 2.14.1
✔ gradle 4.0.1

If everything is good has exits with status code 0. The exit status code reflects number of commands not found on your path.

$ has node go javac
✔ node 8.2.1
✔ go 1.8.3
✘ javac

And echo the status:

$ echo $?
1

Use has in scripts

has can be used in shell scripts to check presence of tool in very readable way

if has node
    then echo you have what it takes 🎉
fi

Pro Tip: the has in above command can be replaced with the entire curl command for to ensure portability of script → if curl -sL https://git.io/_has | bash -s node then ...

Installing 🚀

has is a single bash script that does it all. You can download the script and make it available on your $PATH. However, to make it even simpler, just follow one of these methods.

Homebrew (MacOS) 🍺

Just run the following:

brew install kdabir/tap/has

Cloning the Repo

Just execute the following command in a terminal: it clones has repo and installs it into your path.

git clone https://github.com/kdabir/has.git && cd has && sudo make install

For a non-root installation:

git clone https://github.com/kdabir/has.git
cd has
make PREFIX=$HOME/.local install

To update just do a git fetch or make update followed by the appropriate make install command.

Downloading to a file

curl -sL https://git.io/_has > /usr/local/bin/has
curl -sL https://git.io/_has | sudo tee /usr/local/bin/has >/dev/null

These commands are safe to be called multiple times as well (to update has)

asdf users

asdf plugin add has https://github.com/sylvainmetayer/asdf-has
asdf install has 1.4.0

Running directly off the Internet

If you are lazy, you can run has directly off the Internet as well:

curl -sL https://git.io/_has | bash -s git node npm
✔ git 2.17.1
✔ node 11.11.0
✔ npm 6.7.0

ProTip: if that's too much typing every time, setup an alias in your .bashrc/.zshrc file:

alias has="curl -sL https://git.io/_has | bash -s"

And use it

$ has git
✔ git 2.17.1
$ type has
has is aliased to `curl -sL https://git.io/_has | bash -s'

Command not understood by has?

Let's say $ has foobar returns foobar not understood, because has may not have whitelisted foobar.

In such cases, pass HAS_ALLOW_UNSAFE=y has foobar. This should still check for existence of foobar and tries to detect version as well.

the value must exactly be y for it to work.

The .hasrc file

has looks for .hasrc file in the directory from where has command is issued. This file can contain commands that has will check for. List one command per line. Lines starting with # are treated as comments.

Following is example of .hasrc file:

# tools
git
curl

# interpreters
ruby
node

When has is run in directory containing this file, it produces:

$ has
✔ git 2.19.1
✔ curl 7.54.0
✔ ruby 2.3.1
✔ node 10.7.0

Also, CLI arguments passed to has are additive to .hasrc file. For example, in the same dir, if the following command is fired, has checks for both commands passed from cli args and provided in .hasrc file.

$ has java
✔ java 11.0.1
✔ git 2.19.1
✔ curl 7.54.0
✔ ruby 2.3.1
✔ node 10.7.0

Pro Tip: commit .hasrc file in root of your project. This can work as a quick check for confirming presence all command line tools required to build and run your project.

On machines that don't even have has installed, your project's .hasrc is honored by this command:

curl -sL https://git.io/_has | bash -s

take a look at .hasrc file for this repo.

Contributing

  1. Star the repo, tweet about it, spread the word
  2. Update the documentation (i.e. the README file)
  3. Adding support for more commands
  4. Adding more features to has

Adding more tools

The current list of supported packages can be viewed with bash tests/packages_all.sh

If the command you wish to include supports any of -v, --version, -version, version, -V then you can find corresponding function which can be called to check presence and extract version. However, for many tools version extraction may not work and you will need to add custom parsing of command's output. The has script is commented to guide developers about what needs to be done to add more tools.

/tests/test_all_packages.bats will test every package has supports. This includes newly added commands so please add new packages to

  • alpine.Dockerfile and ubuntu.Dockerfile to install the tool OR
  • packages_alpine_skip.txt and packages_ubuntu_skip.txt to exclude the package from the tests

Adding Features

If you are contributing a feature, please ensure to check current tests. Add test cases for your feature. Tests are executed using the excellent bats testing framework. Add tests and run make test

Raise the PR and make sure the tests pass on GitHub Actions.

More Repositories

1

awesome-groovy

A curated list of awesome groovy libraries, frameworks and resources
Groovy
704
star
2

gstorm

A simple ORM for databases and CSV files. Intended to be used in groovy scripts and small projects
Groovy
81
star
3

glide

Create awesome apps on Google App Engine in a snap
Groovy
53
star
4

active-directory-lookup

Simplest Java API (and CLI) for authenticating and searching in Active Directory
Java
18
star
5

directree

A Simple DSL to create Directory Tree with Text Files
Groovy
14
star
6

lazybone-templates

My Lazybone Templates
Groovy
14
star
7

nixstall

Generic package installer for the packages that are not listed in your favourite package manager
Shell
9
star
8

mac-setup

Setup MacOS for developers
Shell
8
star
9

redash-mac

Running Redash locally on Mac using Docker Compose
Makefile
7
star
10

json-sql-console

Query json like a pro
JavaScript
7
star
11

tomcat-instance-manager

Manage multiple Tomcat instances on Windows using a single Tomcat installation
Batchfile
6
star
12

feku

Generate Intelligent Random Data
JavaScript
6
star
13

finder-buttons

MacOS Finder buttons for quick actions
AppleScript
6
star
14

gmail-saved-searches

chrome plugin to save your gmail search strings and quickly access when required
JavaScript
4
star
15

travis-groovy

execute groovy scripts on travis-ci
Groovy
3
star
16

stay-awake

Keeps machine awake and unlocked
Java
2
star
17

gradle-helpers

Kitchensink utility methods for any gradle build script
Groovy
2
star
18

directree.rb

A simple DSL to create Directory Tree and Files with content, powered by ruby
Ruby
2
star
19

mksrc

Gradle plugin to create source directories and autogenerate settings.gradle file
Groovy
2
star
20

gatling-starter

A skeleton project for performance testing of your web application
Scala
2
star
21

exfost

Expressions For Statements
TypeScript
1
star
22

roft

Gradle plugin to Rerun Only Failed Tests
Groovy
1
star
23

directree.js

Create directory trees with files and content
JavaScript
1
star
24

to-kv

Converts Array of Objects to a simple Key-Value structure.
JavaScript
1
star