sh 要克服所有要点的要点

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 要克服所有要点的要点相关的知识,希望对你有一定的参考价值。

Run like so:

```bash
chmod u+x gist-clone-all
./gist-clone-all username OAUTH_TOKEN
```

You'll want to replace “username” with your own username and “OAUTH_TOKEN” with an OAuth token.

This script clones using the *push* URL, so you should probably be the owner of the gists. You could also use this to clone someone else's gists, but in that case you may wish to edit the code to use `gist_pull_url` instead.
#!/usr/bin/env node

var fs = require("fs"),
    https = require("https"),
    exec = require("child_process").exec;

// TODO --pull or --push

var user = process.argv[2],
    token = process.argv[3];

fetchAndClone(1, function callback(error, nextPage) {
  if (error) throw error;
  if (nextPage > 0) fetchAndClone(nextPage, callback);
});

function fetchAndClone(page, callback) {
  fetch(page, function(error, gists) {
    if (error) return callback(error);
    if (gists.length) ++page; else page = -1;
    cloneNext(gists.pop());

    function cloneNext(gist) {
      if (!gist) return callback(null, page);
      if (directoryExists(gist.id)) return cloneNext(gists.pop());
      console.log("cloning " + gist.id);
      exec("git clone git@gist.github.com:" + gist.id + ".git", function(error, stdout, stderr) {
        if (error) return callback(error);
        cloneNext(gists.pop());
      });
    }
  });
}

function fetch(page, callback) {
  var request = https.request({
    hostname: "api.github.com",
    port: 443,
    path: "/users/" + encodeURIComponent(user) + "/gists?page=" + page,
    method: "GET",
    headers: {
      "Accept": "application/vnd.github.v3+json",
      "Authorization": "token " + token,
      "User-Agent": "mbostock/gist-clone-all"
    }
  }, function(response) {
    var chunks = [];
    response.setEncoding("utf8");
    response.on("data", function(chunk) { chunks.push(chunk); });
    response.on("end", function() { callback(null, JSON.parse(chunks.join(""))); });
  });
  request.on("error", callback);
  request.end();
}

function directoryExists(path) {
  try {
    return fs.lstatSync(path).isDirectory();
  } catch (ignored) {
    return false;
  }
}
#!/bin/bash

for i in *; do
  if [ -d $i ]; then
    pushd $i
    git commit -am '' --allow-empty-message && git push
    popd
  fi
done

以上是关于sh 要克服所有要点的要点的主要内容,如果未能解决你的问题,请参考以下文章

sh 你好世界的要点

sh 用于检查区域配置的要点

sh 在浏览器中打开终端的要点

sh ovodafejlesztés要点

sh 这个要点负责升级系统服务(systemd)并由指定用户进入文件夹并执行git pull

python 自动克隆我的所有要点(要点备份?)