2020-10-31 01:34:23 +08:00
|
|
|
function __fish_mysql_query -a query
|
2024-01-22 14:42:45 +08:00
|
|
|
argparse -i 'u/user=' 'P/port=' 'h/host=' 'p/password=?' 'S/socket=' -- (commandline -px)
|
2020-10-31 01:34:23 +08:00
|
|
|
set -l mysql_cmd mysql
|
|
|
|
for flag in u P h S
|
|
|
|
if set -q _flag_$flag
|
|
|
|
set -l flagvar _flag_$flag
|
|
|
|
set -a mysql_cmd -$flag $$flagvar
|
|
|
|
end
|
|
|
|
end
|
2021-11-23 21:45:28 +08:00
|
|
|
if test -n "$_flag_p"
|
2020-10-31 01:34:23 +08:00
|
|
|
set -a mysql_cmd -p$_flag_p
|
|
|
|
end
|
|
|
|
echo $query | $mysql_cmd 2>/dev/null
|
|
|
|
end
|
|
|
|
|
|
|
|
function __fish_complete_mysql_databases
|
|
|
|
__fish_mysql_query 'show databases'
|
|
|
|
end
|
|
|
|
|
|
|
|
function __fish_complete_mysql
|
|
|
|
set -l command $argv[1]
|
|
|
|
|
|
|
|
complete -c $command -s D -l database -x -d 'The database to use' -a '(__fish_complete_mysql_databases)'
|
|
|
|
complete -c $command -a '(__fish_complete_mysql_databases)'
|
|
|
|
end
|