Commit 3a3e1a5e authored by okashi's avatar okashi
Browse files

Merge branch 'rewrite'

Rewrite
parents e577c367 0cb4c52e
*.log
#### joe made this: http://goel.io/joe
#####=== Vim ===#####
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist
*~
#####=== Tags ===#####
# Ignore tags created by etags, ctags, gtags (GNU global) and cscope
TAGS
!TAGS/
tags
!tags/
gtags.files
GTAGS
GRTAGS
GPATH
cscope.files
cscope.out
cscope.in.out
cscope.po.out
#####=== OwO ===#####
*.gz
src
.ropeproject
This diff is collapsed.
PREFIX ?= /usr/local
.PHONY: install
install: install-bin install-man install-icons install-conf
install-bin: bin/owo
mkdir -p $(PREFIX)/$(dir $<)
install -m 0755 $< $(PREFIX)/$<
install-man: share/man/man1/owo.1
mkdir -p $(PREFIX)/$(dir $<)
gzip -9nc $< > $(PREFIX)/$<
install-icons: share/icons/default/500x500/apps/owo.png
mkdir -p $(PREFIX)/$(dir $<)
cp $< $(PREFIX)/$<
install-conf: share/owo/owo.conf
mkdir -p $(PREFIX)/$(dir $<)
cp $< $(PREFIX)/$<
# OwO.sh
A basic example/uploader for uploading to [owo-whats-th.is](https://owo.whats-th.is)'s image server. The aim was to have a script that allowed for users of all operating systems (that werent already supported by ShareX) to also be able to upload to whats-th.is related products.
Thank you to [jomo](https://github.com/jomo/) and his script [jomo/imgur-screenshot](https://github.com/jomo/imgur-screenshot), to which taking snippets and borrowing code has guided me to improving my own script. This script wouldn't be anywhere near what it is today without his efforts.
# owo.sh
A shell script for uploading and shortening links to
[owo.whats-th.is](https://whats-th.is).
## Dependencies
| os | dependency | description
|--------------- |----------------------------- |-----------------------------------------------------------------------------------------------------
| MacOS | Terminal Notifier | Default OSX Notifications suck and barely work, this is a workaround for that.
| | Screencapture | Comes default with OSX and is the client that you use when you press CMD + Shift 3 or CMD + Shift 4.
| | Pbcopy | Comes default with OSX and is used to copy things to your clipboard.
| | GREP | Comes standard with all UNIX OSes and is used to (in this case) decipher JSON.
| | cURL | Comes standard with all UNIX OSes and is used to (in this case) upload to the owo server.
| Linux | Notify-Send | Default Linux barely has any, if at all, notification support from terminal. This is a workaround.
| | Maim | A rich screenshotting client, that better than what comes default with Linux.
| | XClip | Comes default with most UNIX based OSes and allows for things to copied to clipboards.
| | GREP | Comes standard with all UNIX OSes and is used to (in this case) decipher JSON.
| | cURL | Comes standard with all UNIX OSes and is used to (in this case) upload to the owo server.
| Dependency | OS | Notes |
| ------------------------------------------------- | ------------------ | --------------------------------------------------- |
| [curl][cURL Homepage] | **ALL** | N/A |
| [maim][maim Repository] | **Linux**, **BSD** | For FreeBSD users: version on FreshPorts is ancient |
| [jq][jq Homepage] | **ALL** | Not required if `python` or `ruby` present |
| [python][Python Language Homepage] | **ALL** | Not required if `jq` or `ruby` are present |
| [ruby][Ruby Language Homepage] | **ALL** | Not required if `jq` or `python` are present |
| [ffmpeg][FFmpeg Homepage] | **ALL** | Only required for screen recording |
| [xclip][xclip Repository] | **Linux**, **BSD** | Only required if copy to clipboard is enabled |
| libnotify/notify-send | **Linux**, **BSD** | Only required if notifications are enabled |
| [terminal-notifier][terminal-notifier Repository] | **macOS** | Only required if notifications are enabled |
### Additional notes
On \*BSDs you'll need GNU/make (`gmake`) to install this script.
## Installation
### From source (recommended)
1. `git clone https://owo.codes/whats-this/owo.sh.git owo.sh`
2. `cd owo.sh`
3. `git checkout REV` where `REV` is a release. Current latest is `v1.0.0`
4. `sudo make install`, you can change prefix by doing `sudo make install
PREFIX=/usr`
1. Once you install the dependencies above, simply run the command
```shell
curl -L https://owo.codes/whats-this/owo.sh/raw/master/supersetup.sh | bash
```
in your terminal.
## Usage
Basic usage of the script is like so.
```shell
owo image.png
```
However the following flags can be placed after `owo` for the each of the results.
| short | command | description |
| ----- |------------------ |-------------------------------------------------------------------------------------------------- |
| -h | --help | Shows this help screen to you, displaying all the avaliable commands. |
| -v | --version | Show current application version, incase you wanted to reference it elsewhere. |
| -c | --check | Checks whether or not dependencies are installed. Response with a `INFO : ` or and `ERROR : `. |
| | --update | Checks whether or not your application is completely up to date. If not it will alert you. |
| -l | --shorten | Begins the url shortening process. This can be done through application or another argument. |
| -s | --screenshot | Begins the screenshot uploading process. Your OS should be able to guide you through this however. |
| -gr | | Begins screencast (gif) recording process. At this time, this feature is only available on Linux |
| -gs | | Stops the screencast (gif) recording process and starts encoding/uploading. |
#### Screencast capture requirements
* ffmpeg (build > 2013)
* slop (should come with maim)
* If using compton, `xr_glx_hybrid` or `xrender` backend (`glx` causes flicker/tearing)
See `owo --help`
## Using the Mac Workflow
TODO
1. Unzip the workflow file `owo-uploader.workflow.zip`
2. Click on the workflow file. When prompted to install, click yes.
3. Go to `System Preferences > Keyboard > Shortcuts > Services`
4. Scroll down to `General` and look for `owo-uploader`. Assign a shortcut to it.
5. (Optional) Disable default screenshot keys in `System Preferences > Keyboard > Shortcuts > Screen Shots`
## FAQ
**Screen recording on macOS?**<br/>
[No.](https://owo.codes/whats-this/owo.sh/issues/26)
Now when you press your selected shortcut, the screenshot uploader will be launched, without having to type anything in the shell.
**Symbol Lookup Error on Ubuntu 17.xx**<br/>
Build from source or upgrade.
[maim/issues/120](https://github.com/naelstrof/maim/issues/120).
### Contributing
**Wayland support?**<br/>
No. To elaborate, Wayland quite *literally* does not support screenshots.
It is simply too "secure" to allow such things. Please use Xorg instead.
Pull requests are accepted. Make sure you add test suites for new features and
make sure the code passes the spec (so the build doesn't break). Tests are
automatically run when commits are made in a pull request.
### Contributing
1. `git clone https://owo.codes/whats-this/owo.sh.git owo.sh`
2. Make changes
3. `git add -A && git commit -m 'short message describing your changes'`
4. Create a MR on [our repo](https://owo.codes/whats-this/owo.sh)
### License
The contents of this repository are licensed under the MIT license. A
copy of the MIT license can be found in [LICENSE.md](LICENSE.md).
The contents of this repository are licensed under the GPL version 3.
A copy of the GPL can be found in [LICENSE](LICENSE) or on FSF's
[web page](https://www.gnu.org/licenses/gpl-3.0.en.html).
Also see `owo --version`
[cURL Homepage]: https://curl.haxx.se/
[maim Repository]: https://github.com/naelstrof/maim
[jq Homepage]: https://stedolan.github.io/jq/
[Python Language Homepage]: https://www.python.org/
[Ruby Language Homepage]: https://www.ruby-lang.org/
[FFmpeg Homepage]: https://ffmpeg.org/
[xclip Repository]: https://github.com/astrand/xclip
[terminal-notifier Repository]: https://github.com/julienXX/terminal-notifier
This diff is collapsed.
# _ _
# | | | |
# _____ _____ _ _ _ __ | | ___ __ _ __| | ___ _ __
# / _ \ \ /\ / / _ \ | | | | '_ \| |/ _ \ / _` |/ _` |/ _ \ '__|
# |(_) \ V V / (_)| | |_| | |_) | | (_) | (_| | (_| | __/ |
# \___/ \_/\_/ \___/ \__,_| .__/|_|\___/ \__,_|\__,_|\___|_|
# | |
# |_|
#
# OWOUPLOADER.SH SCRIPT CONFIGURATION.
# ------------------------------------
#
# In here you can find multiple values to which you can edit
# in order to fit what you need. Please make sure you know what
# you are editing before you change it, all errors can be
# referred to https://github.com/whats-this/owo.sh/wiki.
# -------------------------------------
# owo.whats-th.is
# -------------------------------------
# General
userkey=""
debug=false
compatability=false
no_notify=false
cap_cursor=true
# -------------------------------------
# file hosting
# -------------------------------------
#Visit https://whats-th.is/faq.html#how-to-access-files for supported URLs
finished_url="owo.whats-th.is"
shorten_url="thats-a.link"
# ------
# Screenshots
scr_directory=Screenshots
scr_filename="shot_`date '+%Y-%m-%d_%H-%M-%S'`.png"
scr_path=${HOME}/Documents/$scr_directory/
keep_scr=true
# Screenrecords
rec_directory=Screenrecords
rec_filename="record_`date '+%Y-%m-%d_%H-%M-%S'`.gif"
rec_path=${HOME}/Documents/$rec_directory/
keep_rec=true
# -------------------------------------
# url shortener
# -------------------------------------
# Clipboard
url_copy=true
#!/bin/bash
if [ ! $(id -u) -ne 0 ]; then
zenity --error --text="This script cannot be run as sudo."
exit 1
fi
ans=$(zenity --list --text "Choose your action" --radiolist --column "Pick" --column "Choice" FALSE Upload FALSE Screenshot FALSE Shorten)
echo $ans
if [[ $? -eq 1 ]]; then
exit 0
fi
if [[ $ans = "Screenshot" ]]; then
owo -s
if [[ $? -eq 3 ]]; then
zenity --error --text="Please put a key in ~/.config/owo/conf.cfg"
exit 1
fi
if [[ $? -eq 1 ]]; then
zenity --error --text="An unexpected error has occured. Please consult ~/.config/owo/log.txt for details."
exit 1
fi
zenity --info --text="Upload Complete. URL copied to clipboard."
exit 0
elif [[ $ans = "Upload" ]]; then
FILE=`zenity --file-selection --title="Select a File to Upload"`
case $? in
0)
zenity --info --text="\"$FILE\" selected.";;
1)
zenity --error --text="No file selected." && exit;;
-1)
zenity --error --text="An unexpected error has occurred." && exit 1;;
esac
sleep 2
owo $FILE
if [[ $? -eq 3 ]]; then
zenity --error --text="Please put a key in ~/.config/owo/conf.cfg"
exit 1
fi
if [[ $? -eq 1 ]]; then
zenity --error --text="An unexpected error has occured. Please consult ~/.config/owo/log.txt for details."
exit 1
fi
zenity --info --text="Upload Complete. URL copied to clipboard."
exit 0
elif [[ $ans = "Shorten" ]]; then
s_url=`zenity --entry --title="Enter URL" --text="Please enter the URL you wish to shorten."`
owo -l $s_url
if [[ $s_url = "" ]]; then
zenity --error --text="URL not found!"
exit 1
fi
if [[ $? -eq 3 ]]; then
zenity --error --text="Please put a key in ~/.config/owo/conf.cfg"
exit 1
fi
if [[ $? -eq 1 ]]; then
zenity --error --text="An unexpected error has occured. Please consult ~/.config/owo/log.txt for details."
exit 1
fi
zenity --info --text="Upload Complete. URL copied to clipboard."
exit 0
fi
[Desktop Entry]
# The type as listed above
Type=Application
# The version of the desktop entry specification to which this file complies
Version=1.0
# The name of the application
Name=OwO
# A comment which can/will be used as a tooltip
Comment=Screenshoter, Uploader, and Shortener for owo
# The executable of the application, possibly with arguments.
Exec=owo-gui
# The name of the icon that will be used to display this entry
Icon=owo
# Describes whether this application needs to be run in a terminal or not
Terminal=false
# Describes the categories in which this entry should be shown
Categories=Internet;Accesories
#!/usr/bin/env bash
# _ _
# | | | |
# _____ _____ _ _ _ __ | | ___ __ _ __| | ___ _ __
# / _ \ \ /\ / / _ \ | | | | '_ \| |/ _ \ / _` |/ _` |/ _ \ '__|
# |(_) \ V V / (_)| | |_| | |_) | | (_) | (_| | (_| | __/ |
# \___/ \_/\_/ \___/ \__,_| .__/|_|\___/ \__,_|\__,_|\___|_|
# | |
# |_|
#
# OWO.SH SCRIPT.
# ----------------------
# This script allows for native support to upload to the image server
# and url shortener component of whats-th.is. Through this you can do
# plethora of actions.
#
# A big thank you to jomo/imgur-screenshot to which I've edited parts
# of his script into my own.
trap '' 2
if [ ! "$(id -u)" -ne 0 ]; then
echo "ERROR : This script cannot be run as sudo."
echo "ERROR : You need to remove the sudo from \"sudo ./setup.sh\"."
exit 2
fi
owodir="$HOME/.config/owo"
current_version="v0.0.19"
##################################
if [ ! -d "$owodir" ]; then
echo "INFO : Could not find config directory. Please run setup.sh"
exit 1
fi
source "$owodir"/conf.cfg
key="$userkey" >&2
# Split URLs by ;
IFS=';' read -ra output_urls <<< "$finished_url" >&2
if [ ${#output_urls[@]} -le 1 ]; then
output_url="$finished_url" >&2
else
output_url="${output_urls[$RANDOM % ${#output_urls[@]} ]}"
fi
directoryname="$scr_directory" >&2
filename="$scr_filename" >&2
path="$scr_path" >&2
rec_directoryname="$rec_directory" >&2
rec_filename="$rec_filename" >&2
rec_path="$rec_path" >&2
no_notify="$no_notify" >&2
print_debug="$debug" >&2
scr_cursor="$cap_cursor" >&2
IFS=';' read -ra shorten_urls <<< "$shorten_url" >&2
if [ ${#shorten_urls[@]} -le 1 ]; then
shorten_url="$shorten_url" >&2
else
shorten_url="${shorten_urls[$RANDOM % ${#shorten_urls[@]} ]}"
fi
##################################
function is_mac() {
uname | grep -q "Darwin"
}
function check_key() {
if [ -z "$key" ]; then
echo "INFO : \$key not found, please set \$userkey in your config file."
echo "INFO : You can find the key in "$owodir"/conf.cfg"
exit 1
fi
}
function notify() {
if [ "$no_notify" == "false" ]; then
if is_mac; then
/usr/local/bin/terminal-notifier -title owo.whats-th.is -message "${1}" -appIcon $owodir/icon.icns -timeout 5
else
notify-send owo.whats-th.is "${1}" -i "$owodir"/icon.png
fi
fi
}
function delete_scr() {
if [ "$keep_scr" != "true" ]; then
rm "${path}${filename}"
fi
}
function clipboard() {
if is_mac; then
echo "${1}" | tr -d "\n\r" | pbcopy
else
echo "${1}" | tr -d "\n\r" | xclip -i -sel c -f | xclip -i -sel p
fi
}
function keyset() {
read -p "Please enter your API key: " keystring
sed -i /userkey=/c\userkey="$keystring" "$owodir"/conf.cfg
echo "Saved."
echo ""
settings
}
function finishset() {
read -p "Please enter your preferred URLs for upload/screenshot (separated by semicolons ';'): " finishstring
if [ "$finishstring" = "q" ]; then
settings
fi
sed -i /finished_url=/c\finished_url="\"$finishstring\"" "$owodir"/conf.cfg
echo "Saved."
echo ""
settings
}
function shortenset() {
read -p "Please enter your preferred URLs for shortening (separated by semicolons ';'): " shortenstring
if [ "$shortenstring" = "q" ]; then
settings
fi
sed -i /shorten_url=/c\shorten_url="\"$shortenstring\"" "$owodir"/conf.cfg
echo "Saved."
echo ""
settings
}
function notif_prefs() {
read -p "Would you like to recieve notifications from OwO.sh? (y/n/q) " choice
case "$choice" in
y|Y ) sed -i /no_notify=/c\no_notify=false "$owodir"/conf.cfg; echo "Saved."; echo ""; misc;;
n|N ) sed -i /no_notify=/c\no_notify=true "$owodir"/conf.cfg; echo "Saved."; echo ""; misc;;
q|Q ) echo ""; misc;;
* ) echo "Invalid selection. Please choose y or n.";;
esac
}
function scrsave_prefs() {
read -p "Would you like to save screenshots to your local? (y/n/q) " choice
case "$choice" in
y|Y ) sed -i /keep_scr=/c\keep_scr=true "$owodir"/conf.cfg; echo "Saved."; echo ""; misc;;
n|N ) sed -i /keep_scr=/c\keep_scr=false "$owodir"/conf.cfg; echo "Saved."; echo ""; misc;;
q|Q ) echo ""; misc;;
* ) echo "Invalid selection. Please choose y or n.";;
esac
}
function recsave_prefs() {
read -p "Would you like to save screenrecords to your local? (y/n/q) " choice
case "$choice" in
y|Y ) sed -i /keep_rec=/c\keep_rec=true "$owodir"/conf.cfg; echo "Saved."; echo ""; misc;;
n|N ) sed -i /keep_rec=/c\keep_rec=false "$owodir"/conf.cfg; echo "Saved."; echo ""; misc;;
q|Q ) echo ""; misc;;
* ) echo "Invalid selection. Please choose y or n.";;
esac
}
function cursor_prefs() {
read -p "Would you like to capture the cursor in screenshots? (y/n/q) " choice
case "$choice" in
y|Y ) sed -i /cap_cursor=/c\cap_cursor=true "$owodir"/conf.cfg; echo "Saved."; echo ""; misc;;
n|N ) sed -i /cap_cursor=/c\cap_cursor=false "$owodir"/conf.cfg; echo "Saved."; echo ""; misc;;
q|Q ) echo ""; misc;;
* ) echo "Invalid selection. Please choose y or n.";;
esac
}
function xclip_prefs() {
read -p "Would you like links to be copied to your clipboard? (y/n/q) " choice
case "$choice" in
y|Y ) sed -i /scr_copy=/c\scr_copy=true "$owodir"/conf.cfg; sed -i /url_copy=/c\url_copy=true $owodir/conf.cfg; echo "Saved."; echo ""; misc;;
n|N ) sed -i /scr_copy=/c\scr_copy=false "$owodir"/conf.cfg; sed -i /url_copy=/c\url_copy=false $owodir/conf.cfg; echo "Saved."; echo ""; misc;;
q|Q ) echo ""; misc;;
* ) echo "Invalid selection. Please choose y or n."; misc;;
esac
}
function misc() {
echo "Miscellaneous Settings"
echo "1) Notification preferences"
echo "2) Screenshot saving preferences"
echo "3) Screenrecord saving preferences"
echo "4) Cursor visibility preferences"
echo "5) Clipboard copying preferences"
echo "q) Go back"
read -p "Please enter your selection: " selection
case "$selection" in
1 ) notif_prefs;;
2 ) scrsave_prefs;;
3 ) recsave_prefs;;
4 ) cursor_prefs;;
5 ) xclip_prefs;;
q ) echo ""; settings;;
* ) echo "Invalid selection. Please choose 1, 2, 3, 4, or 5."; misc;;
esac
}
function settings() {
echo "OwO.sh Settings"
echo "1) API Key"
echo "2) Upload/Screenshot URL"
echo "3) Shorten URL"
echo "4) Misc"
echo "q) Quit"
read -p "Please enter your selection: " selection
case "$selection" in
1 ) keyset;;
2 ) finishset;;
3 ) shortenset;;
4 ) misc;;
q ) clear; exit 0;;
* ) echo "Invalid selection. Please choose 1, 2, 3, or 4."; settings;;
esac
}
function shorten() {
check_key
if [ -z "${2}" ]; then
notify "Please enter the URL you wish to shorten."
echo "INFO : Please enter the URL you wish to shorten."
read url
else
url="${2}"
fi
#Check if the URL entered is valid.
regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
if [[ "$url" =~ $regex ]]; then
result=$(curl -s -G "https://api.awau.moe/shorten/polr?action=shorten" --data-urlencode "key=$key" --data-urlencode "url=$url" -H "User-Agent: WhatsThisClient (https://github.com/whats-this/owo.sh, v0.0.19)")
#Check if the URL got sucessfully shortened.
if grep -q "https://" <<< "${result}"; then
code=$(echo "$result" | sed 's/.*oe//')
result="https://$shorten_url$code"
d="$1"
if [ "$d" = "true" ]; then
clipboard "$result"
echo "$result"
notify "Copied the link to the keyboard."
echo "$(date): $result" >> "$owodir"/shorten.log
else
echo "$result"
fi
else
notify "Shortening failed!"
fi
else
notify "URL is not valid!"
exit 4
fi
}
function screenshot() {
check_key
# Alert the user that the upload has begun.
notify "Select an area to begin the upload."
# Begin our screen capture.
if [[ $fullscreen ]]; then
if is_mac; then
screencapture -o "${path}${filename}"
elif [[ $scr_cursor ]]; then
maim --hidecursor "${path}${filename}"
else
maim "${path}${filename}"
fi
else
if is_mac; then
screencapture -o -i "${path}${filename}"
elif [[ $scr_cursor ]]; then
maim -s --hidecursor "${path}${filename}"
else