From 1b79a1dc72e703d975effa2de806c9afd9dbaa81 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Apr 2017 00:23:22 +0200 Subject: Try to add support for shell aliases through Ruby's `Kernel.exec` Work in progress. Ruby's `system` and `exec` don't load shell aliases, so the executables defined in `EXECUTABLE_NAME` will always be the ones used to launch database shells. The trouble is, users might have installed the command with a different name (as in "mysql5"), or they might not have the command on their path (as in my case when using Postgres.app). Apparently you can use an interactive or login shell to get aliases (using the `-l` or `-i` flags, which do slightly different things, sourcing .profile and .bashrc separately). Here's what I was following: http://stackoverflow.com/questions/12060863/python-subprocess-call-a-bash-alias/25099813#25099813 Unfortunately I haven't been able to get it to work. Dropping this for now. --- lib/dbshell/exec_alias.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 lib/dbshell/exec_alias.rb (limited to 'lib/dbshell/exec_alias.rb') diff --git a/lib/dbshell/exec_alias.rb b/lib/dbshell/exec_alias.rb new file mode 100644 index 0000000..7bd86b7 --- /dev/null +++ b/lib/dbshell/exec_alias.rb @@ -0,0 +1,11 @@ +module DBShell + class ExecAlias + def self.exec(command_args) + Kernel.exec(*self.build_command(command_args)) + end + + def self.build_command(command_args) + [ENV['SHELL'], '--login', '-c', command_args.join(' ')] + end + end +end -- cgit v1.2.3