-
-
Save lirsacc/1906f19c69fee881efea to your computer and use it in GitHub Desktop.
ZSH database connection shortcuts
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
#compdef db | |
local -a dbs | |
dbs=$(ls $HOME/.dbs) | |
_alternative "files:dbs:($dbs)" |
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
database=db_name | |
username=username | |
host=127.0.0.1 | |
password=pass | |
port=3306 |
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
# ZSH function to quickly connect to known databases (with completion) | |
# | |
# `db connection.file [d] [arguments]` | |
# | |
# Store connection files in $HOME/.dbs (see database.credential for an example) | |
# By default uses the `mycli` client (http://mycli.net/), add `d` at the end to use | |
# standard `mysql`. All arguments are forwarded. | |
function db () { | |
if [ ! -f $HOME/.dbs/$1 ]; then | |
available_databases=$(ls $HOME/.dbs) | |
echo "No available db $1, choose from:" | |
echo $available_databases | |
return 1 | |
fi | |
. $HOME/.dbs/$1 | |
shift | |
[[ $1 == "d" ]] && cmd="mysql" && shift || cmd="mycli" | |
$cmd -h $host -P $port -u $username --password=$password $@ $database | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment