First
This commit is contained in:
commit
47902f6b85
12
LICENSE
Normal file
12
LICENSE
Normal file
@ -0,0 +1,12 @@
|
||||
Copyright (C) 2006 by Rob Landley <rob@landley.net>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose
|
||||
with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
24
README.md
Normal file
24
README.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Fastcop
|
||||
|
||||
Fastcop est un petit script permettant de lire et copier le contenu d'un
|
||||
fichier et de le copier dans le presse-papier.
|
||||
Testé sur :
|
||||
* Fedora 30
|
||||
|
||||
Il prend en argument le fichier (ou la lettre p pour lire depuis le pipe). L'argument -w permet d'ajouter les balises <nowiki></nowiki> afin de coller le contenu d'un bloc de texte dans un fenêtre non formatée sur un wiki.
|
||||
|
||||
Usage :
|
||||
```
|
||||
[justine@argonaut Fastcop]$ fastcop --help
|
||||
usage: fastcop [-h] [-w] file
|
||||
|
||||
positional arguments:
|
||||
file Path of a file or p to read from the pipe
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
-w, --wiki Formats the text for wiki copying.
|
||||
|
||||
```
|
||||
|
||||
IDEE: Faire un presse papier à la mano pour les OS sans presse-papier + utiliser le module vim pour pouvoir coller le texte dans vim
|
84
fastcop.py
Normal file
84
fastcop.py
Normal file
@ -0,0 +1,84 @@
|
||||
#! /usr/bin/env python3
|
||||
# encoding: utf-8
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
import os
|
||||
import pip
|
||||
import sys
|
||||
|
||||
#Install and import pyperclip
|
||||
try:
|
||||
import pyperclip
|
||||
except ImportError as e:
|
||||
answer = str(input("Pyperclip module is not installed and is required. Install it now with pip?[y/N]"))
|
||||
if answer == "y":
|
||||
subprocess.call([sys.executable, "-m", "pip", "install", "pyperclip", "--user"])
|
||||
import pyperclip
|
||||
|
||||
#Reads a file, copies it to clipboard
|
||||
|
||||
|
||||
###############################FONCTS##########################
|
||||
|
||||
def getArgs():
|
||||
'''Gets all the arguments passed to the script and returns them in a parse_args()-type object.
|
||||
No args
|
||||
Returns:
|
||||
-args : an args object containing all the optional arguments passed to the script.
|
||||
'''
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("file", action="store", type=str, help="Path of a file or p to read from the pipe") #Required, can be p
|
||||
parser.add_argument("-w", "--wiki", help="Formats the text for wiki copying.", action="store_true")
|
||||
parser.add_argument("-p", "--python", help="Formats the text for syntaxhighlight lang=python", action='store_true')
|
||||
parser.add_argument("-b", "--bash", help="Formats the text for syntaxhighlight bash", action='store_true')
|
||||
parser.add_argument("-P", "--pshell", help="Formats the text for syntaxhighlight powershell", action='store_true')
|
||||
parser.add_argument("-y", "--yaml", help="Formats the text for syntaxhighlight yaml", action='store_true')
|
||||
|
||||
#Creating the args object
|
||||
args=parser.parse_args()
|
||||
|
||||
return args
|
||||
|
||||
################################MAIN#############################
|
||||
###GETTING THE FILE
|
||||
|
||||
args = getArgs()
|
||||
|
||||
if args.file == "p":
|
||||
'''
|
||||
p means we ride from the pipe
|
||||
pipein, pipeout = os.pipe()
|
||||
os.close(pipeout)
|
||||
pipein = os.fdopen(pipein)
|
||||
content = pipein.read()
|
||||
'''
|
||||
content = sys.stdin.read()
|
||||
content = str(content)
|
||||
else:
|
||||
myfile = args.file
|
||||
with open(myfile, "r") as afile:
|
||||
content = afile.read()
|
||||
|
||||
##formatting
|
||||
|
||||
if args.wiki:
|
||||
tags = [" <nowiki>", "</nowiki>"]
|
||||
elif args.python:
|
||||
tags = ["<syntaxhighlight lang='python'>", "</syntaxhighlight>"]
|
||||
elif args.bash:
|
||||
tags = ["<syntaxhighlight lang='bash'>", "</syntaxhighlight>"]
|
||||
elif args.pshell:
|
||||
tags = ["<syntaxhighlight lang='powershell'>", "</syntaxhighlight>"]
|
||||
elif args.yaml:
|
||||
tags = ["<syntaxhighlight lang='yaml'>", "</syntaxhighlight>"]
|
||||
else:
|
||||
tags = None
|
||||
|
||||
if tags != None:
|
||||
content = f"{tags[0]}\n{content}{tags[1]}"
|
||||
|
||||
pyperclip.copy(content)
|
||||
print("File copied to clipboard")
|
Loading…
x
Reference in New Issue
Block a user