Skip to content

Commit

Permalink
Fixed commands duplication in bash_profile
Browse files Browse the repository at this point in the history
  • Loading branch information
SarathSantoshDamaraju committed Oct 8, 2018
1 parent 1e6d09c commit 053e93e
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions _install
Original file line number Diff line number Diff line change
@@ -1,35 +1,52 @@
#!/bin/bash
# Declare All functions to perform commands

# This Opens the commands.txt, reads the commands into a single variable (lines) and returns it.
readFile () {
#open _commands.txt file and read them in to a single variable and return it.
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
old_IFS=$IFS
IFS=$'\n'
lines=($(cat $dir/'commands.txt'))
IFS=$old_IFS
addCommands
}

# This writes/updates commands to bash_profile.
addCommands () {
echo "πŸ•› Adding commands..."

# Printing Commands to ~/.bash_profile
echo ' '>>~/.bash_profile
echo "# <-------- Lazy Git Commands -------->" >>~/.bash_profile
echo "#Lazy_Git_Commands" >>~/.bash_profile
echo ${lines[@]} >>~/.bash_profile
echo ' '>>~/.bash_profile

# Updating ~/.bash_profile
echo "# <-------- End -------->" >>~/.bash_profile
echo "Updating bash Profile"
echo "#Ends_here" >>~/.bash_profile
echo "βœ… Commands inserted"
source ~/.bash_profile
echo "βœ… Bash profile Updated"

# to Open bash profile type 'open ~/.bash_profile'

echo "πŸ™Œ Thanks for using lazyGit"
}
isBashOpen () {

# Installation invoker function
beginInstallation () {

echo "πŸ•› Checking for .bash_profile..."
# Checks for the existance of .bash_profile file
if ! [ -a ~/.bash_profile ];then
touch .bash_profile
echo "File created. Writing commands"
echo "βœ… File created."
readFile
else
echo "File already exists. Writing Commands.."
echo "βœ… File already exists"
echo "πŸ•› Removing old commands..."
sed -i '' -e '1h;2,$H;$!d;g' -e 's/#Lazy_Git_Commands.*#Ends_here//g' ~/.bash_profile
readFile
fi
}

#Running Installation
isBashOpen
beginInstallation

0 comments on commit 053e93e

Please sign in to comment.