Kaynağa Gözat

Adding bash uploader with extra features from maim and xclip

pull/1/head
alusion 5 yıl önce
ebeveyn
işleme
8fcdfa9bb3
1 değiştirilmiş dosya ile 156 ekleme ve 0 silme
  1. 156
    0
      Upload/teknik.sh

+ 156
- 0
Upload/teknik.sh Dosyayı Görüntüle

@@ -0,0 +1,156 @@
#!/bin/bash
#
# teknik - Upload files/scrots/urls to teknik.io (rip pomf & uguu ;_;7)
# requires maim / slop
# By onodera, modified by SirCmpwn
# Further modified by alusion


## CONFIGURATION
# Copy links to clipboard after upload (requires xclip)
clipboard=true
# Send a notification when done
notify=true
# Open URL in browser
browser=false
# Log URLs
log=false
# Log file location
logfile="$HOME/.teknik"

## FUNCTIONS

# This function sets $file to a selection scrot
selection() {
uploadme="/tmp/scrot.png"

maim --hidecursor -s -b 3 -c 250,250,250 "$uploadme" 2> "/dev/null"
if [[ "$?" -ge 1 ]]; then
echo "Selection cancelled."
exit 1
fi

word=selection
}

# This function sets $file to your clipboard contents
clipboard() {
uploadme="/tmp/scrot.txt"

xclip -o > "$uploadme"

word=clipboard
}

# This function sets $file an url
url() {
type="$(echo "$location" | rev | cut -d "." -f 1 | rev)"
uploadme="/tmp/url.$type"

wget --quiet "$location" -O "$uploadme"

word=url
}

# This function sets $file a file
file() {
if [[ -f "$location" ]]; then
uploadme="$location"
else
echo "File not found."
exit 1
fi

word=file
}

# This function sets $file to a full screen scrot
desktop() {
uploadme="/tmp/scrot.png"

maim --hidecursor "$uploadme"

word=desktop
}

# This function uploads the $file
upload() {
url=$(curl --silent -F file="@$uploadme" "https://api.teknik.io/upload/post")
if [[ "${url}" =~ "error" ]]; then
printf 'error uploading file!\n'
exit 1
else
url="${url##*name\":\"}"
url="https://u.teknik.io/${url%%\"*}"
fi
}

# This function logs the url, copies the url to the clipboard, and/or opens the url in your browser
feedback() {
# Copy url to clipboard
if [[ "$clipboard" == true ]]; then
echo "$url" | xclip -selection primary
echo "$url" | xclip -selection clipboard
fi

# Log url
if [[ "$log" == true ]]; then
echo "$url" >> "$logfile"
fi

# Open url in browser
if [[ "$browser" == true ]]; then
xdg-open "$url"
fi

# Send notification
if [[ "$notify" == true ]]; then
notify-send "Upload complete: $url"
fi

echo "${url}"
}

## EXECUTE

if [[ "$#" -ge 1 ]]; then
case "$@" in
-h|--help)
echo "usage: teknik [options] [file/url]"
echo "options:"
echo " -h, --help print help and exit"
echo " -p, --paste upload your clipboard as text"
echo " -s, --selection upload selection scrot"
echo " -v, --version print version and exit"
exit 0
;;
-s|--selection)
selection
;;
-v|--version)
echo "teknik 0.1.1"
exit 0
;;
-p|--paste)
clipboard
;;
http*)
location="$@"
url
;;
*)
location="$@"
file
;;
esac
else
desktop
fi


if [[ "$#" -eq 0 ]]; then
desktop
fi

upload
feedback

Loading…
İptal
Kaydet