Skip to content

Commit

Permalink
simplify structure to prepare for homebrew etc
Browse files Browse the repository at this point in the history
  • Loading branch information
crumb1e committed Sep 18, 2020
1 parent d6ab1f6 commit 8c514c3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
err.log
out.log
mys.log
*.sql
.DS_Store
17 changes: 0 additions & 17 deletions commands/mys_cpdb

This file was deleted.

16 changes: 0 additions & 16 deletions commands/mys_ddb

This file was deleted.

16 changes: 0 additions & 16 deletions commands/mys_mkdb

This file was deleted.

58 changes: 54 additions & 4 deletions mys
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# -----
# if this is your first time here, please run `mys -h` for more info.

version=0.1.1
version=0.1.2

main() {
CFG=~/.config/mys.conf
Expand Down Expand Up @@ -34,22 +34,72 @@ main() {
;;
"mkdb")
printf -- "\e[1;32mCreating a fresh db with name: \e[42;90m ${args[1]} \e[0m\n"
. ./commands/mys_mkdb ${args[1]}
mkdb ${args[1]}
;;
"ddb")
printf -- "\e[1;32mDropping ${args[1]}\e[0m\n"
. ./commands/mys_ddb ${args[1]}
ddb ${args[1]}
;;
"cpdb")
printf -- "\e[1;32mCopying ${args[1]} into ${args[2]}\e[0m\n"
. ./commands/mys_cpdb ${args[1]} ${args[2]}
cpdb ${args[1]} ${args[2]}
;;
*)
printf -- "\e[91mSorry, mys doesn't recognise that command. (${args[0]})\n"
;;
esac
}

# functions
initconfig() {
. ~/.config/mys.conf
}

mkdb() {
initconfig

db=$1

mysql -u ${MYS_NAME} --password=${MYS_PASS} -e "create database ${db};" > mys.log 2>&1

if [ $? -eq 0 ]; then
printf -- "\e[32mSuccessfully created ${db}!\e[39m\n"
else
printf -- "\e[31mOops! Something wasn't right, please check the mys.log\e[39m"
fi
}

ddb() {
initconfig

db=$1

mysql -u ${MYS_NAME} --password=${MYS_PASS} -e "drop database ${db};" > mys.log 2>&1

if [ $? -eq 0 ]; then
printf -- "\e[32mSuccessfully dropped ${db}!\e[39m\n"
else
printf -- "\e[31mOops! Something wasn't right, please check the mys.log\e[39m"
fi
}

cpdb() {
initconfig

file=$1
db=$2

mysql -u ${MYS_NAME} --password=${MYS_PASS} ${db} < ${file} > mys.log 2>&1

if [ $? -eq 0 ]; then
printf -- "\e[32mSuccessfully copied ${file} into ${db}!\e[39m\n"
else
printf -- "\e[31mOops! Something wasn't right, please check the mys.log\e[39m"
fi
}

# endfunction

# Check if a config file exists
configexists() {
if [ ! -e ~/.config/mys.conf ]
Expand Down

0 comments on commit 8c514c3

Please sign in to comment.