Using python with argument in TCSH autocompletion


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using python with argument in TCSH autocompletion
# 1  
Old 08-17-2016
Linux Using python with argument in TCSH autocompletion

Hi,

I'm using a complete command in tcsh this way, the echo cmd is just for the example :

Code:
complete echo 'p/1/`mypythonalias`/'

And that works just great returning what the python script is printing out.

However I want to give an argument to the python script to narrow down its results and here comes the problem. I tried many things I found on Internet :

Code:
complete echo 'p/1/`mypythonalias $1`/'
complete echo 'p/1/`mypythonalias \{print\ \$1\}`/'
complete echo 'p/1/`mypythonalias '"'"'{print\ \$1\}'"'"'`/'

And other examples using more backslashes but returning errors.

In any case, print $1 was never evaluated, this page on tcsh.org seems to say that it should be possible though :
tcsh.html/Builtin_commands.html#complete

But I couldn't get the example to work properly somehow.

Any help would be really appreciated Smilie

Thanks !
Chris
# 2  
Old 08-22-2016
Linux

Little bump on that one, it would be really nice to get some help :-/

Thanks
Chris

Last edited by chistof; 08-22-2016 at 10:51 PM..
# 3  
Old 08-23-2016
Moderator's Comments:
Mod Comment Bumping up posts is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully.

You'll get a lot more help in this forum when dealing with shells that follow Bourne shell syntax than with shells that use csh style shell syntax. In Bourne shell syntax, command substitutions and positional variables are processed when they appear in a double-quoted string, but are not expanded when they appear inside a single-quoted string. I do not use csh or tcsh, but you might try:
Code:
complete echo "p/1/`mypythonalias $1`/"

instead of:
Code:
complete echo 'p/1/`mypythonalias $1`/'

# 4  
Old 08-25-2016
Hi Don,

sorry for the bump, it's the first time I see it being a bother on a forum Smilie

Thanks for your help, sadly the double quote didn't fix my issue. I'll try other ideas Smilie

Thanks again !
Chris
# 5  
Old 08-26-2016
I don't think you can pass arguments to your perl script like that.

From what I can see the environment variable $COMMAND_LINE should contain the fully typed command line which should be exported to your script.

So if you typed echo one two[^D] at the tcsh prompt, you would get "echo one two" in the COMMAND_LINE env variable available to your script.
# 6  
Old 09-05-2016
Thx Chubler !

I couldn't exactly make it work with what you wrote but the $COMMAND_LINE put me on the right track and helped my research a lot and I found something which worked great !

Code:
complete echo 'p/1/`set cmd = ( $COMMAND_LINE ); mypythonalias $cmd[$#cmd]`/'

Thanks again for your help guys !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python : Problem with " TypeError: float() argument must be a string or a number "

Hello ! I'm creating a CGI which allow to display graph from some data. The datas looks like : 2020-01-13-00-00,384.00,350.00 2020-01-13-06-00,384.00,350.00 2020-01-13-12-00,384.00,350.00 2020-01-13-18-00,384.00,350.00 2020-01-14-00-00,384.00,350.00... (1 Reply)
Discussion started by: Tim2424
1 Replies

2. Programming

Python script to grep fields and use values from file 1 as argument for another command

Hi Experts, I am working one one python script in version 3.x and 2.6. Need your support to complete it Basically for both commands i have telnet to device and run command and then receiving input File 1 and File 2 I have two commands, need to grep data and output in csv file. Next script/code... (0 Replies)
Discussion started by: as7951
0 Replies

3. Programming

Python passing filename through argument

Hello, A python beginner question on passing filename thru argument. My code is: #!/usr/bin/python import sys, getopt import os def main(argv): try: opts, args = getopt.getopt(sys.argv,"hi:o:ce", ) except getopt.GetoptError: usage() print("Usage: %s... (6 Replies)
Discussion started by: yifangt
6 Replies

4. Shell Programming and Scripting

**python : passing list as argument and updating in definition

In the below python code.. Could anyone please let me know why the name(variable) is getting modified if I update the kargs variable in the definition, def f( kargs): kargs.extend() print ("In function :",kargs) name = f(name) print("Outside function :",name) Output ... (5 Replies)
Discussion started by: scriptscript
5 Replies

5. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with -

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

6. Shell Programming and Scripting

white spaces in bash autocompletion

Hello dear community! I've recently written a BASH function for auto completion of options. It works like following: if a user types a command and then an argument to this command which starts with "^-" and then presses TAB, then 'user_command --help (or -h)' is invoked and possible options are... (0 Replies)
Discussion started by: sidorenko
0 Replies

7. UNIX for Dummies Questions & Answers

Unable to get autocompletion on !

Hi, Previously, if I type !cp <tab> the last cp command would come automatically. However, something has changed recently with my system. I am unable to get a autocomplete !cp <tab> now. Where can I look for the changes ? Any idea what might have caused it ? (1 Reply)
Discussion started by: coolket
1 Replies

8. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies

9. AIX

korn prompt autocompletion possible ?

My client`s system is an AIX 4.2 and using the Kron shell. I was just wondering if it is possible to have the prompt autocompletion enabled on it without changing shell version. By autocompletion, I mean to automatically complete the filenames or directories we type in using the Tab key. (2 Replies)
Discussion started by: Browser_ice
2 Replies

10. UNIX for Dummies Questions & Answers

Path autocompletion in ksh

Say, I want to move into dir library from current dir, on prompt if I type in cd li if it is followed by pressing 'Tab' key then complete dir name appears. Would there anyone know, how we can make into effect this path autocompletion? I am using 'ksh'. (5 Replies)
Discussion started by: videsh77
5 Replies
Login or Register to Ask a Question

Featured Tech Videos