LinuxCommandLibrary

gist

Create Gists from the command line

TLDR

Log in to gist on this computer

$ gist --login
copy

Create a gist from any number of text files
$ gist [file.txt] [file2.txt]
copy

Create a private gist with a description
$ gist --private --description "[A meaningful description]" [file.txt]
copy

Read contents from stdin and create a gist from it
$ [echo "hello world"] | gist
copy

List your public and private gists
$ gist --list
copy

List all public gists for any user
$ gist --list [username]
copy

Update a gist using the ID from URL
$ gist --update [GIST_ID] [file.txt]
copy

SYNOPSIS

gist [options] [file...]
gist -l
gist -d GIST_ID
gist -u GIST_ID [file...]
gist -o [GIST_ID]
gist -p | -s [file...]
gist -a [file...]
gist -h | -v

PARAMETERS

-p, --private, -s, --secret
    Makes the created gist private (secret), meaning it will not be discoverable by others unless they have the direct URL.

-P, --public
    Explicitly makes the created gist public. This is often the default behavior if no privacy option is specified.

-d, --delete GIST_ID
    Deletes the specified gist. Requires authentication and ownership of the gist.

-u, --update GIST_ID
    Updates an existing gist with new content from specified files or STDIN. Requires authentication and ownership.

-l, --list
    Lists your gists. Requires authentication to list private gists.

-o, --open [GIST_ID]
    Opens the created gist (or a specified existing gist) in your default web browser.

-c, --copy
    Copies the URL of the created gist to your system's clipboard.

-a, --anonymous
    Creates a gist anonymously, not associated with your GitHub account.

-h, --help
    Displays the help message, showing command usage and options.

-v, --version
    Shows the version information of the gist command.

-f, --filename FILENAME
    Specifies a filename for content provided via STDIN. Useful for syntax highlighting on GitHub.

-r, --raw
    Prints the raw content of a gist (identified by GIST_ID or the last created gist) to standard output.

--description DESCRIPTION
    Adds a textual description to the gist being created or updated.

--embed
    Outputs the HTML embed code for the created gist, allowing it to be easily embedded in web pages.

DESCRIPTION

The gist command-line utility provides a convenient interface for interacting with GitHub Gists directly from your terminal. GitHub Gists are a simple way to share notes, code snippets, and configuration files with others. The gist command simplifies the process of creating new gists from files or standard input, managing existing gists (like listing, opening in a browser, updating, or deleting), and controlling their privacy settings (public or secret). It's particularly useful for quickly sharing code during debugging sessions, demonstrating concepts, or collaborating on small pieces of text. Unlike full-fledged version control systems, Gists are designed for simplicity and quick sharing, and the gist command enhances this efficiency by integrating it directly into your command-line workflow. It typically relies on curl for API interactions and can be configured with a GitHub personal access token for authenticated operations.

CAVEATS

The gist command is not a standard, pre-installed Linux utility; it must be downloaded and installed separately. It typically relies on external tools like curl for network requests and, for clipboard functionality, tools such as xclip (Linux) or pbcopy (macOS). To fully utilize features like listing your private gists, deleting, or updating existing ones, you will need a GitHub account and often a personal access token for authentication, which is usually stored in a configuration file (e.g., ~/.gist). Without proper authentication, only public or anonymous gist creation might be available.

AUTHENTICATION

To interact with your GitHub account (e.g., for private gists, listing your gists, or updating), gist typically uses a GitHub Personal Access Token. This token can be stored in a configuration file, commonly ~/.gist, or the command might prompt you for your GitHub username and password the first time you perform an authenticated action. Ensure the token has the necessary 'gist' scope to grant appropriate permissions.

INPUT HANDLING

The gist command can accept input in several ways. You can provide one or more filenames as arguments, and each file will be uploaded as part of the new gist. If no files are specified, gist reads content from standard input (STDIN), allowing you to pipe output from other commands directly into a new gist. For example, ls -l | gist would create a gist containing the long listing of files.

HISTORY

The gist command emerged as a popular and simple shell script, notably the one by defunkt (Chris Wanstrath), designed to streamline interactions with GitHub Gists. Its development was driven by the need for a quick and uncumbersome way to share code snippets directly from the command line, bypassing the web interface. Its lightweight nature and ease of installation contributed to its widespread adoption among developers for rapid sharing and collaboration.

SEE ALSO

curl(1), git(1), xclip(1)

Copied to clipboard