Giter VIP home page Giter VIP logo

samefile's Introduction

samefile

⚖️ a portable, POSIX-compliant implementation of Bash’s -ef test

AGPL latest release Super-Linter

Installation

L337

Make sure the executable named samefile in bin/ is either

  • moved into a directory in $PATH, or
  • added to $PATH.

Oh My Zsh

  1. clone the repostory:
git clone --depth 1 https://github.com/LucasLarson/samefile "${ZSH_CUSTOM:-${HOME}/.oh-my-zsh/custom}"/plugins/samefile
  1. Next, open the .zshrc file in your home directory
  2. insert the word samefile between the parentheses on the line that begins with plugins=.
  3. save and close the file, then source it with . "${HOME}"/.zshrc.

Usage

# not this
[ path/to/some/file -ef path/to/another/file ]
# and definitely not this
[[ path/to/some/file -ef path/to/another/file ]]

# but rather this
samefile path/to/some/file path/to/another/file
# or this
samefile --verbose path/to/some/file path/to/another/file
# or this
samefile -v path/to/some/file path/to/another/file

# returns a `0` exit status on success and `1` for failure
# just like `[`, `[[`, and `test`

Bash’s -ef and samefile both check that two files aren’t just similar, but are

  1. the same exact file on
  2. the same exact machine and have
  3. the same exact inode values.

But only samefile properly runs on a maximally portable POSIX-conformant interpreter where stat is also installed. samefile works just fine in Bash environments, too.

samefile's People

Contributors

actions-user avatar dependabot[bot] avatar lucaslarson avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar

samefile's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)

GNU `stat -c` is macOS/FreeBSD `stat -f`

This works on macOS only if stat is an alias to coreutils’s stat (gstat if using Homebrew)

[ "$(stat -L -c %d:%i "${1}")" = "$(stat -L -c %d:%i "${2}")" ] && return 0 || return 1

macOS/FreeBSD stat uses -f instead of -c to format the output.

It would work with an additional test of output...

[ "$(stat -L -c %d:%i "${1}" 2>/dev/null || stat -L -f %d:%i "${1}")" = "$(stat -L -c %d:%i "${2}" 2>/dev/null || stat -L -f %d:%i "${2}")" ] && return 0 || return 1

...which somewhat less illegibly is this:

[ "$(
  stat -L -c %d:%i "${1}" 2>/dev/null ||
  stat -L -f %d:%i "${1}"
)" = "$(
  stat -L -c %d:%i "${2}" 2>/dev/null ||
  stat -L -f %d:%i "${2}"
)" ] && return 0 || return 1

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/changelog.yml
  • actions/checkout v4
  • ruby/setup-ruby v1
  • ad-m/github-push-action v0.8.0
.github/workflows/super-linter.yml
  • actions/checkout v4
  • github/super-linter v5

  • Check this box to trigger a request for Renovate to run again on this repository

the executable has no function call

main() without a function call is an impenetrable opaque box

samefile/bin/samefile

Lines 11 to 27 in 5d78013

main() {
# find if two files refer to the device and inode numbers
# usage: samefile [-v|--verbose] file1 file2
# return 0 if they match
if [ "${1}" = -v ] || [ "${1}" = --verbose ]; then
set -x
shift
fi
# stat
# `-L` to dereference symbolic links # https://superuser.com/a/196655
# `-c` to display %d for device and
# %i for inode
[ "$(stat -L -c %d:%i "${1}")" = "$(stat -L -c %d:%i "${2}")" ] && return 0 || return 1
{ set +x; } 2>/dev/null
}

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.