Skip to content

Commit

Permalink
Cleanups / Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhonas committed Apr 19, 2022
1 parent 129a3e5 commit 17344ed
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,28 @@ to replicate the experience of jumping onto a new BBS everytime I started my log
znap source yuhonas/zsh-ansimotd
# for antigen
antigen bundle 'yuhonas/zsh-ansimotd'
antigen bundle yuhonas/zsh-ansimotd
# manually
# Clone the repository and source it in your shell's rc file
```

### Getting some awesome ansi art to display
After installation you'll need to download some ansi art for it to randomly display, I suggest
finding a pack you like at [artscene](http://artscene.textfiles.com/artpacks/) and saving it
into the ansi art config directory
finding a pack you like at [artscene](http://artscene.textfiles.com/artpacks/) and unpacking it
into the ansi motd config directory

You can do this by

```
# using ansi_art_download (a function provided by the plugin) to
# download all zip files or ansi art from 1996
# using ansi_art_download (a function provided by the plugin) to download all zip files of ansi art from 1996
# and unpack them into the ansi motd config directory
ansi_art_download http://artscene.textfiles.com/artpacks/1996/
# manually
# Copy one or more zip files containg ansi art into your ansi art config directory
# Copy any `.ans`, `.img` or `.asc` files containg ansi art into your ansi art config directory
# which is derived from ${XDG_CONFIG_HOME:-~/.config}/ansimotd
```







### Note
The ansi art is assumed to use the [Code Page 437]( https://en.wikipedia.org/wiki/Code_page_437 ) character set
46 changes: 28 additions & 18 deletions zsh-ansimotd.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,51 @@ ANSI_ART_DIR="${XDG_CONFIG_HOME:-~/.config}/ansimotd"
[ -d "$ANSI_ART_DIR" ] || mkdir -p "$ANSI_ART_DIR"

# recursively download all zip's from the supplied url into our config dir
# eg. ansi_art_download http://artscene.textfiles.com/artpacks/1996/
# then unpack all displayable art
# eg. ansi_art_download "http://artscene.textfiles.com/artpacks/1996/"
function ansi_art_download {
wget --directory-prefix "$ANSI_ART_DIR" -r -np -l 1 -A zip "$1"
}

function ansi_art_random_zip {
find "$ANSI_ART_DIR" -type f -iname "*.zip" | shuf -n 1
wget --directory-prefix "$ANSI_ART_DIR" --recursive \
--no-verbose --no-clobber --no-parent --level= 1 --accept zip "$1"

cd $ANSI_ART_DIR

for file in **/*.zip
do
# UnZip 6.00
# no long flag options unfortunately
# so run with quiet mode, never overwite, case insensitive case match for the filename
# and extract to a directory of the zip's filename (minus extension)
unzip -q -n -C $file '*.ans' '*.img' '*.asc' -d $ANSI_ART_DIR/$file:r
done
}

# find a random piece of ansi art to display
function ansi_art_random_file {
if [ -n "$1" ]; then
unzip -Z1 "$1" | grep -i -E ".*\.(ans|asc|img)$" | shuf -n 1
fi;
find "$ANSI_ART_DIR" -type f \
-iname '*.ans' -or \
-iname '*.img' -or \
-iname '*.asc' |\
shuf -n 1
}

function ansi_art_random {
zip_filename="$(ansi_art_random_zip)"
ansi_filename="$(ansi_art_random_file "$zip_filename")"

ansi_filename="$(ansi_art_random_file)"

if [ -n "$ansi_filename" ]; then
# print and decode to stdout
unzip -q -p "$zip_filename" "$ansi_filename" | iconv -f 437
# convert from the original character set (Code page 437)
# see https://en.wikipedia.org/wiki/Code_page_437
iconv -f 437 < $ansi_filename

# save these incase the user wants to find them later
export ANSI_MOTD_ZIP="$zip_filename"
# record the filename in this session incase the user wants to find it later
export ANSI_MOTD_FILENAME="$ansi_filename"
else
# TODO: Swap these out with the calling script name
echo "\
zsh-ansimotd.plugin.zsh:
I couldn't find any ansi art to display, I tried looking in '$ANSI_ART_DIR' 😢
There are many artpacks available at http://artscene.textfiles.com/artpacks/
You can download an entire years worth of art using 'ansi_art_download'
eg. ansi_art_download http://artscene.textfiles.com/artpacks/1996/ " >&2
You can download an unpack one of these using 'ansi_art_download'
eg. ansi_art_download http://artscene.textfiles.com/artpacks/1996/" >&2
fi;
}

Expand Down

0 comments on commit 17344ed

Please sign in to comment.