0

I am trying to create an alias for creating a GitHub repo using the terminal and the command to do so is curl -u 'username' https://api.github.com/user/repos -d '{"name":"repo_name"}'

I've defined a function inside my .zshrc file gitcreate() that is supposed to create a GitHub repo using the first parameter as its name

gitcreate() {
  curl -u 'my_gh_username' https://api.github.com/user/repos -d '{"name":"$1"}'
}

unfortunately, I keep getting the error {"message": "Problems parsing JSON", "documentation_url": "https://docs.github.com/rest/reference/repos#create-a-repository-for-the-authenticated-user"} I've tried escaping the $ and other suggestions I read online but nothing worked and I was hoping someone has a simple solution to this/can refer me to somewhere I might be able to find an answer. thanks!

Kaleb
  • 1

1 Answers1

1

Just

"{\"name\":\"$1\"}"

or

'{"name":"'"$1"'"}'

but at best would be to use proper JSON tool:

data=$(jq -n --arg arg "$1" '{"name": $arg}')
curl ...  "$data"
KamilCuk
  • 120,984
  • 8
  • 59
  • 111