-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5ff1b20
Showing
3 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
img* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# What is Conics? | ||
|
||
Conics `(CONsole comICS)` is a program that helps you watch comics from `xkcd.com` right in your TTY, without even starting the X server! | ||
|
||
|
||
# Installation | ||
|
||
## Step 1 - dependencies | ||
|
||
Conics uses FBI (**F**rame**B**uffer **I**mageviewer) and cURL so install them | ||
|
||
Arch (FBI is in AUR): | ||
|
||
`yay -S curl fbida` | ||
|
||
Debian, Ubuntu, Mint: | ||
|
||
`sudo apt-get install fbi` | ||
|
||
Other: | ||
|
||
Idk, please tell me if you know | ||
|
||
## Step 2 - main | ||
|
||
Run the following commands to install this program: | ||
|
||
``` | ||
# Download | ||
git clone https://github.com/xezo360hye/Conics | ||
# Make it executable | ||
chmod +x Conics/conics | ||
# Move to $PATH | ||
sudo mv Conics/conics /usr/local/bin/ | ||
# Clean up | ||
rm -rf Conics | ||
``` | ||
|
||
And you are done! | ||
|
||
# Usage | ||
|
||
## General | ||
|
||
To get help message use `conics -h` or `conics --help` - there's all you need to know about arguments | ||
|
||
To navigate through downloaded images, use `J` and `K` keys, or `space` to move forward UNTIL THE LAST ONE REACHED. Press `H` in FBI to get more info | ||
|
||
## Options | ||
|
||
### Dir (-d) | ||
|
||
Use to specify the directory where downloaded images will be stored - for example, `~/Pictures` or `.hidden_memes`. Default folder is *.* (current working directory) | ||
|
||
### Format (-f) | ||
|
||
Format is used in `mktemp` command, so check it for more information. It needs to end with 3 or more X's that will be replaced with random ~letters and numbers~ alnums. By default format is *img-XXXXX* | ||
|
||
### Count (-c) | ||
|
||
Count of comics you want to see. If not used, only one will be shown *(have you done your homework yet?)* | ||
|
||
### Time (-t) | ||
|
||
Great feature of FBI: if you don't press any key in <> seconds, it automatically goes to the next one. Closes when reached to the end | ||
|
||
### Remove (-r) | ||
|
||
Use it with or without argument. If next arg after -r is `true` or `false`, conics uses it, but if not it'll set it to *true*. However, the default value is *false* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#!/bin/bash | ||
|
||
usage() { | ||
echo "\ | ||
Usage: conics [ OPTIONS ] | ||
Available options: | ||
-h --help Show this message and exit | ||
-d --dir STR Directory where images will be saved | ||
-f --format STR Format of files (must end with 3+ X) | ||
-c --count INT Count of images to download | ||
-t --time INT Next image if no user input within TIME seconds | ||
-r --remove [B] Remove images after closing FBI (if no ARG after, set to True) | ||
Default FORMAT is img-XXXXX, DIR is . (current) and COUNT is 1" | ||
|
||
exit $1 | ||
} | ||
|
||
|
||
# Default options | ||
declare FORMAT="img-XXXXX" DIR="." REMOVE=false | ||
declare -i COUNT=1 TIME=5 | ||
|
||
|
||
# Parse args | ||
while [[ -n "$1" ]]; do | ||
case "$1" in | ||
-h|--help) | ||
usage 0;; | ||
-d|--dir) | ||
if [[ -d "$DIR" ]]; then | ||
DIR="$2" | ||
shift 2 | ||
else | ||
echo "Directory not found: $DIR" | ||
exit 4 | ||
fi | ||
;; | ||
-f|--format) | ||
if [[ "$2" =~ ^.*XXX+$ ]]; then | ||
FORMAT="$2" | ||
shift 2 | ||
else | ||
echo "Invalid format: $2\nRun 'conics -h'" | ||
exit 3 | ||
fi | ||
;; | ||
-c|--count) | ||
if [[ "$2" =~ ^[0-9]+$ ]] && (( "$2" > 0 )); then | ||
COUNT="$2" | ||
shift 2 | ||
else | ||
echo "Option 'count' requires INT > 0" | ||
exit 2 | ||
fi | ||
;; | ||
-t|--time) | ||
if [[ "$2" =~ ^[0-9]+$ ]] && (( "$2" > 0 )); then | ||
TIME="$2" | ||
shift 2 | ||
else | ||
echo "Option 'time' requires INT > 0" | ||
exit 5 | ||
fi | ||
;; | ||
-r|--remove) | ||
if [[ "$2" =~ ^(true|false)$ ]] && (( "$2" > 0 )); then | ||
REMOVE="$2" | ||
shift 2 | ||
else | ||
REMOVE=true | ||
shift | ||
fi | ||
;; | ||
--) | ||
break;; | ||
*) | ||
echo "Unknown option: $1" | ||
usage 1;; | ||
esac | ||
done | ||
|
||
|
||
# Check if directory is writable | ||
if [[ ! -w "$DIR" ]]; then | ||
echo "Directory is unwritable" | ||
exit 3 | ||
fi | ||
|
||
|
||
# Download files | ||
while (( COUNT-- )); do | ||
files+=( $(mktemp "$DIR/$FORMAT") ) | ||
curl -so "${files[-1]}" "$(curl -s "https://xkcd.com/$(( $RANDOM % 2599 ))/info.0.json" | jq . | grep -o '"img": ".*"' | grep -o 'h[^"]*')" & | ||
done | ||
wait -n | ||
|
||
|
||
# Watch memes ^_^ | ||
fbi -t "$TIME" -1 -a -l <(echo "${files[@]}" | tr " " "\n") &> /dev/null | ||
|
||
# Remove files | ||
if $REMOVE; then | ||
rm -rf "${files[@]}" | ||
fi |