Skip to content

Commit ab98a65

Browse files
authored
* chore: add a man page * refactor: Use regex instead of manual verification
1 parent a920448 commit ab98a65

File tree

5 files changed

+75
-8
lines changed

5 files changed

+75
-8
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.vscode/*
2+
git-2.*/*
3+
.editorconfig
4+
build/*
5+
test*

commit

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
# Make the credentials available at the start of the script
44

5-
username=$(grep -oP '^user_email:\s*\K.*' ~/.commitconfig)
6-
email=$(grep -oP '^user_username:\s*\K.*' ~/.commitconfig)
5+
y_regex="^([y|Y][eE][sS]|[y|Y])$"
6+
7+
email=$(grep -oP '^user_email:\s*\K.*' ~/.commitconfig)
8+
username=$(grep -oP '^user_username:\s*\K.*' ~/.commitconfig)
79

810
# Check if the --help flag is used
911
if [[ "$*" == *"--help"* ]]; then
@@ -28,7 +30,7 @@ fi
2830
# Check if the current directory is a Git repository
2931
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
3032
read -rp "The current directory is not a Git repository. Would you like to initialize it? (y/n): " initialize
31-
if [[ "$initialize" == "y" || "$initialize" == "Y" ]]; then
33+
if [[ "$initialize" =~ $y_regex ]]; then
3234
git init
3335
else
3436
echo "Script terminated. Please initialize a Git repository to continue."

commit.1

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.TH "COMMIT ASSISTANT" 1 "2023-06-18" GNU "Commit Manual"
2+
.SH NAME
3+
commit assistant \- effortlessly commit
4+
.SH SYNOPSIS
5+
.B commit
6+
.RB [ \-\-verbose ]
7+
.RB [ filename... ]
8+
.SH DESCRIPTION
9+
.B commit
10+
is a tool that helps you commit without having to remember any of the git commands.
11+
.br
12+
It intelligently chooses the correct
13+
.IR "git command"
14+
to use for your current situation.
15+
.br
16+
.B commit
17+
uses the git commands under the hood to perform it's tasks.
18+
.br
19+
.SH OPTIONS
20+
.TP 8
21+
.B \-\-verbose
22+
Prints out the steps that the program is taking.
23+
This is useful incase the process failed for whatever reason.
24+
.TP 8
25+
.B file(s)
26+
State explicitly which files should be committed.
27+
If nothing is given, all the files in the current directory are committed.
28+
.SH EXAMPLE
29+
.TP 4
30+
.B commit --verbose
31+
.br
32+
Runs the program in verbose mode.
33+
.TP 4
34+
.B commit file1 file2
35+
.br
36+
Commit certain files.
37+
.B commit
38+
takes 0 or more values. If zero, then all the files are selected.
39+
.SH FILES
40+
.IR /usr/local
41+
.br
42+
.IR ~/.commitconfig
43+
.SH SEE ALSO
44+
.BR git(1)
45+
.SH BUGS
46+
When run in root it may have undefined behaviours
47+
.br
48+
No support for any advanced or intermediate git commands
49+
.br
50+
If you find any problem, want to add or a feature added.
51+
.br
52+
Consider checking out the official Github repository
53+
https://github.com/ALX-Students-Contribution/commit-assistant

git-install.sh

100755100644
File mode changed.

install.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -e
4+
y_regex="^([y|Y][eE][sS]|[y|Y])$"
45

56
# Copy commit.sh to the bin directory
67
if ! sudo cp commit /usr/local/bin/; then
78
echo "Error: Failed to copy commit script to /usr/local/bin/"
89
exit 1
910
fi
1011

12+
# Copy commit manual to man directory
13+
# Installation should not stop incase it fails, only a warning
14+
if ! sudo cp commit.1 /usr/local/man/man1; then
15+
echo "Failed to add commit man page to system"
16+
fi
17+
1118
# Check if git is installed in the system
1219

1320
if ! command -v git > /dev/null 2>&1; then
1421
echo -e "Git is not installed in your system \n Do you want to install it? (y/n): "
1522

1623
read -r git_choice
1724

18-
if [[ $git_choice == 'y' || $git_choice == 'Y' ]]; then
25+
if [[ $git_choice =~ $y_regex ]]; then
1926
echo "This process may take *alot* of time, please be patient and make sure you have stable internet connection"
2027
chmod +x git_install.sh
2128
./git_install.sh
@@ -28,13 +35,13 @@ fi
2835
# Create a validation regex that will be used to validate if the email is correct or not
2936
# This only checks for the syntax and not deliverability
3037

31-
regex="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
38+
email_regex="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
3239

3340
# Ask if the user will like to enter other details or will like to continue with the system configuration
3441

3542
read -rp "Do you want to enter your details(y/n): " detail_choice
3643

37-
if [[ $detail_choice == 'y' || $detail_choice == 'Y' ]]; then
44+
if [[ $detail_choice =~ $y_regex ]]; then
3845
# Prompt for Git username
3946
read -rp "Enter Git username: " username
4047

@@ -54,7 +61,7 @@ if [[ $detail_choice == 'y' || $detail_choice == 'Y' ]]; then
5461
fi
5562

5663
# Validate the email is correct
57-
if [[ ! $email =~ $regex ]]; then
64+
if [[ ! $email =~ $email_regex ]]; then
5865
echo "Error: Your email is invalid"
5966
exit 1
6067
fi

0 commit comments

Comments
 (0)