Skip to content

Instantly share code, notes, and snippets.

@rubo77
Forked from s-leroux/pgist.sh
Last active August 30, 2020 09:41
Show Gist options
  • Select an option

  • Save rubo77/3b8b15f4df5b5287a24f87523c41e4ce to your computer and use it in GitHub Desktop.

Select an option

Save rubo77/3b8b15f4df5b5287a24f87523c41e4ce to your computer and use it in GitHub Desktop.

Revisions

  1. rubo77 renamed this gist Aug 24, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. rubo77 revised this gist Aug 24, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pgist.sh
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ fi
    # 0. file name for the Gist
    if [ "$2" == "" ]; then
    FNAME="$1"
    elif
    else
    FNAME="$2"
    fi

  3. rubo77 revised this gist Nov 19, 2016. 1 changed file with 16 additions and 3 deletions.
    19 changes: 16 additions & 3 deletions pgist.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,18 @@
    # 0. Your file name
    FNAME=some.file
    #!/bin/bash

    GITHUB_USERNAME=rubo77

    if [ "$1" == "" ]; then
    echo 'usage: gistfile-post.sh filename [gistname]'
    exit 0
    fi

    # 0. file name for the Gist
    if [ "$2" == "" ]; then
    FNAME="$1"
    elif
    FNAME="$2"
    fi

    # 1. Somehow sanitize the file content
    # Remove \r (from Windows end-of-lines),
    @@ -27,4 +40,4 @@ EOF
    # curl -X POST -d "${DESC}" "https://api.github.com/gists"

    # REGISTERED USER
    curl -u "${GITHUB_USERNAME}" -X POST -d "${DESC}" "https://api.github.com/gists"
    curl -u "${GITHUB_USERNAME}" -X POST -d "${DESC}" "https://api.github.com/gists"
  4. @s-leroux s-leroux created this gist Jun 24, 2016.
    30 changes: 30 additions & 0 deletions pgist.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    # 0. Your file name
    FNAME=some.file

    # 1. Somehow sanitize the file content
    # Remove \r (from Windows end-of-lines),
    # Replace tabs by \t
    # Replace " by \"
    # Replace EOL by \n
    CONTENT=$(sed -e 's/\r//' -e's/\t/\\t/g' -e 's/"/\\"/g' "${FNAME}" | awk '{ printf($0 "\\n") }')

    # 2. Build the JSON request
    read -r -d '' DESC <<EOF
    {
    "description": "some description",
    "public": true,
    "files": {
    "${FNAME}": {
    "content": "${CONTENT}"
    }
    }
    }
    EOF

    # 3. Use curl to send a POST request

    # ANONYMOUS GIST :
    # curl -X POST -d "${DESC}" "https://api.github.com/gists"

    # REGISTERED USER
    curl -u "${GITHUB_USERNAME}" -X POST -d "${DESC}" "https://api.github.com/gists"