The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to launch a Csh shell script using Excel Macro ? Raynon Shell Programming and Scripting 1 11-08-2006 08:22 AM
Return value (int) from main to calling shell flounder High Level Programming 3 09-25-2006 07:14 PM
Shell script to catch PL/SQL return values Veera_Raghav Shell Programming and Scripting 0 06-26-2006 02:16 PM
return variable from PL/SQL procedure to shell ap_gore79 Shell Programming and Scripting 4 06-03-2004 01:49 PM
macro on shell script ? inquirer UNIX for Dummies Questions & Answers 4 08-15-2001 07:31 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-04-2008
Registered User
 

Join Date: Jul 2008
Location: UK
Posts: 2
Return shell value to a VI macro

Hi,

Have searched around for a solution to this and get frustrating close but have not nailed it.

vi on HP-UX

what I'm trying to do is utilise the key mapping available within Vi to run a shell script which uses awk script to scan the file i'm working on and return the line number or unique pattern (could go either way but the principle im trying to achieve is pass a value back so that vi macro can then utilise it)

The closest ive got via Google is

The most powerful macros, however, are created using programs combined
into shell scripts (or DOS batch files), and acting as filters on the text
sent to them from within vi. Such shell scripts or programs must take standard
input and send results to standard output (which most UNIX tools do).

but guess what no example! I've tried more in hope than expectation to set a map command as follows:

map ^[[O ^[: !line_test^M

where line_test is hard coded to echo out a line number which then can but as expected all it does is echo out the line number and is not interpreted as the line number I wanted to go to.

I subsequently modified the script to exit with a value and then tried to use $?

map ^[[O :!line_test : ^[: $?^M

but get error badly formatted address

any help greatly appreciated.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-07-2008
Registered User
 

Join Date: Jul 2008
Location: UK
Posts: 2
found it (sort of)

Despite the absence of any reply (not sure if this question was in the wrong place or just didn't interest anybody!) i have found an answer which i will post as I know from past experience that nothing is more frustrating than trawling the Net for something find it and then found its not been followed up.

I managed to achieve my goal by having the external shell script write out the value to a file in /tmp, the macro then read in the file to the current file , deleted the line and assigned it to buffer 'a' and then using the @ notation to pass to the : (go to line) command.

map ^[[O :!goto_func %^M :r /tmp/goto.mac^M "add:@a^M : !rm -f /tmp/goto.mac^M

still a bit cludgy as edits the existing file, (im thinking is there a way of reading directly into the buffer?) if anyone has a more elegant solution then please post it here.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0