-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed commands duplication in bash_profile
- Loading branch information
1 parent
1e6d09c
commit 053e93e
Showing
1 changed file
with
26 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |