Skip to content

Add simple command line script #50

Description

@keithrbennett

Hi, Peter, great idea and gem!

I'd like to suggest making the functionality available on the command line as well. A trivially simple implementation would take the string into stdin and output the language code to stdout. You could have a 'whatlanguage' script in /exe containing simply, for example:

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'whatlanguage'

puts WhatLanguage.language_iso($stdin.read) || 'und'

and/or document that one could create a simple alias:

alias whatlanguage='ruby -rwhatlanguage -e '\''puts WhatLanguage.language_iso($stdin.read) || "und"'\'

or, if you prefer, a shell function:

whatlanguage(){ ruby -rwhatlanguage -e 'puts WhatLanguage.language_iso($stdin.read) || "und"'; }

...and then call any as in:

$ whatlanguage < README.md
en

For the executable script, you'd also want to specify this in the gemspec:

spec.bindir = 'exe'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions