-2

I have a script which takes a UUID as the argument. When I run it manually I can access it using custom tab completion I have written. Is there a way of accessing this completion in a shell script?

~/myscript stop 0011<tab>

It will complete to:

~/myscript stop 0011-1111-1111-1111

Edit: For example:

#!/bin/bash
echo "~/myscript stop \t" | bash -i 

The bash completion is already written. I'm currently executing it in another interactive shell, is there a way of executing this is the same shell?

Luke Exton
  • 3,506
  • 2
  • 19
  • 33
  • 2
    When you are *writing* the script? Maybe, but that would be provided by your editor, not the shell. – chepner Oct 24 '14 at 18:19
  • `id` [command] in the script will do the work for you.. don't take arguments from outside – Ashish Oct 24 '14 at 18:38
  • Are you asking whether you can run `~/myscript stop 0011-1111-1111-1111` and have myscript access the value `0011-1111-1111-1111`? – that other guy Oct 24 '14 at 19:11
  • I'm working a python program which has bash completion enabled. When I access it via the terminal I am able to use the bash completion by starting the argument and pressing tab. However, if I put it into a shell script, I want to be able to access the same tab completion. Currently I'm accessing it by piping it into a new interactive shell. `echo "~/myscript stop 0011\t" | bash -i` – Luke Exton Oct 24 '14 at 21:25
  • @Ashish [UUID](http://en.wikipedia.org/wiki/Universally_unique_identifier) != user ID – PM 2Ring Oct 25 '14 at 10:51
  • It would somehow perhaps be less unnerving if your implementation was in Python and your Bash script would call Python, rather than the other way around. – tripleee Oct 25 '14 at 12:41

1 Answers1

0

I'm not sure why you can't just put the full UUID into your script. But I expect that you can do what you want to do using the bash compgen builtin.

I haven't played with compgen much and I've never used custom tab completion, so I can't give you detailed instructions, but using compgen to generate a list of possible filename completions is easy enough.

Eg, in my home directory,

compgen -f .ba

prints

.bash_history
.bashrc.dpkg-old
.bashrc
.bash_logout
.bashrc~
PM 2Ring
  • 54,345
  • 6
  • 82
  • 182
  • Ahh this is pretty useful, this is the what I was looking for. Wasn't really sure where to start with this one. – Luke Exton Oct 27 '14 at 17:31