Last active
April 28, 2016 09:46
-
-
Save akalongman/e31f4db9dc6ae62ff79f285cb65bbf1e to your computer and use it in GitHub Desktop.
Tasker - Bash alias runner for fast development
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
#!/usr/bin/env bash | |
# Avtandil Kikabidze aka LONGMAN <[email protected]> | |
PATH=$PATH:./node_modules/.bin | |
VERSION="1.1" | |
COLOR_RED=`tput setaf 1` | |
COLOR_GREEN=`tput setaf 2` | |
COLOR_BROWN=`tput setaf 3` | |
COLOR_RESET=`tput sgr0` | |
declare -A CMD_ALIAS | |
declare -A CMD_DESC | |
# Commands | |
CMD_ALIAS["watch"]="gulp watch" | |
CMD_DESC["watch"]="Run gulp in watch mode" | |
CMD_ALIAS["build"]="gulp" | |
CMD_DESC["build"]="Run gulp" | |
CMD_ALIAS["clear"]="php artisan clear" | |
CMD_DESC["clear"]="Run gulp in watch mode" | |
CMD_ALIAS["redisclear"]="redis-cli FLUSHALL" | |
CMD_DESC["redisclear"]="Clear redis cache if php artisan stopped working" | |
CMD_ALIAS["phpunit"]="./vendor/bin/phpunit" | |
CMD_DESC["phpunit"]="Run PHP tests" | |
CMD_ALIAS["phpcs"]="./vendor/bin/phpcs --standard=phpcs.xml -spn --encoding=utf-8 app/ --report-width=150" | |
CMD_DESC["phpcs"]="Check PHP Coding style" | |
CMD_ALIAS["phpcbf"]="./vendor/bin/phpcbf --standard=phpcs.xml -spn --encoding=utf-8 app/ --report-width=150" | |
CMD_DESC["phpcbf"]="Fix PHP Coding style" | |
if [[ $1 ]]; then | |
if [ ${CMD_ALIAS[$1]+abc} ]; then | |
COMMAND=${CMD_ALIAS[$1]} | |
eval "${COMMAND} ${@:2}" | |
else | |
echo "${COLOR_RED}Command $1 not found!${COLOR_RESET}" | |
fi | |
else | |
echo "${COLOR_GREEN}Tasker ${COLOR_RESET}version ${COLOR_BROWN}${VERSION}${COLOR_RESET} - Bash alias runner | |
${COLOR_BROWN}Usage:${COLOR_RESET} | |
./tasker command [arguments] | |
${COLOR_BROWN}Available commands:${COLOR_RESET}" | |
for index in "${!CMD_ALIAS[@]}" | |
do | |
size=${#index} | |
size2=`expr 30 - $size` | |
spaces=`eval "printf ' %.0s' {1..$size2}"` | |
if [ ${CMD_DESC[$index]+abc} ]; then | |
DESCRIPTION=${CMD_DESC[$index]} | |
echo " ${COLOR_GREEN}$index$spaces${COLOR_RESET}${DESCRIPTION}" | |
else | |
echo " ${COLOR_GREEN}$index${COLOR_RESET}" | |
fi | |
done | tac | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment