Last active
August 29, 2015 14:20
-
-
Save geowarin/b57a194c071b818fa0e3 to your computer and use it in GitHub Desktop.
Publish files as gists with fish shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function gh-gist | |
if not are_installed http jq | |
echo "Please install httpie and jq" | |
return 1 | |
end | |
set -l username (git config --global user.name) | |
echo -n "Enter password for $username : " | |
stty -echo | |
head -n 1 | read -l password | |
stty echo | |
echo | |
for file in $argv; | |
if test -f $file | |
set names $names $file | |
set contents $contents (json_escape_file $file) | |
else | |
echo "$file is not a file" | |
end | |
end | |
for index in (seq (count $names)) | |
set -l name $names[$index] | |
set -l content $contents[$index] | |
set result $result "\"$name\" : { \"content\": $content }" | |
end | |
set files (mktemp -t files) | |
echo "{" (join_arr $result) "}" >> $files | |
set url (http --check-status -a "$username:$password" POST https://api.github.com/gists description="$names[1]" public=true files:=@$files | jq '. | (.html_url)') | |
rm $files | |
echo "Gist created: $url" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function join_arr | |
python -c 'import sys; print ", ".join(sys.argv[1:])' $argv | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function json_escape_file | |
cat $argv | python -c 'import json,sys; print json.dumps(sys.stdin.read())' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment