Skip to content

Commit

Permalink
added bin/fe to check if a file or directory exists in the working di…
Browse files Browse the repository at this point in the history
…rectory. Modified bin files to use `fe`
  • Loading branch information
wesscoby committed Jun 10, 2019
1 parent 4345d98 commit d56986f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 64 deletions.
44 changes: 17 additions & 27 deletions bin/commit
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Options : None

### Git Prefix specifying the current working directory
prefix="--git-dir=$PWD/.git"
prefix="$PWD"

### Text Style and Color formatting
black_on_red_bold="\033[1;30;41m"
Expand All @@ -23,16 +23,6 @@ none="\033[0m"
#======================== HELPER FUNCTIONS ===========================
#===========================================================================================

### check if a file (or directory [or path] ) exists [in the current working directory]
fileExists() {
if [[ -e "$PWD/$1" ]];
then
echo true;
else
echo false;
fi
}

### prompt for boolean response
confirm() {
shopt -s nocasematch # turn on case insensitive matching
Expand All @@ -56,13 +46,13 @@ confirm() {
initRepo() {
read -r -p "Initialize Git Repository? [ Y/N ]: " response;
if [[ $(confirm "$response") == "true" ]]; then
git ${prefix} init # Initialize Repository
git -C ${prefix} init # Initialize Repository
handleArgs $@
elif [[ $(confirm "$response") == "false" ]]; then
printf "\n${blue_bold}Repository is NOT Initialized.\nFiles NOT Committed.\nGoodbye!!!${none}\n\n";
exit 1;
else
echo -e "${red_bold}Invalid Response. Try Again!!!${none}";
errlog "$Invalid Response. Try Again!!!";
initRepo $@
fi
}
Expand All @@ -77,7 +67,7 @@ handleArgs() {
echo "";

if [[ $(confirm "$response") == "true" ]]; then
git ${prefix} add . && git ${prefix} status; # Stage all files and check status
git -C ${prefix} add . && git -C ${prefix} status; # Stage all files and check status
commit;
elif [[ $(confirm "$response") == "false" ]]; then
# prompt user to add files to be staged and committed
Expand All @@ -92,7 +82,7 @@ handleArgs() {
elif [[ $# == 1 ]]; then
# if argument passed is "."
if [[ $1 == "." ]]; then
git ${prefix} add . && git ${prefix} status; # Stage all files and check status
git -C ${prefix} add . && git -C ${prefix} status; # Stage all files and check status
commit;
else
stageFiles $1 # stage the single specified file
Expand All @@ -112,32 +102,32 @@ stageFiles() {

# If only one argument
if [[ $# == 1 ]]; then
if [[ $(fileExists "$1") == "true" ]]; then
git ${prefix} add $1 && git ${prefix} status; # Stage file and check status
if [[ $(fe "$1") == "true" ]]; then
git -C ${prefix} add $1 && git -C ${prefix} status; # Stage file and check status
commit;
else
printf "\n${white_on_red_bold} ERROR ${none} ${red_bold}'%s' NOT found in directory. Check Path or Filename. ${none}\n\n" "$1";
errlog "'$1' NOT found in directory. Check Path or Filename. ${none}\n\n";
handleArgs
fi
else
# More than one argument
for file in "$@"
do
if [[ $(fileExists "$file") == "true" ]]; then
if [[ $(fe "$file") == "true" ]]; then
existing_files+=("$file"); # Add file to array of existent files.
git ${prefix} add "${file}"; # Stage file
git -C ${prefix} add "${file}"; # Stage file
else
nonexistent_files+=("$file"); # Add file to array of nonexistent files.
fi
done

if [[ "${#nonexistent_files[@]}" -ne 0 ]]; then
printf "\n${white_on_red_bold} ERROR ${none} ${red_bold} [ %s ] NOT found in directory. Check Path(s) or Filename(s). ${none}\n\n" "${nonexistent_files[*]}";
git ${prefix} status; # Check status
errlog "[ ${nonexistent_files[*]} ] NOT found in this directory. Check Path(s) or Filename(s)";
git -C ${prefix} status; # Check status
fi

if [[ "${#existing_files[@]}" -ge 1 ]]; then
git ${prefix} status; # Check status
git -C ${prefix} status; # Check status
commit
else
handleArgs
Expand All @@ -150,22 +140,22 @@ commit() {
## Prompt for commit message
read -r -p "Commit message: " message
## Track file deletes
git ${prefix} add -u
git -C ${prefix} add -u

# Committing
git ${prefix} commit -m "$message"
git -C ${prefix} commit -m "$message"
}

#===========================================================================================
#============================== START ================================
#===========================================================================================

### Check if current directory is a git repository
if [[ $(fileExists ".git") == "true" ]];
if [[ $(fe ".git") == "true" ]];
then
handleArgs $@
else
printf "${blue_bold}%s${none}\n" "This Directory is not a Git repository";
errlog "This Directory is not a Git repository";
initRepo $@
fi
### Done
Expand Down
15 changes: 15 additions & 0 deletions bin/fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

#: Title: fe
#: Date: Mon Jun 10 11:33:18 DST 2019
#: Author: [Your name]
#: Version: 1.0.0
#: Description: Short for File Exists. Check if a file (or directory [or path] ) exists [in the current working directory]


if [[ -e "$PWD/$1" ]];
then
echo true;
else
echo false;
fi
24 changes: 4 additions & 20 deletions bin/push
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,15 @@
#: Description: Push command simplified

### Git Prefix specifying the current working directory
prefix="--git-dir=$PWD/.git"


### Text Style and Color formatting
bldred="\033[1;31m"
none="\033[0m"

prefix="$PWD"

#===========================================================================================
#======================== HELPER FUNCTIONS ===========================
#===========================================================================================

### Check if a file (or directory [or path] ) exists [in the current working directory]
fileExists() {
if [[ -e "$PWD/$1" ]];
then
echo true;
else
echo false;
fi
}

### Git Push Command
push() {
git ${prefix} push origin $1
git -C ${prefix} push origin $1
}


Expand All @@ -40,7 +24,7 @@ push() {
#==========================================================================================

### Check if current directory is a git repository
if [[ $(fileExists ".git") == "true" ]];
if [[ $(fe ".git") == "true" ]];
then
if [[ -n $1 ]]; then
push $1; # push to specified branch
Expand All @@ -50,7 +34,7 @@ then
exit 0;
fi
else
printf "${bldred}%s${none}\n" "This Directory is not a Git repository";
errlog "This Directory is not a Git repository";
exit 0;
fi

Expand Down
18 changes: 1 addition & 17 deletions bin/st
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,10 @@
gitDirectoryPath="$PWD"


### Text Style and Color formatting
bldred="\033[1;31m"
none="\033[0m"


#===========================================================================================
#======================== HELPER FUNCTIONS ===========================
#===========================================================================================

### Check if a file (or directory [or path] ) exists [in the current working directory]
fileExists() {
if [[ -e "$PWD/$1" ]];
then
echo true;
else
echo false;
fi
}


status() {
git -C ${gitDirectoryPath} status
}
Expand All @@ -39,7 +23,7 @@ status() {
#==========================================================================================

### Check if current directory is a git repository
if [[ $(fileExists ".git") == "true" ]];
if [[ $(fe ".git") == "true" ]];
then
status;
else
Expand Down

0 comments on commit d56986f

Please sign in to comment.