Giter Site home page Giter Site logo

gisht's Introduction

gisht

Gists in the shell

Build Status License

With gisht, you can run scripts published as GitHub (or other) gists with a single command::

gisht Xion/git-today

Behind the scenes, gisht will fetch the gist, cache it locally, and run its code. Magic!

Usage

gisht [OPTIONS] [SUBCOMMAND]

OPTIONS:
    -c, --cached     Operate only on gists available locally
    -f, --fetch      Always fetch the gist from a remote host
    -v, --verbose    Increase logging verbosity
    -q, --quiet      Decrease logging verbosity
    -H, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    run      Run the specified gist [aliases: exec]
    which    Output the path to gist's binary
    print    Print the source code of gist's binary [aliases: cat]
    open     Open the gist's webpage [aliases: show]
    info     Display summary information about the gist [aliases: stat]
    hosts    List supported gist hosts (services) [aliases: services]
    help     Prints this message or the help of the given subcommand(s)

Hint: `gisht run GIST` can be shortened to just `gisht GIST`.
If you want to pass arguments, put them after `--` (two dashes), like this:

	gisht Octocat/greet -- "Hello world" --cheerful

Installation

Binaries are available for Linux and Mac.

If you use Mac OS X, gisht can be installed with Homebrew:

brew tap Xion/gisht https://github.com/Xion/gisht.git
brew install gisht

Windows binaries coming soon.

Development

gisht is written in Rust. Besides the Rust toolchain, build requirements include:

  • cmake 2.8.11 or higher (for compiling libgit2)
  • OpenSSL 1.1 (for hyper)
    • on Linux, it likely means libssl1.1, libssl-dev, and/or equivalent package(s) must be installed
    • on OSX, besides the relevant package, it may also require adjusting some environment variables
    • (Windows unknown)
  • Some Linux setups may require installing of libssh-dev and pkg-config.

Additionally, the Python-based Invoke task runner is used for automation. It is recommended you install it inside a Python virtualenv. e.g.:

$ virtualenv ~/venv/gisht && source ~/venv/gisht/bin/activate
$ pip install -r -requirements-dev.txt

Then you can use:

$ inv

to build the binary and run tests.

gisht's People

Contributors

xion avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

gisht's Issues

Add codesend.com

Looks to be mostly Basic, but there is no separate raw URL apparently, so would require HTML scraping.

Add termbin.com

Seems like a very Basic gist host that you only access from the command line / telnet / netcat. Raw URLs in the form termbin.com/$LETTERS, and no HTML URLs.

Panic on fresh Linux box

$ RUST_BACKTRACE=1 inv run -- Xion/list_tags.sh
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/gisht Xion/list_tags.sh`
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /checkout/src/libcore/option.rs:335:20
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:397
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:611
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:572
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:522
   7: rust_begin_unwind
             at /checkout/src/libstd/panicking.rs:498
   8: core::panicking::panic_fmt
             at /checkout/src/libcore/panicking.rs:71
   9: core::panicking::panic
             at /checkout/src/libcore/panicking.rs:51
  10: <core::option::Option<T>>::unwrap
             at /checkout/src/libcore/macros.rs:32
  11: gisht::hosts::github::api::GistsIterator::gist_from_json
             at src/hosts/github/api.rs:155
  12: gisht::hosts::github::api::GistsIterator::next_cached
             at src/hosts/github/api.rs:106
  13: <gisht::hosts::github::api::GistsIterator<'o> as core::iter::iterator::Iterator>::next
             at src/hosts/github/api.rs:95
  14: <&'a mut I as core::iter::iterator::Iterator>::next
             at /checkout/src/libcore/iter/iterator.rs:2278
  15: core::iter::iterator::Iterator::find
             at /checkout/src/libcore/iter/iterator.rs:1565
  16: gisht::hosts::github::resolve_gist
             at src/hosts/github/mod.rs:191
  17: <gisht::hosts::github::GitHub as gisht::hosts::Host>::fetch_gist
             at src/hosts/github/mod.rs:50
  18: gisht::decode_gist
             at src/main.rs:244
  19: gisht::main
             at src/main.rs:126
  20: __rust_maybe_catch_panic
             at /checkout/src/libpanic_unwind/lib.rs:99
  21: std::rt::lang_start
             at /checkout/src/libstd/panicking.rs:459
             at /checkout/src/libstd/panic.rs:361
             at /checkout/src/libstd/rt.rs:61
  22: main
  23: __libc_start_main
  24: _start

Add glot.io

HTML pages are in the format https://glot.io/snippets/$LETTERS but there doesn't seem to be a raw version at all. However, there seems to be a dedicated API that allows to fetch snippets by ID: https://github.com/prasmussen/glot-snippets/blob/master/api_docs/get_snippet.md.

The host also supports gists spanning multiple files (like GitHub) but maybe we can ignore it for now and just pick the first file. It would be best to fetch them all, though, place in a directory, and link the first file as gist's executable -- i.e. very much like GitHub, just a little smarter (files in GitHub gists aren't ordered, but here there seem to be).

Accept "arbitrary" URLs

Instead of just canned URLs to gists, we could accept "any" URL that points to code. At first this could be just plain text code (like raw versions of files hosted in regular repos on GitHub/BitBucket/Gitlab/etc.). V2 may also accept HTML browser URLs where we'd try to find the code based on some heuristics.

Internally, http could function like a virtual gist Host. The Uri would have to be expanded to essentially allow arbitrary URLs and not just <owner>/<name>. Or we could introduce a more general gist moniker (essentially a more advanced version of args::GistArg).

Add paste.bananium.fr

Mostly a simple gist host but it seems it doesn't have a raw URL. Instead, the raw gist text is within a div#cleartext element in the HTML that'd have to be extracted out.

Add zerobin.net

Okay, this one is funky. The raw gist doesn't actually seem to have an URL at all, it just shown on the HTML page via JavaScript (!). So we probably have to fish it right out of its HTML element (#cleartext), in which it is pretty conveniently stored as a single blob of text.

Ship with man page

Besides containing the command line usage, the man page should describe all the various gists hosts that are supported and their URI formats. And the HTML urls, and so on.

The man page can be written in Markdown & compiled with Pandoc, like here: https://github.com/BurntSushi/ripgrep/tree/master/doc . This should preferably happen on Travis.

Add ghostbin.com

This host should be a typical Basic host with ghostbin.com/paste/$ID as HTML URL format and ghostbin.com/paste/$ID/raw as raw URL format. IDs are digits and lowercase letters.

Add dpaste.com

This shouldn't be confused with dpaste.de which is different and already implemented :)

dpaste.com looks like a Basic gist, with simple URL patterns for both HTML and raw URLs.

Stop when a GitHub gist is found

When looking for a GitHub gist, the entire list of gists for a user is looked through. This makes more HTTP requests to GitHub API than necessary.

Turn list_gists function into an Iterator which dispenses gists semi-lazily, only talking to the API when strictly necessary.

Add IRCCloud's pastebin

This is almost Basic pastebin that automatically creates gists out of things pasted into IRCCloud client by its user. The HTML URL format is something like https://irccloud.mozilla.com/pastebin/fqQ7iPhh/, and the raw version is easily accessible.

One caveat is that in the raw version, the actual code seems to be prefaced with an additional line that says # Pastebin $ID. It's unknown whether # is added smartly as to coincide with the comment syntax of the snippet (which would imply that some language inference is done, and that's unlikely).

Even if so, we don't really want that line as it would screw up with shebang handling, either by the OS or us. So we'll have to remove it when downloading the gist.

Publish Debian package

We're building a .deb package but it isn't hosted by any APT repositories. This should change. Most likely a dedicated Debian repository is needed ;/

Add paste.pound-python.org

Straightforward Basic gist host.

The language seems to be baked into the gist itself there, and not any particular link to it, though, so if we want to extract it it, we'd need to look at the HTML code. (Specifically for a .lang-$LANG CSS class of div#paste). But since this would only be for gisht info, it's very low priority.

Example paste: https://paste.pound-python.org/show/EGVEeDuanaGoaUy33Ydi/
Proposed host ID: ppp

Honor locality flags when fetching GitHub gists

GItHub::fetch_gist is not properly honoring --cached & --remote flags now, and refreshing local gists based on the time of last git pull.

We should pass Locality as additional param to Host::fetch_gist and have GitHub impl use it when fetching gists.

Migrate to serde_json

The interface is very similar to rustc_serialize::json so it should be pretty easy.

The reasoning is that rustc_serialize is apparently semi-deprecated.

Add nopaste.me

Straightforward Basic host, it seems, with the following URL patterns:

  • HTML: https://nopaste.me/view/$ID
  • raw: https://nopaste.me/view/raw/$ID

ID format is [0-9A-Za-z]+ from the looks of it.

Alternate raw URL is https://nopaste.me/view/download/$ID, with Content-Disposition:attachment (file download in browsers) where the filename has an extension which seems to correspond to the language of the gist. So ideally we'd hit that to get the gist::info::Language.

Add "meta" command(s)

There should be a way to obtain information about & do things to the gisht app itself. Some of those information pieces include:

  • the gist hosts we support, including the URL format that each one accepts (gisht hosts or gisht services)
  • information about currently cached gists and/or gists matching given pattern (gisht ls; requires a little more thought into how it'd be used but "local-only" should probably NOT be the default)
  • gisht clean to purge all downloaded gists (probably with confirmation) from the locla cache, or gists of given host, or a specific gist

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.