LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 12-29-2012, 03:46 AM   #1
Leo Simon
LQ Newbie
 
Registered: Aug 2004
Posts: 21

Rep: Reputation: 0
Filename completion in a specific directory for a specific command using tcsh


Hi

I'm calling a simple bash script, called Help, from a tcsh shell. For example

Help tcsh simply cats the file ~/help/tcsh.help

If I'm in the directory ~/help, sentence completion works fine, but if I'm any any other directory, of course it doesn't. Is there some analog for tcsh of bash_completion.d that would allow me to get the same completion functionality that I could get if I were using a bash shall?

For example, I'd like to be able to type Help tcs<TAB> and have it complete to
Help tcsh.help

Thanks for any suggestions!
 
Old 12-29-2012, 09:07 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,488

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
Yes. Take a look at the complete built-in. If I understand well, you have a command (script) called Help somewhere in your PATH and you want to apply TAB completion to the first argument. The first argument will be the name of a .help file inside the $HOME/help directory, right? Here we go:
Code:
complete Help "p/1/(list)/"
this tells the shell to apply TAB completion to the first argument of the command Help and use the words in list. At this point you have to build the list of words by means of a command that lists all the .help files in the desired location. Example:
Code:
complete Help "p/1/(`cd $HOME/help && echo *.help`)/"
Suppose you want to remove the .help suffix, you can enhance the command at your pleasure, for example:
Code:
complete Help "p/1/(`cd $HOME/help && echo *.help | sed s/.help//g`)/"
Now put this line in a file that is sourced at login (e.g. $HOME/.tcshrc) and the trick is done. Hopefully!
 
Old 12-29-2012, 10:21 AM   #3
Leo Simon
LQ Newbie
 
Registered: Aug 2004
Posts: 21

Original Poster
Rep: Reputation: 0
Magic! Works beautifully, thanks very much indeed!

Well, that completion worked but the next one didn't. Here's a simple version of it.

Quote:
echo "horse \n dog \n bear " > animals
Then in my .cshrc file

Quote:
complete foo "p/1/(echo `cat $HOME/animals`)/"
which looks like the same idea structurally as the last example. But when I type

Quote:
foo ho<TAB>
I get the error

Quote:
Missing separator '/' after completion "(echo horse
which from the web seems to have cropped up in past years. Could you advise please?[

Last edited by Leo Simon; 12-29-2012 at 06:11 PM. Reason: Duplicated the problem in a slightly different context
 
Old 12-29-2012, 10:44 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,488

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
You're welcome!
 
  


Reply

Tags
command, directory, filename expansion, tcsh


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Not able to change to a specific directory using one command- CD slackkid Linux - Newbie 3 12-24-2012 12:25 AM
How to delete all files with specific word in filename? moviecarpet Programming 13 05-26-2011 08:44 AM
How to make a specific command(s) work for specific users or group only naren_0101bits Linux - General 3 08-28-2005 05:22 PM
How to make a specific command(s) work in a specific shell only naren_0101bits Linux - Newbie 3 08-28-2005 01:24 PM
Searching a specific directory for a specific extension? RoaCh Of DisCor Linux - Newbie 3 08-13-2005 03:28 PM


All times are GMT -5. The time now is 12:16 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration