Re: Feature : walkthrough lines of stdout

2015-06-19 Thread Raphaël Droz
Just to mention that for urxvt a perl plugin was already posted some
times ago¹. The sad thing is that it has no clue about the semantic of
the last line.
For example you may not want to paste the last line if it's the
prompt. Neither you have the context of the output (the last command
entered).

I think that readline could be a good layer for that since it can easily
guess what was the entered and validated command and I guess that it
knows where the output ends and where the prompt and other things are..
(actually only the bash process parses the line and can consistently
say that in ...
$ x=y ls foo
... the actual command is ls)
And the main uses of grabbing the last line come if we know what was the
command they come from (see the regexp in the attachment...)

The missing bit is probably a link between readline lines (and states)
and the terminal. The later could then provide
API/configuration/key-bindings to reuse the last
line-of-output-really-being-the-output-of-a-command.

Anyway I have no clue about the means by which, if possible, the
terminal could interact with readline or vice versa.


¹ http://lists.schmorp.de/pipermail/rxvt-unicode/2011q4/001494.html
  Enhanced version attached

On Wed, Jun 17, 2015 at 04:05:56AM -0700, Hrazel wrote:
 Now it would be nice just to log the last lines on stdout and walk it
 through line by line ready to be put to the clipboard.

This is a bit different since here you're intending to *walk* along the
(multiple) previous lines, not only splitting the last one.
Still in the urxvt case, you may want to take inspiration from the
url-select extension while assuming a set of word boundary characters.
#! perl

# Author:   Raphaël Droz
# Website:  http://gitorious.org/~drzraf
# Version:  0.1
# License:  GPLv2

# TODO
# use Term::ReadLine::Gnu;
use POSIX ();

sub on_user_command {
my ($self, $cmd) = @_;

if ($cmd eq yank-return:true) {
my ($row, $col) = $self-screen_cur;
my $line = $self-ROW_t ($row - 1);

# TODO: if (readline-previous-command-was-grep)
#   and no newline
#   and last line was not the prompt

# bash: xxx command not found
if ($line =~ /^bash:\s/) {
$line =~ s/^bash:\s(.*?):\scommand not found\s*/$1/;
$self-tt_write($line);
}

# ls -l (before grep because hours contain :)
elsif ($line =~ /^[ldp-][r-][w-][x-][r-][w-][x-][r-][w-][tx-]\s+/) {
# $line =~ 
s/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+\S+\s+(.*?)\s+$/$1/;
# (in ls -l), these two \d\d may be
# the minutes or the two last digits of the year
$line =~ s/^.*\d\d\s(.*?)\s+$/$1/;
$self-tt_write($line);
}

# unzip
elsif ($line =~ /^\s+inflating:/) {
$line =~ s/^\s+inflating:\s+(.*?)\s+/$1/;
$self-tt_write($line);
}

# dpkg -l
elsif ($line =~ /^(ii|hi|rc)\s+/) {
$line =~ s/^(ii|hi|rc)\s+(.*?)\s+.*/$1/;
$self-tt_write($line);
}

elsif ($line =~ /:/) {
my $login = getlogin;
# prompt: return prev path
if($line =~ /^$login@.*\$\s+$/) {
$line =~ s/^.*?:(.*?)\s[\$#].*$/$1/;
$self-tt_write($line);
}

# grep
else {
# TODO: custom regexp
$line =~ s/^([^:\s]+):.*$/$1/;
$self-tt_write($line);
}
}

# wget
elsif ($line =~ /^\s+$/) {
my $pline = $self-ROW_t ($row - 2);
$pline =~ s/^.*«(.*?)» sauvegardé \[.*$/$1/;
$pline =~ s/^.*'(.*?)' saved \[.*$/$1/;
$pline =~ s/^.*`(.*?)' saved \[.*$/$1/;
$self-tt_write($pline);
}

# any other
else {
$line =~ s/\s+$//;
$self-tt_write($line);
}
}

()
}


Re: Feature : walkthrough lines of stdout

2015-06-17 Thread Bob Proulx
Hrazel wrote:
 It would be so cool just to [shift] + [arrow up]  to go to the line of
 interest. [arrow right]  to copy it to the clipboard and return to the
 normal console again. then I can decide what to do with it next. 

This would need some type of wrapper around everything such as GNU
'screen' or as Andreas Schwab hints at emacs interactive shell mode.

Have you looked at screen's copy and paste mechanism?

There are also programs such as xclip and xsel that interface with X
and allow you to cut and paste text from the command line.  If you
know you want the output of a program into the cut buffer you can pipe
it to xclip.  Or pull text out of the buffer with xclip.

Bob



Feature : walkthrough lines of stdout

2015-06-17 Thread Hrazel
Hello,

Bash has a nice feature to walkthrough the lines of the command history by
arrow keys.
But when a command is executed and leaves arbitrary traces on stdout I am
forced to take the mouse to copy lines of interest
if I want to use it again.

Im not talking about directing the output of a command to the next command.
I know about piping.

Now it would be nice just to log the last lines on stdout and walk it
through line by line ready to be put to the clipboard.

Lets say  there is a lot of debug info or something arbitrary on screen.
But you want to pick a filename that you find on one of the lines.

Now you would have to copy paste it by mouse so that you can use it like :
vim /usr/bin/myscript.sh

It would be so cool just to [shift] + [arrow up]  to go to the line of
interest. [arrow right]  to copy it to the clipboard and return to the
normal console again. then I can decide what to do with it next. 

This would be useful above all in situations where the output is already
produced and the cant just reproduce it  or where it is too hard to create
an expression just to rgab exactely what you want.


Thanks a lot 

Hrazel




--
View this message in context: 
http://gnu-bash.2382.n7.nabble.com/Feature-walkthrough-lines-of-stdout-tp15616.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.



Re: Feature : walkthrough lines of stdout

2015-06-17 Thread Greg Wooledge
On Wed, Jun 17, 2015 at 04:05:56AM -0700, Hrazel wrote:
 Now it would be nice just to log the last lines on stdout and walk it
 through line by line ready to be put to the clipboard.

This has nothing to do with bash.  You would have to request this
kind of feature at the terminal level (where terminal could be an
X terminal emulator, or a terminal multiplexer like screen or tmux).

When bash runs a command, and that command writes stuff to stdout, bash
is not involved in the writing.  Bash does not sit as an intermediary
between the command and the terminal.  Bash doesn't even know whether
the command wrote anything to the terminal or not, let alone what was
written.



Re: Feature : walkthrough lines of stdout

2015-06-17 Thread Andreas Schwab
Hrazel msj...@gmx.de writes:

 Now it would be nice just to log the last lines on stdout and walk it
 through line by line ready to be put to the clipboard.

M-x shell

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
And now for something completely different.