Skip to content

Commit

Permalink
experimental zsh support - still no completions
Browse files Browse the repository at this point in the history
  • Loading branch information
machellerogden committed Feb 21, 2017
1 parent 92994c1 commit 600fa1f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
3 changes: 2 additions & 1 deletion dotfiles/cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
function bitcar_cli() {
local root="${BITCAR_ROOT_DIR:-"$HOME/bitcar-repos"}"
[ -z "$1" ] && cd "$root" && return
bitcar "$@" && cd "$(cat "$BITCAR_ROOT_DIR/.bitcar_target" )"
local target="$HOME/.bitcar/.bitcar_target"
bitcar "$@" && if [ -f "$target" ]; then cd "$(cat "$target")" && rm "$target"; fi
}
alias <%= alias %>=bitcar_cli
3 changes: 2 additions & 1 deletion lib/setTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ const rootDir = require('./rootDir');
const path = require('path');

module.exports = setTarget;
const TARGET_PATH = path.normalize(process.env.HOME + '/.bitcar/.bitcar_target');

function setTarget(sourceResult) {
return new Promise((resolve, reject) => {
if (sourceResult && sourceResult.repoDir) {
fs.write(path.normalize(rootDir + '/.bitcar_target'), sourceResult.repoDir);
fs.write(TARGET_PATH, sourceResult.repoDir);
fs.commit((err) => {
if (err) return reject(err);
return resolve(sourceResult.repoDir);
Expand Down
25 changes: 20 additions & 5 deletions setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,22 @@ source $HOME/.bitcar/completions.sh
fs.copyTpl(path.normalize(__dirname + '/dotfiles/cli.sh'), path.normalize(process.env.HOME + '/.bitcar/cli.sh'), answers);
fs.copyTpl(path.normalize(__dirname + '/dotfiles/completions.sh'), path.normalize(process.env.HOME + '/.bitcar/completions.sh'), answers);
fs.copy(path.normalize(__dirname + '/dotfiles/strip_codes'), path.normalize(process.env.HOME + '/.bitcar/strip_codes'));
fs.copy(path.normalize(process.env.HOME + '/.bash_profile'), path.normalize(process.env.HOME + '/.bash_profile.bkup'));
const bashProfile = fs.read(path.normalize(process.env.HOME + '/.bash_profile'));
let cleanedProfile = bashProfile.replace(/\n# begin bitcar[\s\S]+# end bitcar/gm, '');
cleanedProfile = cleanedProfile + profileContent;
fs.write(path.normalize(process.env.HOME + '/.bash_profile'), cleanedProfile);

const SHELL = process.env.SHELL;
if (SHELL.match(/bash/)) {
fs.copy(path.normalize(process.env.HOME + '/.bash_profile'), path.normalize(process.env.HOME + '/.bash_profile.bkup'));
let profile = fs.read(path.normalize(process.env.HOME + '/.bash_profile'));
let updatedProfile = cleanProfile(profile) + profileContent;
fs.write(path.normalize(process.env.HOME + '/.bash_profile'), updatedProfile);
} else if (SHELL.match(/zsh/)) {
fs.copy(path.normalize(process.env.HOME + '/.zshrc'), path.normalize(process.env.HOME + '/.zshrc.bkup'));
let profile = fs.read(path.normalize(process.env.HOME + '/.zshrc'));
let updatedProfile = cleanProfile(profile) + profileContent;
fs.write(path.normalize(process.env.HOME + '/.zshrc'), updatedProfile);
} else {
console.log('unsupported shell');
process.exit(1);
}

return fs.commit(function (err) {
if (err) return reject(err)
Expand All @@ -119,3 +130,7 @@ source $HOME/.bitcar/completions.sh
});
});
}

function cleanProfile(profile) {
return profile.replace(/\n# begin bitcar[\s\S]+# end bitcar/gm, '');
}

0 comments on commit 600fa1f

Please sign in to comment.