From ee7a8a710674951089591b78ea84574f2836a03a Mon Sep 17 00:00:00 2001 From: Mac Heller-Ogden Date: Mon, 6 Mar 2017 09:45:46 -0600 Subject: [PATCH] various fixes and cleanup --- cli.js | 4 ---- dotfiles/cli.sh | 18 +++++++++++------- lib/syncExisting.js | 9 ++++++--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/cli.js b/cli.js index a5a2b7d..b7e4892 100644 --- a/cli.js +++ b/cli.js @@ -9,10 +9,6 @@ const output = require('./lib/output'); module.exports = cli; -process.on('SIGINT', () => { - process.exit(1); -}); - function setSearchTerm(options) { let searchTerm; let defaultToCurrent = _.pick(options, [ diff --git a/dotfiles/cli.sh b/dotfiles/cli.sh index eb6a0a3..660c5f7 100644 --- a/dotfiles/cli.sh +++ b/dotfiles/cli.sh @@ -1,16 +1,17 @@ #!/usr/bin/env bash -function bitcar_cli() { - local workspace_dir="${BITCAR_WORKSPACE_DIR:-"$HOME/bitcar-repos"}" +function bitcar_cli { + local workspace_dir target cmd nbin + workspace_dir="${BITCAR_WORKSPACE_DIR:-"$HOME/bitcar-repos"}" if [ -z "$1" ]; then cd "$workspace_dir"; return fi - local target="$HOME/.bitcar/.bitcar_target" + target="$HOME/.bitcar/.bitcar_target" - local cmd=() - local nbin="$(ls -d1 $HOME/n/n/versions/node/* | egrep '6\.\d\.\d' | tail -1 | tr -d '[:space:]')/bin/node" + cmd=() + nbin="$(ls -d1 $HOME/n/n/versions/node/* | egrep '6\.\d\.\d' | tail -1 | tr -d '[:space:]')/bin/node" if [[ -x "$nbin" ]]; then cmd+=( "$nbin" "$(which bitcar)" "$@" ); else @@ -18,13 +19,16 @@ function bitcar_cli() { fi if "${cmd[@]}"; then - cd "$(cat "$target")" + + [ -f "$target" ] && cd "$(cat "$target")" > /dev/null 2>&1 + if [ "$1" = "--edit" ] || [ "$2" = "--edit" ] || [ "$1" = "-e" ] || [ "$2" = "-e" ]; then if [ -n "$BITCAR_EDITOR_CMD" ]; then "$BITCAR_EDITOR_CMD" "$(cat "$target")/" fi fi - rm "$target" + + [ -f "$target" ] && rm "$target" fi } diff --git a/lib/syncExisting.js b/lib/syncExisting.js index c81a0bb..9ba0017 100644 --- a/lib/syncExisting.js +++ b/lib/syncExisting.js @@ -55,9 +55,12 @@ function syncExisting() { return acc; }, {}); - let sourceData = _.reduce(hosts, (acc, host) => { - acc[host] = _.unionBy(cache[host], entries[host], 'name'); - return acc; + let sourceData = _.reduce(_.union(_.keys(entries, cache)), (kacc, key) => { + kacc[key] = _.reduce(_.union(_.map(cache[key], 'name'), _.map(entries[key], 'name')), (eacc, name) => { + eacc.push(_.assign({}, _.find(entries[key], { name }), _.find(cache[key], { name }))); + return eacc; + }, []); + return kacc; }, {}); sourceData['github.com'] = _.map(sourceData['github.com'] || [], (repo) => {