mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-23 01:17:24 +08:00
Compare commits
3 Commits
efafef8495
...
d6f84f3e7d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6f84f3e7d | ||
|
|
47767bd03c | ||
|
|
f1764f8a56 |
@ -1,7 +1,7 @@
|
|||||||
certifi==2024.7.4
|
certifi==2024.7.4
|
||||||
charset-normalizer==3.3.2
|
charset-normalizer==3.3.2
|
||||||
idna==3.7
|
idna==3.7
|
||||||
PyYAML==6.0.1
|
PyYAML==6.0.2
|
||||||
requests==2.32.3
|
requests==2.32.3
|
||||||
semver==3.0.2
|
semver==3.0.2
|
||||||
urllib3==2.2.2
|
urllib3==2.2.2
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
# catimg
|
# catimg
|
||||||
|
|
||||||
Plugin for displaying images on the terminal using the `catimg.sh` script provided by [posva](https://github.com/posva/catimg)
|
Plugin for displaying images on the terminal using the `catimg.sh` script provided by
|
||||||
|
[posva](https://github.com/posva/catimg)
|
||||||
|
|
||||||
To use it, add `catimg` to the plugins array in your zshrc file:
|
To use it, add `catimg` to the plugins array in your zshrc file:
|
||||||
|
|
||||||
@ -10,7 +11,7 @@ plugins=(... catimg)
|
|||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- `convert` (ImageMagick)
|
- `magick convert` (ImageMagick)
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
|
|||||||
@ -9,9 +9,11 @@
|
|||||||
|
|
||||||
|
|
||||||
function catimg() {
|
function catimg() {
|
||||||
if [[ -x `which convert` ]]; then
|
if (( $+commands[magick] )); then
|
||||||
zsh $ZSH/plugins/catimg/catimg.sh $@
|
CONVERT_CMD="magick" zsh $ZSH/plugins/catimg/catimg.sh $@
|
||||||
|
elif (( $+commands[convert] )); then
|
||||||
|
CONVERT_CMD="convert" zsh $ZSH/plugins/catimg/catimg.sh $@
|
||||||
else
|
else
|
||||||
echo "catimg need convert (ImageMagick) to work)"
|
echo "catimg need magick/convert (ImageMagick) to work)"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,10 @@
|
|||||||
# GitHub: https://github.com/posva/catimg #
|
# GitHub: https://github.com/posva/catimg #
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
|
# this should come from outside, either `magick` or `convert`
|
||||||
|
# from imagemagick v7 and ahead `convert` is deprecated
|
||||||
|
: ${CONVERT_CMD:=convert}
|
||||||
|
|
||||||
function help() {
|
function help() {
|
||||||
echo "Usage catimg [-h] [-w width] [-c char] img"
|
echo "Usage catimg [-h] [-w width] [-c char] img"
|
||||||
echo "By default char is \" \" and w is the terminal width"
|
echo "By default char is \" \" and w is the terminal width"
|
||||||
@ -43,23 +47,23 @@ if [ ! "$WIDTH" ]; then
|
|||||||
else
|
else
|
||||||
COLS=$(expr $WIDTH "/" $(echo -n "$CHAR" | wc -c))
|
COLS=$(expr $WIDTH "/" $(echo -n "$CHAR" | wc -c))
|
||||||
fi
|
fi
|
||||||
WIDTH=$(convert "$IMG" -print "%w\n" /dev/null)
|
WIDTH=$($CONVERT_CMD "$IMG" -print "%w\n" /dev/null)
|
||||||
if [ "$WIDTH" -gt "$COLS" ]; then
|
if [ "$WIDTH" -gt "$COLS" ]; then
|
||||||
WIDTH=$COLS
|
WIDTH=$COLS
|
||||||
fi
|
fi
|
||||||
|
|
||||||
REMAP=""
|
REMAP=""
|
||||||
if convert "$IMG" -resize $COLS\> +dither -remap $COLOR_FILE /dev/null ; then
|
if $CONVERT_CMD "$IMG" -resize $COLS\> +dither -remap $COLOR_FILE /dev/null ; then
|
||||||
REMAP="-remap $COLOR_FILE"
|
REMAP="-remap $COLOR_FILE"
|
||||||
else
|
else
|
||||||
echo "The version of convert is too old, don't expect good results :(" >&2
|
echo "The version of convert is too old, don't expect good results :(" >&2
|
||||||
#convert "$IMG" -colors 256 PNG8:tmp.png
|
# $CONVERT_CMD "$IMG" -colors 256 PNG8:tmp.png
|
||||||
#IMG="tmp.png"
|
# IMG="tmp.png"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Display the image
|
# Display the image
|
||||||
I=0
|
I=0
|
||||||
convert "$IMG" -resize $COLS\> +dither `echo $REMAP` txt:- 2>/dev/null |
|
$CONVERT_CMD "$IMG" -resize $COLS\> +dither `echo $REMAP` txt:- 2>/dev/null |
|
||||||
sed -e 's/.*none.*/NO NO NO/g' -e '1d;s/^.*(\(.*\)[,)].*$/\1/g;y/,/ /' |
|
sed -e 's/.*none.*/NO NO NO/g' -e '1d;s/^.*(\(.*\)[,)].*$/\1/g;y/,/ /' |
|
||||||
while read R G B f; do
|
while read R G B f; do
|
||||||
if [ ! "$R" = "NO" ]; then
|
if [ ! "$R" = "NO" ]; then
|
||||||
|
|||||||
@ -42,12 +42,12 @@ colorize_cat() {
|
|||||||
ZSH_COLORIZE_STYLE="emacs"
|
ZSH_COLORIZE_STYLE="emacs"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use stdin if no arguments have been passed.
|
# Use stdin if stdin is not attached to a terminal.
|
||||||
if [ $# -eq 0 ]; then
|
if [ ! -t 0 ]; then
|
||||||
if [[ "$ZSH_COLORIZE_TOOL" == "pygmentize" ]]; then
|
if [[ "$ZSH_COLORIZE_TOOL" == "pygmentize" ]]; then
|
||||||
pygmentize -O style="$ZSH_COLORIZE_STYLE" -g
|
pygmentize -O style="$ZSH_COLORIZE_STYLE" -g
|
||||||
else
|
else
|
||||||
chroma --style="$ZSH_COLORIZE_STYLE" --formatter="${ZSH_COLORIZE_CHROMA_FORMATTER:-terminal}"
|
chroma --style="$ZSH_COLORIZE_STYLE" --formatter="${ZSH_COLORIZE_CHROMA_FORMATTER:-terminal}" "$@"
|
||||||
fi
|
fi
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user