-
Notifications
You must be signed in to change notification settings - Fork 0
/
👍
executable file
·67 lines (57 loc) · 2.11 KB
/
👍
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
set -e
GITHUB_REPO=smurthas/psemoji
GITHUB_URL="https://raw.githubusercontent.com/$GITHUB_REPO/master/$(python -c 'import urllib; print urllib.quote_plus("🚲")')"
INSTALL_DIR=$HOME/.🚲
INSTALL_FILE=$INSTALL_DIR/🚲
mkdir -p $INSTALL_DIR
FILENAME=${BASH_SOURCE[0]}
if [ -f $FILENAME ] && [[ "$FILENAME" != "" ]]
then
# copy in the script from the FS
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cp -r $DIR/🚲 $INSTALL_DIR
else
# curl'd the install script from GH, so let's curl the psemoji script as well
curl -s $GITHUB_URL > $INSTALL_FILE
fi
# install the cronjob
(crontab -l | grep -v "🚲" || true; echo "* * * * * . $INSTALL_FILE && refresh_weather_cache") | crontab -
PROFILE=$HOME/.profile
PROFILE_LINE_COUNT=`cat $PROFILE | wc -l`
PROFILE_TMP=$PROFILE.tmp
PROFILE_BKP=$PROFILE.🚲-bkp
# backup the .profile file just in case
cp $PROFILE $PROFILE_BKP
# add lines to the .profile and write it out
(cat $PROFILE | (grep -v "psemoji" || true) | grep -v "🚲" || true; echo "# psemoji prompt modification 🚲"; echo "source $INSTALL_FILE";) > $PROFILE_TMP
# if they don't have any emoji in their prompt yet, let's add the defaults
source $PROFILE
if [[ !$(echo $PS1 | grep "_pse_") ]]; then
echo "export PS1=\$PSE_STANDARD$PS1" >> $PROFILE_TMP
fi
# check the line count of the new file
NEW_PROFILE_LINE_COUNT=`cat $PROFILE_TMP | wc -l`
if [ "$PROFILE_LINE_COUNT" -gt "$NEW_PROFILE_LINE_COUNT" ]
then
# the line count of the new file was less than that of the old file, this
# shouldn't happen, so we'll let the use know there is a backup and exit 1
echo "😬"
echo "Something doesn't quite seem right with your new $PROFILE file."
echo "But don't worry, there's a backup of the original at $PROFILE_BKP."
exit 1
else
rm $PROFILE
mv $PROFILE_TMP $PROFILE
. $INSTALL_FILE && refresh_weather_cache
echo ""
echo "👍"
echo ""
echo "To be extra double safe that your .profile didn't get messed up we made"
echo "a backup before we started at $PROFILE_BKP. If you"
echo "want to clean it up you can run:"
echo ""
echo " rm $PROFILE_BKP"
echo ""
echo "Thanks, simon"
fi