aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-30 14:59:13 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-30 14:59:13 +1200
commit6ccd74f78e84401212efc11e72ef624c5f201c80 (patch)
tree8a615ea3d4d0a92414790d0e13af8fdac4a849dd
parentRemove fixed completion issue (diff)
downloaddotfiles-6ccd74f78e84401212efc11e72ef624c5f201c80.tar.gz
dotfiles-6ccd74f78e84401212efc11e72ef624c5f201c80.zip
Fix mysql()
-rw-r--r--ISSUES.markdown1
-rw-r--r--README.markdown2
-rw-r--r--sh/shrc.d/mysql.sh18
3 files changed, 13 insertions, 8 deletions
diff --git a/ISSUES.markdown b/ISSUES.markdown
index 4422664e..85d7d26e 100644
--- a/ISSUES.markdown
+++ b/ISSUES.markdown
@@ -23,4 +23,3 @@ Known issues
standard.
Turns out that old versions of Bash in `sh` mode do this too.
-* mysql() is broken due to a logic error, shifting off $1 before using it.
diff --git a/README.markdown b/README.markdown
index 033ced9b..5ec7556a 100644
--- a/README.markdown
+++ b/README.markdown
@@ -185,7 +185,7 @@ in `sh/shrc.d` to be loaded by any POSIX interactive shell. Those include:
through your pager, using color if it can.
* `mkcd()` creates a directory and changes into it.
* `mysql()` allows shortcuts to MySQL configuration files stored in
- `~/.mysql` (presently broken).
+ `~/.mysql`.
* `path()` manages the contents of `PATH` conveniently.
* `pd()` changes to the argument's parent directory.
* `pwgen()` generates just one decent password with `pwgen(1)`.
diff --git a/sh/shrc.d/mysql.sh b/sh/shrc.d/mysql.sh
index d37c3ead..abb496d2 100644
--- a/sh/shrc.d/mysql.sh
+++ b/sh/shrc.d/mysql.sh
@@ -1,5 +1,8 @@
-# If a file ~/.mysql/$1.cnf exists, call mysql(1) using that file. Otherwise
-# just run MySQL with given args. Use restrictive permissions on these files.
+# If a file ~/.mysql/$1.cnf exists, call mysql(1) using that file, discarding
+# the rest of the arguments. Otherwise just run MySQL with given args. Use
+# restrictive permissions on these files. Doesn't allow filenames beginning
+# with hyphens.
+#
# Examples:
#
# [client]
@@ -11,9 +14,12 @@
# database=bar
#
mysql() {
- if [ -f "$HOME/.mysql/$1".cnf ] ; then
- shift
- set -- --defaults-extra-file="$HOME/.mysql/$1".cnf "$@"
- fi
+ case $1 in
+ -*) ;;
+ *)
+ [ -f "$HOME/.mysql/$1".cnf ] &&
+ set -- --defaults-extra-file="$HOME/.mysql/$1".cnf
+ ;;
+ esac
command mysql "$@"
}