commit 47902f6b857ac1681f55882f204bf57f55f8be33 Author: Justine Date: Fri Nov 1 12:29:34 2019 +0100 First diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e9d84ae --- /dev/null +++ b/LICENSE @@ -0,0 +1,12 @@ +Copyright (C) 2006 by Rob Landley + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..db88522 --- /dev/null +++ b/README.md @@ -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 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 \ No newline at end of file diff --git a/fastcop.py b/fastcop.py new file mode 100644 index 0000000..0bdbd49 --- /dev/null +++ b/fastcop.py @@ -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 = [" ", ""] +elif args.python: + tags = ["", ""] +elif args.bash: + tags = ["", ""] +elif args.pshell: + tags = ["", ""] +elif args.yaml: + tags = ["", ""] +else: + tags = None + +if tags != None: + content = f"{tags[0]}\n{content}{tags[1]}" + +pyperclip.copy(content) +print("File copied to clipboard")