<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Linux Forum &mdash; Tee для stdin]]></title>
	<link rel="self" href="https://linuxforum.ru/extern.php?action=feed&amp;tid=20981&amp;type=atom" />
	<updated>2012-03-18T12:33:57Z</updated>
	<generator>PunBB</generator>
	<id>https://linuxforum.ru/viewtopic.php?id=20981</id>
		<entry>
			<title type="html"><![CDATA[Re: Tee для stdin]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=260806#p260806" />
			<content type="html"><![CDATA[<p>так... значит вот что у меня получилось: <br /><strong>~/.vim/plugin/piper.vim</strong><br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>&quot; a vim part a script to stream text from vimto some interpreter

let s:username= $USER
if strlen(s:username)==0
    let s:username= system(&quot;id -un&quot;)[:-2]
endif

if strlen(s:username)==0
    echoerr &quot;Can&#039;t determin your username&quot;
    let g:DefaultPiperDir=&quot;/tmp/piperiser&quot;
else
    let g:DefaultPiperDir=&quot;/tmp/&quot; . s:username . &quot;/piperiser&quot;
endif

let s:mainfile = &quot;&quot;
let b:scriptpipe=&quot;&quot;

nmap &lt;script&gt; &lt;silent&gt; &lt;Plug&gt;PiperSetMainScript :call &lt;SID&gt;ExecuteScript()&lt;CR&gt;
nmap &lt;script&gt; &lt;silent&gt; &lt;Plug&gt;PiperResetMainScript :call &lt;SID&gt;ResetMainScript()&lt;CR&gt;
nmap &lt;script&gt; &lt;silent&gt; &lt;Plug&gt;PiperPipeScript :call &lt;SID&gt;PipeScript()&lt;CR&gt;
vmap &lt;script&gt; &lt;silent&gt; &lt;Plug&gt;PiperPipeScriptSnip :call &lt;SID&gt;PipeScriptSnip()&lt;CR&gt;

function s:SetMainScript()
    let s:mainfile = bufname(&#039;%&#039;)
    echo &#039;Set&#039; . s:mainfile . &#039; as the starting program script for the program.&#039;
endfunction

function s:ResetMainScript()
    echo s:mainfile . &#039; is no longer the starting script.&#039;
    let s:mainfile = &quot;&quot;
endfunction

&quot;function s:PipeMainScript()
&quot; how to write specific file?
&quot;    if strlen(s:mainfile)==0
&quot;        echo &#039;ERROR: no mainfile was seted&#039;
&quot;    else
&quot;        write! b:scriptpipe
&quot;    fi
&quot;endfunction

function s:PipeScript()
    if strlen(b:scriptpipe)==0
        echoerr &quot;You haven&#039;t seted up the output pipe for the buffer.&quot;
    else
        exe &quot;write!&quot; b:scriptpipe
    endif
endfunction

function s:PipeScriptSnip()
    if strlen(b:scriptpipe)==0
        echoerr &quot;You haven&#039;t seted up the output pipe for the buffer.&quot;
    else
        exe a:firstline . &quot;,&quot; . a:lastline . &quot;write!&quot; b:scriptpipe
    endif
endfunction</code></pre></div></div></div><p><strong>~/.vim/tfplugin/python/piper.vim</strong><br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>let b:scriptpipe = DefaultPiperDir . &quot;/python&quot;

&quot; Map keys to special function calls
nmap &lt;F11&gt; &lt;Plug&gt;PiperSetMainScript&lt;CR&gt;
nmap &lt;C-F11&gt; &lt;Plug&gt;PiperResetMainScript&lt;CR&gt;

nmap &lt;C-X&gt; &lt;Plug&gt;PiperPipeScript&lt;CR&gt;
vmap &lt;C-X&gt; &lt;Plug&gt;PiperPipeScriptSnip&lt;CR&gt;</code></pre></div></div></div><p><strong>~/.vim/ftplugin/sql/psql_piper.vim</strong><br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>let b:scriptpipe = DefaultPiperDir . &quot;/psql&quot;

&quot; Map keys to special function calls
nmap &lt;F11&gt; &lt;Plug&gt;PiperSetMainScript&lt;CR&gt;
nmap &lt;C-F11&gt; &lt;Plug&gt;PiperResetMainScript&lt;CR&gt;

nmap &lt;C-X&gt; &lt;Plug&gt;PiperPipeScript&lt;CR&gt;
vmap &lt;C-X&gt;  &lt;Plug&gt;PiperPipeScriptSnip&lt;CR&gt;</code></pre></div></div></div><p><strong>piperise</strong><br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>#!/bin/bash

usage() {
    echo &quot;usage: $0 &lt;program&gt; [parametrs] ...&quot;
}

PIPEDIR=${PIPERISER_PIPEDIR:-&quot;/tmp/${USER:=&quot;$(id -un)&quot;}/piperiser&quot;}
FMASK=&quot;${PAIPERISER_FMASK:-0700}&quot;;
PIPE=${PIPE:-&quot;$PIPEDIR/$1&quot;}
NORMAL_PIPE=&quot;$PIPE&quot;

[ -z &quot;$1&quot; ] &amp;&amp; usage &amp;&amp; exit 100500
mkdir -p &quot;$(dirname &quot;$PIPE&quot;)&quot;

if [ -e &quot;$PIPE&quot; ]; then
    for I in {1..1024}; do
        if [ ! -e &quot;$PIPE.$I&quot; ]; then 
            PIPE=&quot;$PIPE.$I&quot;;
            break;
        fi
    done
    echo &quot;pipe was seted to $PIPE&quot;;    
fi 

mknod $PIPE p || ( echo ERROR! &amp;&amp; exit 100500 )
chmod $FMASK $PIPE

TMP_HELPER_SCRIPT=$(mktemp)

cat &gt;${TMP_HELPER_SCRIPT} &lt;&lt;EOF
#!/usr/bin/python
import sys
from fcntl import ioctl
import termios

while 1:
    f=open(&quot;${PIPE}&quot;)
    txt = f.read()
    for c in txt:
        ioctl(sys.stdout.fileno(), termios.TIOCSTI, c)
    f.close
EOF

python $TMP_HELPER_SCRIPT &amp;
PIPERISER_HELPER=$!

$@ 

rm -f $TMP_HELPER_SCRIPT

kill $PIPERISER_HELPER;
rm -f $PIPE</code></pre></div></div></div><p>чтобы работало интерпретатор надо запускать, как piperise &lt;интерпретатор&gt;<br />фичи: послать на интерпретацию весь буфер или выделить кусок и послать... по &lt;C-X&gt;. пока выделяются только целые строки, как зделать, чтоб можно было оперировать кусками строк - не знаю.</p><p>установка &quot;мейн-скрипта&quot; пока не работает - не знаю. как записать в файл определённый буфер.</p><p>за идею того, как взаимодействовать с интерпретатором спасибо тов. parafin с #gentoo-ru. за помощь с vim-скриптингом спасибо людям на #vim.</p><p>замечания/идеи?</p>]]></content>
			<author>
				<name><![CDATA[Fat-Zer]]></name>
				<uri>https://linuxforum.ru/profile.php?id=11911</uri>
			</author>
			<updated>2012-03-18T12:33:57Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=260806#p260806</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tee для stdin]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=260550#p260550" />
			<content type="html"><![CDATA[<p>c tail идея интересная, но с пайпами он как-то криво работает... хотя надо попинать его ещё... на предмет ввода из двух труб и клячей -fFq, а также дескрипторов.</p><p>пока пытаюсь на питоне сделать... общая идея такая:<br /></p><div class="codebox"><pre><code>#!/usr/bin/python

import threading
import sys

class MyThread(threading.Thread):
    def run(self):
        while 1:
            f=open(&quot;/tmp/pipe&quot;)
            scrpt = f.read()
            sys.stdout.write(scrpt)
            sys.stdout.flush()
            f.close();

thr = MyThread()
thr.start()
while 1:
    s = sys.stdin.read(1)
    sys.stdout.write(s)
    sys.stdout.flush()</code></pre></div><p>только надо как-нить аккуратней завершать...</p>]]></content>
			<author>
				<name><![CDATA[Fat-Zer]]></name>
				<uri>https://linuxforum.ru/profile.php?id=11911</uri>
			</author>
			<updated>2012-03-17T13:39:22Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=260550#p260550</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tee для stdin]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=260531#p260531" />
			<content type="html"><![CDATA[<p>Может что-то наподобие этого:<br /><div class="termtitle" style="font-family: sans-serif; position:relative; height:auto; width:auto; background:#3A4061; color:#FFFFFF; padding: 1px;"><b> Консоль:</b></div>
<div class="termcont" style="font-family: Terminus; position:relative; height:auto; width:auto; overflow-x:scroll; white-space: nowrap ; overflow-y:auto;background:#000000; color:#4EF44E; line-height:1.2; padding: 3px; font-size: 1rem; max-height: 60vh"><br />tail -f file1.txt file2.txt<br /></div></p><p>не, че т это вроде не то</p>]]></content>
			<author>
				<name><![CDATA[unk]]></name>
				<uri>https://linuxforum.ru/profile.php?id=1383</uri>
			</author>
			<updated>2012-03-17T12:41:14Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=260531#p260531</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Tee для stdin]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=259997#p259997" />
			<content type="html"><![CDATA[<p>нужна утилитка, которая сможет брать вход из нескольких мест и выводить всё это в stdout.<br />причём не как cat, последовательно, а как только в одном из входов появилось что-то приятное, то сразу выводить.<br />для чего оно надо: в одном терминале запущен (g)vim, во втором - интерпретатор, можно вводить команды в интерпретатор вручную, а можно выделять текст в вим и посылать в интерпретатор (через трубу например).</p>]]></content>
			<author>
				<name><![CDATA[Fat-Zer]]></name>
				<uri>https://linuxforum.ru/profile.php?id=11911</uri>
			</author>
			<updated>2012-03-15T16:58:27Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=259997#p259997</id>
		</entry>
</feed>
