Skip to content

Instantly share code, notes, and snippets.

@pzskc383
Last active December 19, 2015 21:29
Show Gist options
  • Save pzskc383/6020599 to your computer and use it in GitHub Desktop.
Save pzskc383/6020599 to your computer and use it in GitHub Desktop.
#!/bin/sh
[[ $# > 2 || $# < 1 ]] && exit 1;
[[! hash pass 2>&-]] && exit 2
IFS=$'\n' data=($(pass work/sql-$1))
cmd=" -p'${data[0]}'"
for (( i=1; i<${#data[@]}; i++ )); do
IFS=': ' read -r k v <<< ${data[i]}
case $k in
user|username)
cmd+=" -u $v"
;;
host|hostname)
cmd+=" -h $v"
;;
dbname|database|db)
cmd+=" $v"
;;
esac
done
if [ $# = 2 ] && [ $2 = 'dump' ]; then
fn=~/tmp/$1-$(date +'%y-%m-%d').sql
cmd="mysqldump -C $cmd > $fn"
echo dumping to $fn
else
cmd="mysql -C $cmd"
fi
eval $cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment