Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
LeaveAirykson committed Jul 11, 2019
0 parents commit 407b4a7
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_STORE
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# PEPE
A hackable CLI helper tool written in bash.

- [Install](#install)
- [Commands](#commands)
- [Configuration](#configuration)
- [Variables](#variables)
- [Uninstall](#uninstall)

## Install
To install pepe download the latest release here: [Download Pepe](https://github.com/LeaveAirykson/Pepe/archive/master.zip) and unzip the folder in your user home folder. Alternatively you can download it via `curl`.

```bash
# download via curl
curl https://github.com/LeaveAirykson/Pepe/archive/master.zip ~/pepe.zip && unzip pepe.zip

# Go to downloaded pepe folder
cd ~/pepe

# run install script
. install.sh
```
## Commands
Pepe on its own does very little. It actually just executes bash scripts that are located inside the `~/pepe/commands` folder.

If you omit any option to the `pepe` command it will show you some usage information and the available commands.

```bash
# Omit the command name to show more information.
pepe

# Outputted informations
Usage
pepe [COMMAND] [[OPTIONS]...]

Available commands
create-command [NAME]
Helps creating custom commands
```

## Uninstall
The install script will place a symlink inside your `~/bin/` folder. To uninstall the script just remove the symlink and delete the project folder.

```bash
rm ~/bin/pepe
rm -rf ~/pepe
```
49 changes: 49 additions & 0 deletions commands/create-command
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
# @desc Helps creating custom commands.
# @option [NAME]
# shellcheck disable=SC2034,SC2181,SC2154
#
function create-command() {
echo -e "\n${bold}Create custom command${normal}"

if [[ -z "$2" ]] ; then
read -r -p "Name of the command (no whitespace): " COMMANDNAME
else
COMMANDNAME=$2
fi

if [[ -n "$COMMANDNAME" ]] ; then
if [ -f "$COMMANDSPATH/$COMMANDNAME" ]; then
ERROR=true
MESSAGE="A command with this name already exist!"
else

read -r -p "Description: " DESCRIPTION
read -r -p "Options: " OPTIONS

touch "$COMMANDSPATH/$COMMANDNAME"
{
echo "#!/bin/bash"
echo -e "# @desc $DESCRIPTION"

if [[ -n "$OPTIONS" ]]; then
echo -e "# @option $OPTIONS"
fi

echo "function $COMMANDNAME() {"
echo -e "\t# start your logic here"
echo "}"
} >> "$COMMANDSPATH/$COMMANDNAME"

chmod +x "$COMMANDSPATH/$COMMANDNAME"

if [ $? -eq 0 ]; then
MESSAGE="Success in creating $COMMANDSPATH/$COMMANDNAME."

else
ERROR=true
MESSAGE="Error occured while trying to create custom config file."
fi
fi
fi
}
6 changes: 6 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

DIR=$(dirname "${BASH_SOURCE[0]}")
DIR=$(realpath "${DIR}")

ln -s "$DIR/pepe" "$HOME/bin/pepe"
84 changes: 84 additions & 0 deletions pepe
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash
# shellcheck disable=SC1090,SC1091,SC2034
# ==================================
# COLORS
# ==================================
# terminal formats
bold="\033[1m"
red="\033[31m"
green="\033[32m"
yellow="\033[33m"
normal="\033[0m"

# ==================================
# CONFIG
# ==================================
# config path
CONFIGFILE="$HOME/pepe.conf"
PEPEPATH="$(dirname "$(readlink "$0")")"
VHOSTPATH="/usr/local/etc/httpd/vhosts"
SITESPATH="$HOME/Sites"
COMMANDSPATH="$PEPEPATH/commands"
TOPDOMAIN="loc"
ERROR=false
MESSAGE=''

# create a default pepe.conf if it
# does not exist yet
if [ ! -f "$CONFIGFILE" ]; then

# create empty file
touch "$CONFIGFILE"

# add defaults to it
{
echo "VHOSTPATH=\"$VHOSTPATH\""
echo "SITESPATH=\"$SITESPATH\""
echo "TOPDOMAIN=\"$TOPDOMAIN\""
} >> "$CONFIGFILE"
fi

# load our config
source "$CONFIGFILE"

# grep the command and arguments
COMMAND=$1

# ==================================
# HELP
# ==================================
function showhelp() {
echo ""
echo -e "${yellow}Usage${normal}"
echo "pepe [COMMAND] [[OPTIONS]...]"
echo ""
echo -e "${yellow}Available commands${normal}"

for file in "$COMMANDSPATH"/*; do
filename="$(basename "$file")"
descline="$(grep "\@desc" "$file" | head -n1)"
optionline="$(grep "\@option" "$file" | head -n1)"
desc="${descline/\# \@desc /}"
optiondesc="${optionline/\# \@option /}"

echo -e "${bold}$filename${normal} $optiondesc\n$desc\n"
done
}

# ==================================
# COMMAND OPTION
# ==================================

if [ -f "$COMMANDSPATH/$COMMAND" ]; then
source "$COMMANDSPATH/$COMMAND"
$COMMAND "$@"

else
showhelp;
fi

if $ERROR ; then
echo -e "${red}$MESSAGE${normal}"
else
echo -e "${green}$MESSAGE${normal}"
fi

0 comments on commit 407b4a7

Please sign in to comment.