diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2018-04-05 13:19:10 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2018-04-05 13:19:10 +0200 |
commit | 76eb86e2e45bb111c8a6215e13892e292d5ab3c4 (patch) | |
tree | a47b2bd9c483f71ae6f855f81da7a23c9c8a4a9a | |
parent | .gitconfig: add alias.fixup (diff) | |
download | linux-home-76eb86e2e45bb111c8a6215e13892e292d5ab3c4.tar.gz linux-home-76eb86e2e45bb111c8a6215e13892e292d5ab3c4.zip |
add mysql.sh
Diffstat (limited to '')
-rw-r--r-- | %HOME%/.bash_utils/mysql.sh | 41 | ||||
-rw-r--r-- | %HOME%/.bashrc | 1 |
2 files changed, 42 insertions, 0 deletions
diff --git a/%HOME%/.bash_utils/mysql.sh b/%HOME%/.bash_utils/mysql.sh new file mode 100644 index 0000000..e5a02fe --- /dev/null +++ b/%HOME%/.bash_utils/mysql.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Copyright (c) 2018 Egor Tensin <Egor.Tensin@gmail.com> +# This file is part of the "Linux/Cygwin environment" project. +# For details, see https://github.com/egor-tensin/linux-home. +# Distributed under the MIT License. + +_runsql_check_var() ( + set -o errexit -o nounset -o pipefail + + local prefix="${FUNCNAME[0]}" + [ "${#FUNCNAME[@]}" -gt 1 ] && prefix="${FUNCNAME[1]}" + + local var_name + for var_name; do + if [ -z "${!var_name:+x}" ]; then + echo "$prefix: $var_name is not set" >&2 + return 1 + fi + done +) + +runsql() ( + set -o errexit -o nounset -o pipefail + + _runsql_check_var MYSQL_USER MYSQL_PASSWORD MYSQL_HOST + local MYSQL_PORT="${MYSQL_PORT:-3306}" + + local -a statement_list + local stmt + for stmt; do + statement_list+=(-e "$stmt") + done + + mysql \ + --user="$MYSQL_USER" \ + --password="$MYSQL_PASSWORD" \ + --host="$MYSQL_HOST" \ + --port="$MYSQL_PORT" \ + "${statement_list[@]}" +) diff --git a/%HOME%/.bashrc b/%HOME%/.bashrc index 0eb29a5..71f7172 100644 --- a/%HOME%/.bashrc +++ b/%HOME%/.bashrc @@ -52,6 +52,7 @@ alias copy='xclip -sel clip' [ -r "$HOME/.bash_utils/os.sh" ] && source "$HOME/.bash_utils/os.sh" [ -r "$HOME/.bash_utils/path.sh" ] && source "$HOME/.bash_utils/path.sh" +[ -r "$HOME/.bash_utils/mysql.sh" ] && source "$HOME/.bash_utils/mysql.sh" [ -r "$HOME/.bash_utils/python.sh" ] && source "$HOME/.bash_utils/python.sh" [ -r "$HOME/.bash_utils/ruby.sh" ] && source "$HOME/.bash_utils/ruby.sh" |