diff options
author | eoli3n | 2020-11-15 23:39:41 +0100 |
---|---|---|
committer | eoli3n | 2020-11-15 23:39:41 +0100 |
commit | 71c2acfc32b0179b14f00dbaeb8820f3f7ec99ce (patch) | |
tree | 70af84336004aab9d9a6ee7f88c96f21532ce366 | |
download | aur-71c2acfc32b0179b14f00dbaeb8820f3f7ec99ce.tar.gz |
initial commit
-rw-r--r-- | .SRCINFO | 14 | ||||
-rw-r--r-- | PKGBUILD | 17 | ||||
-rw-r--r-- | README.md | 27 | ||||
-rw-r--r-- | UNLICENSE | 24 | ||||
-rwxr-xr-x | up | 161 |
5 files changed, 243 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 000000000000..711d2015b755 --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,14 @@ +pkgbase = upaste + pkgdesc = Paste and upload files on ix.io and x0.at + pkgver = 0.1.0 + pkgrel = 1 + url = https://github.com/eoli3n/upaste + arch = any + license = UNLICENSE + source = up + source = UNLICENSE + sha256sums = 32987e5f3547a041930a6ddfc3bfe440489b23bb1cd70948b63168d93797b960 + sha256sums = 6b0382b16279f26ff69014300541967a356a666eb0b91b422f6862f6b7dad17e + +pkgname = upaste + diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 000000000000..9915b997d217 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,17 @@ +# Maintainer: Jonathan Kirszling <jkirsz@gmail.com> +pkgname=upaste +pkgrel=1 +pkgver=0.1.0 +pkgdesc="Paste and upload files on ix.io and x0.at" +arch=('any') +url="https://github.com/eoli3n/$pkgname" +license=('UNLICENSE') +source=("up" + "UNLICENSE") +sha256sums=("32987e5f3547a041930a6ddfc3bfe440489b23bb1cd70948b63168d93797b960" +"6b0382b16279f26ff69014300541967a356a666eb0b91b422f6862f6b7dad17e") + +package() { + install -Dm755 'up' "${pkgdir}/usr/bin/up" + install -Dm644 'UNLICENSE' "${pkgdir}/usr/share/licenses/${pkgname}/UNLICENSE" +} diff --git a/README.md b/README.md new file mode 100644 index 000000000000..4fb79974eac5 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# upaste +Paste and upload files on ix.io and x0.at + +### Usage + +Bash file uploader + +Usage : + +# Upload a file +``` +$ up [OPTIONS] file +$ cat file.ext | up [OPTIONS] +``` + +# Upload text +``` +$ echo "upaste rocks" | up +$ up +upaste +really +rocks +C-d C-d +``` +Options : + -h Print this usage + -a Disable autocopy in clipboard diff --git a/UNLICENSE b/UNLICENSE new file mode 100644 index 000000000000..fdddb29aa445 --- /dev/null +++ b/UNLICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to <https://unlicense.org> @@ -0,0 +1,161 @@ +#!/usr/bin/env bash + +# Bash file uploader + +# Install: sudo wget $raw_url -O /usr/bin/up && sudo chmod +x /usr/bin/up + +# Use with fish: +# echo "\ +# function up +# /usr/bin/up $argv; +# end +# " > $HOME/.config/fish/functions/up.fish + +# Vars + +AUTOCOPY=1 + +# Functions + +function usage(){ + filename=$(basename "$0") + cat <<- EOF +Bash file uploader + +Usage : + +# Upload a file +$ $filename [OPTIONS] file +$ cat file.ext | $filename [OPTIONS] + +# Upload text +$ echo "upaste rocks" | up +$ up +upaste +really +rocks +C-d C-d + +Options : + -h Print this usage + -a Disable autocopy in clipboard +EOF +} + +function x0(){ + # x0 will be used for file upload and stdin upload + # It correctly set filetype for imgs, ix does not + + # If argument is empty, upload stdin + if [ -z "$1" ] + then + curl -s -F "file=@-" 'https://x0.at/' + # Else upload filename + else + curl -s -F "file=@\"$1\"" 'https://x0.at/' + fi +} + +function ix(){ + # ix.io will be used for piped data upload + curl -s -F 'f:1=<-' 'http://ix.io' +} + +# Arguments + +function arguments(){ + while getopts "ha" arg + do + case $arg in + a) + AUTOCOPY=0 + ;; + h) + usage + exit + ;; + *) + usage + exit 1 + ;; + esac + done + shift $((OPTIND-1)) +} + +function autocopy(){ + # If xorg or wayland is running + if grep 'DISPLAY' <(env) &> /dev/null + then + # If xclip is installed + if which xclip &> /dev/null + then + xclip "$1" + # Else if wl-clipboard is installed + elif which wl-copy &> /dev/null + then + wl-copy "$1" + fi + fi +} + +function is_file(){ + # Test if first argument is an existing file + if [ ! -f "$1" ] + then + echo "File \"$1\" does not exist or is not a regular file" + exit 2 + fi +} + +function main(){ + + # Vars + local url + + # Getopts + arguments "$@" + + # If no piped data + if [ -t 0 ] + then + + # If no argument, read stdin and save url + if [ -z "$1" ] + then + url=$(x0) + # Else upload argument to x0.at and save url + else + # Test if file exists and is a regular file + if [ -n "$1" ] + then + is_file "$1" + fi + url=$(x0 "$1") + fi + + # Else if piped data + else + # Test if argument exists + if [ -n "$1" ] + then + echo "Warning: ignoring file $1..." + fi + # Upload to ix.io and save url + url=$(ix) + fi + + # Print url + echo "$url" + + # If autocopy is set + if [ "$AUTOCOPY" == "1" ] + then + # Autocopy url + autocopy "$url" + fi +} + +# Main + +main "$1" |