phallstrom / AlfredGist

An workflow for Alfred to create Gists from your clipboard contents or selected file(s).
160 stars 10 forks source link

python: command not found #36

Open lirenyeo opened 2 years ago

lirenyeo commented 2 years ago

Error Message:

[22:03:43.349] STDERR: Gist[[Run Script] functions.sh: line 236: python: command not found

I'm not sure how does the shim work for Alfred? I have python 2 installed via pyenv:

❯ which python                                                                                                                                                                          ─╯
/Users/liren/.pyenv/shims/python

❯ python --version                                                                                                                                                                      ─╯
Python 2.7.18

However the /usr/bin/python3 executable could be read by the Alfred Workflow, so I tried changing the script to python3:

echo -n "$1" | python3 -c 'import json,sys; print json.dumps(sys.stdin.read())'

But I don't think the string can be parsed correctly because I will still get error from gist API:

{
  "message": "Problems parsing JSON",
  "documentation_url": "https://docs.github.com/rest/reference/gists#create-a-gist"
}
mjball commented 2 years ago

I'm also getting this Problems parsing JSON" error, whether I use python2 or python3.

MBrouns commented 1 year ago

Changing the relevant parts to the following fixed it for me:

#
# Escape JSON string
#
function json_escape()
{
  echo -n "$1" | python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()))'
}

#
# Get Gist API endpoint from top level API
#
function get_gist_api()
{
  # GitHub.com & GitHub Enterprise have different
  if [[ "${server}" == 'api.github.com' ]]; then
    echo "https://${server}/gists"
  else
    curl --silent --header "$auth_header" https://$server/api/v3 | python3 -c 'import json,sys; print(json.loads(sys.stdin.read())["gists_url"].split("{")[0])'
  fi
}