1 Востаннє редагувалося dot (14.10.2020 07:48:51)

Тема: Perepysaty fajlj do bufera na konsolji

Dekotri zauvahy.

1. Moja systema:

OS: Linux Mint 20 x86_64
DE: Cinnamon

Tobto tut otcevydnyj Xserver, ale moglyvi zminy.

2. Same do buferu. Sutj v tim, aby mih do polja z pidtrymkoju drag-and-drop zakynuty fajl tcerez Ctrl + V. Tomu pro cp zabudjte odrazu.

3. Same fajl, a ne tekstovyj zmist. Bo fajl moge budj-jakyj, v tomu tcysli pdf i gif. Tomu pro cat i podibne mogete teg odrazu zabuty.

Perevirjaty јmu zakyd fajliv na Teljeqram. Odrazu skazju, ge z fajljovoho menedgera Nemo, kotrym majge ne korystuju, to pratsjuje, tobto tam Ctrl + C, a v hyncyx mistsjax pislja Ctrl + V, v tomu tcysli Teljeqrami, fajlj sja zakydujejsja.

Ctco meni vidomo i do tcoho dijcov:

1. Oskiljky Xserver, to za podibni manipuljatsijy vidpovidaje xclip. Jak ne dyvno, pratsjuje, ale duge obmegeno, tobto ja zmih:

xclip -i -selection clipboard -t image/png file.png

2. Ale, napryklad, hadky ne maju pro -t dlja gif. Jak meni tsjoho uznavaty? Takog xotjiv b universaljnostjy. Nadybav takoho:

xclip -i -selection clipboard -t x-special/gnome-copied-files file.form

Ale take ne robe. Nadybav (napryklad) takog na x-special/mate-copied-files, x-special/nautilus-clipboard. Kotri, zvisno, ne pidxodjatj. Jakctco meni treba desj takym cljaxom, to jak meni uznaty zminnu -t? Jakctco g ne takym, to jak vzahali?

2 Востаннє редагувалося dot (14.10.2020 09:07:51)

Re: Perepysaty fajlj do bufera na konsolji

Rjicyv pocukaty, jak tsjoho robjatj na ranger. Vypadkovo, tam i (Anql.) znajcov:

printf "file://${PWD}/%s\r\n" file.form | xclip -i -selection clipboard -t text/uri-list

Jak vyjavylo sja, vsjo znatcno prostjice. Zaraz pysju skrypta, aby mogna bulo prostjice, typu komanda {fajlj[y]} i aby mogno bulo odrazu dekiljka fajljiv.

3 Востаннє редагувалося dot (15.10.2020 09:24:28)

Re: Perepysaty fajlj do bufera na konsolji

Ja ne duge vyhaduvav, tomu uzjav z hotovoho. A stegyty poky ctco mogna bude tut.

Kid
#!/bin/bash

# clipboard-files - Copy files from the clipboard in a Linux terminal.
#
# Read more: https://replace.org.ua/topic/12326/
#
# By dot as know as pt
#
# Clipboard interfacing code inspired from:
# https://github.com/larspontoppidan/clipboard-files
# https://redd.it/hs9kv1
#

SCRIPT_REV=2019-05-14

# Is this script being sourced?
if [[ -z $BASH_SOURCE ]] || [[ $(basename ${0#-}) != ${BASH_SOURCE##*/} ]]; then
  # Being sourced
  sourced=true
  EXIT=return
else
  # Running directly
  sourced=false
  EXIT=exit
fi

if [ $# -lt 1 ]; then
  syntax_error
  $EXIT
fi

xclip -version 1>/dev/null 2>/dev/null
result=$?
if [ $result != 0 ]; then
  echo "xclip doesn't seem to be installed, exiting"
  $EXIT
fi

clipboard=""
count=0

for one_arg in "$@"
do
    if [[ ${one_arg} == -* ]]; then
      syntax_error
      $EXIT
    fi

    filename=$(realpath "${one_arg}")

    if [ -e "${filename}" ]; then
      clipboard="${clipboard}\nfile://${filename}"
      count=$((count+1))
    else
      echo "File doesn't exist or error: ${filename}"
    fi
done

if [ $count -ge 1 ]; then
  echo -en "${clipboard}" | xclip -i -selection clipboard -t text/uri-list
  result=$?
  if [ $result != 0 ]; then
    echo "Error copying to clipboard"
  else
    echo "${count} item(s) copied to clipboard"
  fi
fi

Na Teljeqram zalyvaje, tak. Ale probljema zalycyla sja, bo v bravzeri z poljamy drag-and-drop