All Projects → hairyhenderson → go-which

hairyhenderson / go-which

Licence: MIT license
A cross-platform Go implementation of the which(1) command, usable both as a CLI and library

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to go-which

sshc
~/.ssh/config swiss army knife
Stars: ✭ 16 (-56.76%)
Mutual labels:  golang-cli
currency
A currency computations package.
Stars: ✭ 52 (+40.54%)
Mutual labels:  go-package
octotui
🐙🐱🖥️ GitHub stats in your terminal
Stars: ✭ 202 (+445.95%)
Mutual labels:  go-package
googletrans
G文⚡️: Concurrency-safe, Free and Unlimited google translate api for Golang. 🔥免费、无限、并发安全的谷歌翻译包
Stars: ✭ 94 (+154.05%)
Mutual labels:  go-package
ip2proxy-go
IP2Proxy Go package allows users to query an IP address to determine if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits.
Stars: ✭ 12 (-67.57%)
Mutual labels:  go-package
valast
Convert Go values to their AST
Stars: ✭ 251 (+578.38%)
Mutual labels:  go-package
cache
LRU-based cache package for Go.
Stars: ✭ 25 (-32.43%)
Mutual labels:  go-package
telegram
📚 Golang bindings for Telegram API
Stars: ✭ 15 (-59.46%)
Mutual labels:  go-package
gut
🍱 yet another collection of go utilities & tools
Stars: ✭ 24 (-35.14%)
Mutual labels:  go-package
rebirth
Supports live reloading for Go
Stars: ✭ 60 (+62.16%)
Mutual labels:  golang-cli
jira-cli
🔥 [WIP] Feature-rich interactive Jira command line.
Stars: ✭ 809 (+2086.49%)
Mutual labels:  golang-cli

go-which

Build Status hairyhenderson/go-which on DockerHub GoDoc

A cross-platform Go implementation of the which(1) command, usable both as a CLI and library.

Usage of which:
  -a    List all instances of executables found (instead of just the first).
  -s    No output, just return 0 if all executables are found, or 1 if some were not found.
  -v    Print the version

Unlike the UNIX which(1) command, even if multiple programs are given as input, only the first one found will be returned.

CLI Usage

Chances are you don't really need this, since most UNIX-like OSes come with the more established (and significantly smaller) C implementation of which(1), either as a standalone binary, or as a shell builtin.

But if there's some reason this may be useful to you, you can use this just like the normal which(1):

$ which zsh
/usr/local/bin/zsh
$ which -a zsh
/usr/local/bin/zsh
/bin/zsh
$ which zsh bash sh
/usr/local/bin/zsh
$ which -a zsh bash sh
/usr/local/bin/zsh
/bin/zsh
/bin/bash
/bin/sh
$ if (which -s zsh bash); then
> echo 'I have zsh and bash installed';
> fi
I have zsh and bash installed
$ if (which -s zsh bash ash); then echo 'yup'
> else
> echo "I'm missing one of them...";
> fi
I'm missing one of them...

Go package usage

If you're writing a program in the Go language, it can be useful to not have to shell out to which(1) to locate a binary.

The simplest usage is:

package main

import (
  "fmt"
  "github.com/hairyhenderson/go-which"
)

func main() {
  zshPath := which.Which("zsh")

  fmt.Printf("zsh found at %s", zshPath)
}

See the godocs for more information.

License

The MIT License

Copyright (c) 2018-2020 Dave Henderson

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].