LINUX.ORG.RU

История изменений

Исправление wandrien, (текущая версия) :

Отлично, я повторил фишку этого чувака.)

Пойду спать с чувством выполненного долга xD

$ cat .bin/terminal-read-buffer 
#!/bin/sh
xdotool key ctrl+shift+a
xsel -o -p
$ cat .bin/terminal-copyout 
#!/bin/sh
BUFFER="`terminal-read-buffer`"

BUFFER="`echo "$BUFFER" | awk '
BEGIN {
  n = 1
  command=""
  output=""
}
function emit_command() {
  if (output != "" && command != "") {
    print ">> COMMAND << :$ [" n "] " command
    print output
    n++
  }
  command=""
  output=""
}
END {
  emit_command()
}
match($0, "^([[:alnum:]]+@[[:alnum:]]+:.+[$] )(.*)", m) {
  emit_command()
  command = m[2]
  next
}
{
  if (output != "")
    output = output "\n" $0
  else
    output = $0
}
'`"

selected="`echo "$BUFFER" | grep -P -o '(?<=^>> COMMAND << :[$] )\[.*' | fzf`"

if test -n "$selected" ; then
  echo "$BUFFER" | awk -v selected="$selected" '
    BEGIN {
      output=""
      inside_match=0
    }
    ($0 == ">> COMMAND << :$ " selected) {
      inside_match = 1
      next
    }
    (inside_match == 1) {
      if (match($0, "^>> COMMAND << :[$] ")) {
        print output
        nextfile
      }
      if (output != "")
        output = output "\n" $0
      else
        output = $0
    }
  ' | xsel -i -b
fi

Исходная версия wandrien, :

Отлично, я повторил фишку этого чувака.)

Пойду спать с чувством выполненного долга xD

$ cat .bin/terminal-read-buffer 
#!/bin/sh
xdotool key ctrl+shift+a
xsel -o -p
$ cat .bin/terminal-copyout 
#!/bin/sh
BUFFER=`terminal-read-buffer`

BUFFER="`echo "$BUFFER" | awk '
BEGIN {
  n = 1
  command=""
  output=""
}
function emit_command() {
  if (output != "" && command != "") {
    print ">> COMMAND << :$ [" n "] " command
    print output
    n++
  }
  command=""
  output=""
}
END {
  emit_command()
}
match($0, "^([[:alnum:]]+@[[:alnum:]]+:.+[$] )(.*)", m) {
  emit_command()
  command = m[2]
  next
}
{
  if (output != "")
    output = output "\n" $0
  else
    output = $0
}
'`"

selected="`echo "$BUFFER" | grep -P -o '(?<=^>> COMMAND << :[$] )\[.*' | fzf`"

if test -n "$selected" ; then
  echo "$BUFFER" | awk -v selected="$selected" '
    BEGIN {
      output=""
      inside_match=0
    }
    ($0 == ">> COMMAND << :$ " selected) {
      inside_match = 1
      next
    }
    (inside_match == 1) {
      if (match($0, "^>> COMMAND << :[$] ")) {
        print output
        nextfile
      }
      if (output != "")
        output = output "\n" $0
      else
        output = $0
    }
  ' | xsel -i -b
fi