diff --git a/bin/commit b/bin/commit index 441e9d5..03d4d89 100644 --- a/bin/commit +++ b/bin/commit @@ -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" @@ -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 @@ -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 } @@ -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 @@ -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 @@ -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 @@ -150,10 +140,10 @@ 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" } #=========================================================================================== @@ -161,11 +151,11 @@ commit() { #=========================================================================================== ### 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 diff --git a/bin/fe b/bin/fe new file mode 100644 index 0000000..9569b72 --- /dev/null +++ b/bin/fe @@ -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 diff --git a/bin/push b/bin/push index b0bcd77..4b787ba 100644 --- a/bin/push +++ b/bin/push @@ -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 } @@ -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 @@ -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 diff --git a/bin/st b/bin/st index 40e9375..7166290 100644 --- a/bin/st +++ b/bin/st @@ -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 } @@ -39,7 +23,7 @@ status() { #========================================================================================== ### Check if current directory is a git repository -if [[ $(fileExists ".git") == "true" ]]; +if [[ $(fe ".git") == "true" ]]; then status; else