Skip to content

Instantly share code, notes, and snippets.

@papertigers
Forked from bahamas10/0-README.md
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save papertigers/1901d24e1498917d1d1d to your computer and use it in GitHub Desktop.

Select an option

Save papertigers/1901d24e1498917d1d1d to your computer and use it in GitHub Desktop.

Revisions

  1. @bahamas10 bahamas10 revised this gist Aug 3, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions 0-README.md
    Original file line number Diff line number Diff line change
    @@ -39,6 +39,8 @@ Will open the SmartOS changelog in your browser (on a Mac).
    Pass a file as the first argument, or as stdin, to create a paste in manta and print the URL to stdout

    Requires `Pygments`, which can be installed with `sudo easy_install Pygments` or similiar.

    Example

    ```
  2. @bahamas10 bahamas10 created this gist Aug 3, 2015.
    69 changes: 69 additions & 0 deletions 0-README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    Joyent Manta Functions
    ======================

    Taken from https://github.com/bahamas10/dotfiles/blob/master/bashrc

    `mbillable`
    -----------

    > Show amount of billable storage spaced used in Manta
    Allows the user to optionally be specified as the first argument

    Example

    ```
    $ mbillable
    bahamas10 => using 2 GB (3 GB billable)
    $ mbillable papertigers
    papertigers => using 4 GB (5 GB billable)
    ```

    `mopen`
    -------

    > Open Manta files using `open` on the current system
    Example

    ```
    $ mopen /Joyent_Dev/public/SmartOS/smartos.html
    ```

    Will open the SmartOS changelog in your browser (on a Mac).

    `mpaste`
    --------

    > Store pastebin style pastes with syntax highlighting in Manta
    Pass a file as the first argument, or as stdin, to create a paste in manta and print the URL to stdout

    Example

    ```
    $ mpaste .bashrc
    https://us-east.manta.joyent.com/[email protected]/public/pastes/1438621637.html
    $ cat .vimrc | mpaste
    https://us-east.manta.joyent.com/[email protected]/public/pastes/1438621641.html
    ```

    (see https://us-east.manta.joyent.com/[email protected]/public/pastes/1438621637.html)

    `murl`
    ------

    > Convert Manta filenames to URLs
    Example

    ```
    $ murl ~~/public/foo /papertigers/public/foo
    https://us-east.manta.joyent.com/bahamas10/public/foo
    https://us-east.manta.joyent.com/papertigers/public/foo
    ```

    License
    -------

    MIT License
    37 changes: 37 additions & 0 deletions manta.bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    # Total the billable amount in Manta
    mbillable() {
    local u=${1:-$MANTA_USER}
    mget -q "/$u/reports/usage/storage/latest" |\
    json storage | json {public,stor,reports,jobs}.bytes |\
    awk -v "u=$u" "
    {
    s += \$1;
    }
    END {
    gb = s / 1024 / 1024 / 1024;
    billable = gb + 1;
    printf(\"%s => using %d GB (%d GB billable)\\n\",
    u, gb, billable);
    }
    "
    }

    # Open files from manta in the browser
    mopen() {
    murl "$@" | xargs open
    }

    # Paste bin using manta
    mpaste() {
    local mfile=~~/public/pastes/$(date +%s).html
    pygmentize -f html -O full "$@" | mput -p "$mfile"
    murl "$mfile"
    }

    # convert manta paths into URLs
    murl() {
    local u
    for u in "$@"; do
    echo "$MANTA_URL${u/#~~//$MANTA_USER}"
    done
    }