Skip to content

Commit 49f3ee5

Browse files
committed
init
0 parents  commit 49f3ee5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1403
-0
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
3+
All notable changes to this project are documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/-0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.1.0] - 2021-06-03
9+
10+
### Added
11+
12+
- Initial release.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Rob O'Leary
4+
Permission is hereby granted, free of charge, to any person obtaining
5+
a copy of this software and associated documentation files (the
6+
"Software"), to deal in the Software without restriction, including
7+
without limitation the rights to use, copy, modify, merge, publish,
8+
distribute, sublicense, and/or sell copies of the Software, and to
9+
permit persons to whom the Software is furnished to do so, subject to
10+
the following conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
<h1 align="center">
2+
<br>
3+
<img align="center" src="img/title/logo.png" width="301" alt="Fetching">
4+
<br>
5+
</h1>
6+
<p align="center"><strong>A collection of <i>fetching</i> unicode art for the terminal.</strong></p>
7+
8+
> You have to be in a state of play to design. If you're not in a state of play, you can't make anything.
9+
>
10+
> \- Paula Scher
11+
12+
The goal is to add a touch of beauty to your terminal, and trigger a sense of play.
13+
14+
![mario example](img/mario-mytheme.png)
15+
16+
The art is **colored according to your terminal color scheme**. Here are some examples side-by-side using different themes: the top-left theme is [Dracula](https://draculatheme.com/),the top-right is [Solarized](https://ethanschoonover.com/solarized/), the other two are just me playing around with colors! The output can have a different personality depending on your color scheme.
17+
18+
![mario colored](img/mario-colors.png)
19+
20+
The included image scripts are **responsive to the terminal window**. This prevents distorted output in the random and slideshow modes. 🕶️
21+
22+
![garbled output](img/garbled.png)
23+
24+
The included scripts are inspired by:
25+
26+
- abstract art, particularly the [De Stijl movement](https://en.wikipedia.org/wiki/De_Stijl) with its simplified forms and limited palette
27+
28+
![mondrian](img/mondrian.png)
29+
- computer games, particularly from the 1980's and 1990's
30+
31+
![space invaders](img/space-invaders.png)
32+
- street art
33+
34+
![obey by invader](img/obey.png)
35+
36+
- star wars
37+
38+
![groku](img/groku.png)
39+
40+
I have a list of more images I would like to add (in *todo.md*). I will work through this when the mood strikes me!
41+
42+
## Installation
43+
44+
```bash
45+
git clone https://github.com/robole/fetching
46+
cd fetching
47+
bash install.sh
48+
```
49+
50+
<u>Usage</u>: `bash install.sh [OPTION]`
51+
52+
| OPTIONS: | |
53+
|:--------------------|:-------------|
54+
|-d, --dest | Specify destination directory (Default: `$HOME/.local/bin`)|
55+
|-h, --help | Show this help|
56+
57+
> Note: The default installation location may not be on your [`PATH`](https://opensource.com/article/17/6/set-path-linux). You can run fetching from any folder on your system, all this script does is move the files to a "sane" executable location.
58+
59+
If you want to uninstall, run `bash uninstall.sh` with the same destination directory that you provided on installation.
60+
61+
## Usage
62+
63+
<u>Usage</u>: `fetching [OPTION] [SCRIPT NAME/INDEX/NUMBER OF SECONDS]`
64+
65+
| OPTIONS: | |
66+
|:--------------------|:-------------|
67+
| -h, --help, help|Print the help page. |
68+
| -l, --list, list | List all available scripts.|
69+
| -r, --random, random | Show a random image. It only picks image that fit within the terminal window.|
70+
| -e, --exec, exec | Show an image by SCRIPT NAME or INDEX. |
71+
| -s, --slideshow, slideshow | Run a slideshow showing a new image every NUMBER OF SECONDS. It is responsive to the terminal width.|
72+
| -w, --width, width | Show the terminal width. It is shown as a size e.g 'xs' for extra small,and as a width in columns. This can be used to grade the size of the output of your scripts.|
73+
74+
The most common scenarios are:
75+
1. The command `fetching -l` will show you all the available images to show (scripts to run). You can run an image by index: `fetching -e 4` to show the 4th image from the list, or by name `fetching -e mario-xs`.
76+
1. I put the following command `fetching -r` in my `.bashrc` and `.zshrc` files to show a random image every time I open a new terminal.
77+
1. If you want to run a slideshow that cycles through images every 3 seconds, you can run `fetching -s 3`.
78+
![slideshow](img/slideshow.gif)
79+
80+
**I recommend using a monospace font**. Fonts with variable spacing may mess up the alignment of some of the art.
81+
82+
## Rendering differences between terminals
83+
84+
I noticed that some terminals show the unicode output from the script with gaps. You can see Alacritty does this (bottom left in screenshot below).
85+
86+
![terminal rendering differences](img/terminal-diff.png)
87+
88+
I'm not sure if there is a setting that would tweak Alacritty to look the same way as Kitty. I use Kitty, so I'm not bothered to look! I think the uniform texture is more aesthetic, but you may like the blockier style!
89+
90+
## Make your own art
91+
92+
You can use the `template` script in the root folder to get started quickly on your own creation.
93+
94+
There are approxmiately 143,859 unicode characters. You can use any of those, search through [the list](https://en.wikipedia.org/wiki/List_of_Unicode_characters)) to find different ones!
95+
96+
I mostly used the [Block Elements character set](https://en.wikipedia.org/wiki/Block_Elements) (as below) in my art, but I am interested to try out more.
97+
98+
```
99+
█ ▉ ▊ ▋ ▌ ▍ ▎ ▏▐ ▕ ▇ ▆ ▅ ▄ ▃ ▂ ▁ ■ ▄ ▀ ▬ ▓ ▒ ░
100+
```
101+
102+
I included a wider selection of symbols as a comment in `template` to get you started.
103+
104+
The script has the color variables to set colors for the background and foreground. You can use these together with `cat` to create your own masterpiece.
105+
106+
For example, this code:
107+
108+
![pacman-right-xs code](img/pacman-right-xs-code.png)
109+
110+
produces this output:
111+
112+
![pacman-right-xs output](img/pacman-right-xs-output.png)
113+
114+
The `rt` variable is used to reset the current color to the default text color. <u>You should use always use `rt` at the end of your output text</u>, so it doesn't affect the text in your terminal after the script is run!
115+
116+
You will notice that all image scripts have a *naming convention*. **The size is added as a postfix to enable the responsive behaviour** e.g. `mario-xs`. To find the width of the output, run your image script and reduce the width of the terminal until the output becomes distorted. You can run the command `fetching -w`to see what the current terminal size is. Set the name of the script based on this. Ensure that the output width does not exceed the range of that size. The sizes are: xs, s, m, l, and xl. I will see if I can do something to automate this process.
117+
118+
If you find it difficult to create an image in this format, the process is similar to the patterns people design for cross-stitching. You could use someone else's pattern. See the [inspiration](#inspiration) section below for more on that.
119+
120+
### Process
121+
122+
You can create a reference image in one of the many pixel art editors. I like [piskel](https://www.piskelapp.com/). Its free to use, and you don't need to signup/login to use it. You can pick a grid size and play around with a composition. You don't want to do this with raw text in the script a lot of the time! 😅
123+
124+
![piskel editor](img/editing-process/piskel.png)
125+
126+
Once the composition is finished, I zoom in on the composition as to have it at a decent size, and take a screenshot. I do this because I want the grid lines included, if you export it from Piskel as an image, it does not include the gridlines!
127+
128+
![exported](img/editing-process/export.png)
129+
130+
Once you are ready to transform it to text, hop into your editor, and open the `template`. I set my windows up like this and it's quite quick to do it. I run the script in the terminal in VS Code to verify what I am doing. This mondrian image took approx 30 mins of editing in VS Code, whereas the mondrian lozenge image took me half a day to get right.
131+
132+
![editing process](img/editing-process/windows.png)
133+
134+
Be mindful that since you're using a "grid", you're editing text that is related in 2 dimensions! So, if you delete something from one line, it can knock your entire image out of wack. There are a few tricks I honed to minimise mistakes and become more efficient.
135+
136+
I will speak about specific VS Code features, but most editors should have similar features:
137+
138+
1. Use multipe cursors to make quick multi-line edits. Using Ctl+Shift+Down select multiple successive lines below.
139+
![multi-line edit](img/editing-process/multi-line-edit.gif)
140+
1. If you find yourself making bigger changes across multiple lines, you can switch to "column selection mode". You will find this in the menu by going `Selection` > `Column Selection Mode`. This allows you to make vertical edits. This is particularly useful for copying portions of text in the middle of lines that span across many lines.
141+
142+
This may sound like a lot, but you can get the hang of it quite quickly if you enjoy playing around with the process. A custom editor would be nice for this of course, but it's quite a niche thing to make!
143+
144+
## Inspiration
145+
146+
The process for creating image patterns is similar to the patterns people design when making things with beads and cross-stitching. It's digital cross-stitching really! So if you search for these patterns, you may find something you like and the design work is done for you.
147+
148+
Some resources I found useful are:
149+
150+
- [Kandi Patterns](https://kandipatterns.com/)
151+
152+
![yoda search kandi patterns](img/inspiration/yoda-kandi-patterns.png)
153+
154+
- Search [pinterest](https://www.pinterest.com/) for cross-stitch patterns, and explore some [boards](https://www.pinterest.com/flowerthread/free-cross-stitch-patterns/).
155+
156+
![pinterest patterns](img/inspiration/pinterest.png)
157+
158+
You can also look at grafitti stencils are a source of inspiration. Designs with diagonal lines and circular shapes are a bit harder to pull off.
159+
160+
## Contribute
161+
162+
If you have a suggestion, find a bug, or have made some image scripts that you would like to share, feel free to open an issue.
163+
164+
I am bit fussy about what image scripts I would include, so it's prob best to ask before you make a PR. I could add a "gallery" section here to point to your repo if you made some nice ones that others could include.
165+
166+
The minimum prerequisites for accepting an image script are that it has to have:
167+
1. A blank line as the fist line,
168+
1. All lines have left padding of 2 spaces
169+
1. It resets the colors using `$rt` on the last line.
170+
171+
All of my image scripts are formatted consistently in this way. Generally, my images scripts are not too tall also. That's my taste.
172+
173+
## Show gratitude
174+
175+
If you are happy with this, please star the repo and recommend it to others.
176+
177+
You can [buy me a coffee](https://Ko-fi.com/roboleary) if you would like to enable me to make more great open-source software and tutorials. 🍵🙏
178+
179+
## Credit
180+
181+
- The original idea probably came from [this discussion on crunchbang](https://crunchbang.org/forums/viewtopic.php?id=13645).
182+
- Derek Taylor's [Shell Color Scripts](https://gitlab.com/dwt1/shell-color-scripts) was a source of inspiration for a few scripts.

fetching

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#!/usr/bin/env bash
2+
3+
# Name: fetching
4+
#
5+
# Description: A collection of "fetching" unicode art for the terminal.
6+
#
7+
# Author: Rob O'Leary
8+
9+
full_path=$(realpath $0)
10+
dir_path=$(dirname $full_path)
11+
12+
dir_scripts="${dir_path}/fetching-scripts"
13+
14+
fmt_help=" %-20s\t%-54s\n"
15+
list_scripts_fpath=($(find "${dir_scripts}" -type f | sort)) # array
16+
list_scripts="$(find "${dir_scripts}" -type f | sort | xargs basename -a | nl)"
17+
length_scripts="$(find "${dir_scripts}" -type f | wc -l)"
18+
19+
function _help() {
20+
echo "Description: A collection of *fetching* unicode art for the terminal. You can choose an image to show, show one at random, or show them all as a slideshow."
21+
echo ""
22+
echo "Usage: fetching [OPTION] [SCRIPT NAME/INDEX/NUMBER OF SECONDS]"
23+
printf "${fmt_help}" \
24+
"-h, --help, help" "Print the help page." \
25+
"-l, --list, list" "List all available scripts." \
26+
"-r, --random, random" "Show a random image. It only picks image that fit within the terminal window." \
27+
"-e, --exec, exec" "Show an image by SCRIPT NAME or INDEX." \
28+
"-s, --slideshow, slideshow" "Run a slideshow showing a new image every NUMBER OF SECONDS. It is responsive to the terminal width." \
29+
"-w, --width, width" "Show the terminal width. It is shown as a size e.g 'xs' for extra small,and as a width in columns. This can be used to grade the size of the output of your scripts."
30+
}
31+
32+
function _list() {
33+
echo "There are ${length_scripts} installed scripts:"
34+
echo "${list_scripts}"
35+
}
36+
37+
function _terminal_width() {
38+
cols="$( _terminal_cols)"
39+
40+
if [[ $cols -lt 40 ]]; then
41+
echo 'xs'
42+
elif [[ $cols -ge 40 && $cols -lt 60 ]]; then
43+
echo 's'
44+
elif [[ $cols -ge 60 && $cols -lt 80 ]]; then
45+
echo 'm'
46+
elif [[ $cols -ge 80 && $cols -lt 100 ]]; then
47+
echo 'l'
48+
else
49+
echo 'xl'
50+
fi
51+
}
52+
53+
54+
function _terminal_cols() {
55+
cols="$( stty size | awk '{print $2}')"
56+
echo $cols
57+
}
58+
59+
function _random() {
60+
size=$(_terminal_width)
61+
file_pattern=".*"
62+
63+
if [[ "$size" == "xs" ]]; then
64+
file_pattern=".*-xs$"
65+
elif [[ "$size" == "s" ]]; then
66+
file_pattern=".*-(xs|s)$"
67+
elif [[ $size == "m" ]]; then
68+
file_pattern=".*-(xs|s|m)$"
69+
elif [[ $size == "l" ]]; then
70+
file_pattern=".*-(xs|s|m|l)$"
71+
fi
72+
73+
files=($(find "${dir_scripts}" -type f | grep -P "${file_pattern}"))
74+
num_of_files=${#files[@]}
75+
76+
declare -i random_index=$RANDOM%num_of_files
77+
[[ $random_index -eq 0 ]] && random_index=1
78+
79+
random_script="${files["$random_index"]}"
80+
81+
# uncomment next line to show filename
82+
# echo " $(basename $random_script)"
83+
84+
exec "${random_script}"
85+
}
86+
87+
function _has_script() {
88+
echo $(find "${dir_scripts}" -type f -name "$1")
89+
}
90+
91+
function _run_by_name() {
92+
if [[ "$1" == "random" ]]; then
93+
_random
94+
else
95+
script=$(_has_script "$1")
96+
97+
if [[ -n "$script" ]]; then
98+
exec "$script"
99+
else
100+
echo "Input error: No script innamed $1."
101+
exit 1
102+
fi
103+
fi
104+
}
105+
106+
function _run_by_index() {
107+
if [[ "$1" -gt 0 && "$1" -le "${length_scripts}" ]]; then
108+
index=$(expr ${1} - 1)
109+
script="${list_scripts_fpath["${index}"]}"
110+
exec "${script}"
111+
else
112+
echo "Input error: No script indexed $1."
113+
exit 1
114+
fi
115+
}
116+
117+
function _slideshow() {
118+
if [[ "$1" =~ ^[0-9]+$ ]]; then
119+
echo " Press <CTRL+C> to exit."
120+
while true
121+
do
122+
fetching random
123+
sleep "$1s"
124+
done;
125+
else
126+
echo "Input error. Must supply a number of seconds."
127+
exit 1
128+
fi
129+
130+
}
131+
132+
function _run_script() {
133+
if [[ "$1" =~ ^[0-9]+$ ]]; then
134+
_run_by_index "$1"
135+
else
136+
_run_by_name "$1"
137+
fi
138+
}
139+
140+
case "$#" in
141+
0)
142+
_help
143+
;;
144+
1)
145+
case "$1" in
146+
-h | --help | help)
147+
_help
148+
;;
149+
-l | --list | list)
150+
_list
151+
;;
152+
-r | --random | random)
153+
_random
154+
;;
155+
-w | --width | width)
156+
echo "size: $(_terminal_width)"
157+
echo "$(_terminal_cols) columns wide"
158+
;;
159+
*)
160+
echo "Input error."
161+
exit 1
162+
;;
163+
esac
164+
;;
165+
2)
166+
if [[ "$1" == "-e" || "$1" == "--exec" || "$1" == "exec" ]]; then
167+
_run_script "$2"
168+
elif [[ "$1" == "-s" || "$1" == "--slideshow" || "$1" == "slideshow" ]]; then
169+
_slideshow "$2"
170+
else
171+
echo "Input error."
172+
exit 1
173+
fi
174+
;;
175+
*)
176+
echo "Input error, too many arguments."
177+
exit 1
178+
;;
179+
esac

0 commit comments

Comments
 (0)