Skip to content

Commit

Permalink
simplify bash function and support colors
Browse files Browse the repository at this point in the history
  • Loading branch information
machellerogden committed Feb 10, 2017
1 parent b097021 commit d67f277
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
5 changes: 1 addition & 4 deletions dotfiles/cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
function bitcar_cli() {
local root="${BITCAR_ROOT_DIR:-"$HOME/bitcar-repos"}"
[ -z "$1" ] && cd "$root" && return
set -o pipefail
BITCAR_CLI_TARGET_TMP=$(mktemp 2>/dev/null || mktemp -t tmp)
BITCAR_CLI_SELECT_TMP=$(mktemp 2>/dev/null || mktemp -t tmp)
set -- bitcar "$@" && "$@" | tee $BITCAR_CLI_SELECT_TMP && tail -1 $BITCAR_CLI_SELECT_TMP | "$HOME/.bitcar/strip_codes" >| $BITCAR_CLI_TARGET_TMP && echo && cd $(cat $BITCAR_CLI_TARGET_TMP)
set -- bitcar "$@" && "$@" && cd "$(cat "$BITCAR_ROOT_DIR/.bitcar_target" )"
}
alias <%= alias %>=bitcar_cli
7 changes: 2 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#!/usr/bin/env node
const cli = require('./cli');
const argv = require('optimist').argv;
const setTarget = require('./lib/setTarget');

cli(argv)
.then((sourceResult) => {
if (sourceResult && sourceResult.repoDir) {
console.log(sourceResult.repoDir);
}
})
.then(setTarget)
.catch((err) => {
console.log(err.message);
process.exit(1);
Expand Down
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';
exports.fs = require('./fs');
exports.getPaths = require('./getPaths');
exports.getSourceData = require('./getSourceData');
exports.getSourceResult = require('./getSourceResult');
exports.maybeClone = require('./maybeClone');
exports.openInBrowser = require('./openInBrowser');
exports.rootDir = require('./rootDir');
exports.setTarget = require('./setTarget');
18 changes: 18 additions & 0 deletions lib/setTarget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
const fs = require('./fs');
const rootDir = require('./rootDir');
const path = require('path');

module.exports = setTarget;

function setTarget(sourceResult) {
return new Promise((resolve, reject) => {
if (sourceResult && sourceResult.repoDir) {
fs.write(path.normalize(rootDir + '/.bitcar_target'), sourceResult.repoDir);
fs.commit((err) => {
if (err) return reject(err);
return resolve(sourceResult.repoDir);
});
}
});
}

0 comments on commit d67f277

Please sign in to comment.