howto tab completion

  • Thread starter Michael 'entropie' Trommer
  • Start date
M

Michael 'entropie' Trommer

--6zdv2QT/q3FMhpsV
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hello,

I use [1] to process a string from cmdline-user-input to call methods
form a module namespace. It works for
now, but there are later a lot of commands to input so i want
tab-completion because iam lazy :)

module CmdsBase
CmdsBase.cmd_foo
DoSomething.new
end

...
end

All methods with /^cmd_(\w*)$/ should be completeable from
commandline.

Any ideas to solve this clean?

[1]
# snip:
def self.cmd
begin

line = gets
args, i =[], -1
line.scan(/\w*\s/) do |a|
a.strip!
meth = nil
unless (i+=1).zero? and

MyBiadjCmdlineCaller.methods.include?(a)
break if i.zero?
args.push(a)
else
meth = a
end

unless args.size.zero? # ignoring input with arguments yet
MyBiadjCMDLine.ok?(MyBiadjCmdlineCaller.method(meth).call)
end

end
end while true
end





So long
--
Michael 'entropie' Trommer; http://ackro.org

ruby -e "0.upto((a='njduspAhnbjm/dpn').size-1){|x| a[x]-=1}; p 'mailto:'+a"

--6zdv2QT/q3FMhpsV
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDrP6BBBd8ye5RguQRAuBiAJ49CspQM2fc3IqdrYbCviChm9AzZACgxJPk
VUPKSQ1rU6sg45DphcL2Krs=
=Z+ob
-----END PGP SIGNATURE-----

--6zdv2QT/q3FMhpsV--
 
D

Daniel Calvelo

Have you tried using the Readline module?

require "readline"
$completions = ["cmd_1","cmd_42","cmd_one"]
Readline::completion_proc = Proc.new{ |prefix| $completions if prefix
=~ /cmd_/ }
0.upto(4) { line = Readline::readline( "Cmd? ", true ) }

You get the idea...

Daniel.
 
M

Michael 'entropie' Trommer

--HVCoas+krw6dou6l
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

* Daniel Calvelo ([email protected]) said:
Have you tried using the Readline module?
=20
require "readline"
$completions =3D ["cmd_1","cmd_42","cmd_one"]
Readline::completion_proc =3D Proc.new{ |prefix| $completions if prefix
=3D~ /cmd_/ }
0.upto(4) { line =3D Readline::readline( "Cmd? ", true ) }

thanks a lot, thats what i need!

So long
--
Michael 'entropie' Trommer; http://ackro.org

ruby -e "0.upto((a=3D'njduspAhnbjm/dpn').size-1){|x| a[x]-=3D1}; p 'mailto:=
'+a"

--HVCoas+krw6dou6l
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDsXvdBBd8ye5RguQRAqx4AKCQP91qTs5h4+UO2pDxNTnDCeFrGACePT88
PQKT1MNYLt5QNHohlDWhi6M=
=4oPK
-----END PGP SIGNATURE-----

--HVCoas+krw6dou6l--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

sprintf 2
state pattern? 4
cool way to save big object tree 0
irb selective auto-completion 0
No tab completion if sys.stdout is redirected 3
alarm? 4
ruby command -- bash readline completion 0
FileUtils.cp 4

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top