blob: 94f23e55dbf0d16bcec578169e25d71c93c404d5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#! /usr/bin/env bash
set -e
# Default settings
SETTING_DIR=${SETTING_DIR:-~/helper}
REPO=${REPO:-typebrook/helper}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-dev}
COMMENT_IN_RCFILE="# $REPO: source custom shell settings"
PROFILE=profile.sh
case "$(basename $SHELL)" in
bash) RCFILE=~/.bashrc
;;
zsh) RCFILE=~/.config/zsh/.zshrc
;;
*) echo Current shell is not bash or zsh; exit 1;
;;
esac
# If ~/helper doesn't exist, do git clone
if [ ! -d $SETTING_DIR ]; then
git clone --depth=1 --branch "$BRANCH" "$REMOTE" "$SETTING_DIR" || {
error "git clone of helper repo failed"
exit 1
}
fi
# Write initial commands into .bashrc or .zshrc
sed -i "\^$COMMENT_IN_RCFILE^, /^$/ d" $RCFILE
cat >>$RCFILE <<EOF
$COMMENT_IN_RCFILE
export SETTING_DIR=$SETTING_DIR
source \$SETTING_DIR/$PROFILE
EOF
echo Add profile into $RCFILE
cd "$SETTING_DIR" || exit 1
make
|