feat(zsh): add mkcd() & new icat() function

chezmoi
sgoudham 2 years ago
parent d0cdfd2bbb
commit bb24b336bc
Signed by: hammy
GPG Key ID: 44E818FD5457EEA4

@ -43,19 +43,64 @@ export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quo
# Color support of 'ls' and also add aliases # Color support of 'ls' and also add aliases
if [ -x /usr/bin/dircolors ]; then if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto' alias ls='ls --color=auto'
alias grep='grep --color=auto' alias grep='grep --color=auto'
fi fi
# Make directories & cd into them
function mkcd() {
mkdir -p $@ && cd ${@:$#}
}
# Display images in the terminal # Display images in the terminal
function icat() { function icat() {
if [ "$TERM_PROGRAM" = "WezTerm" ]; then function display() {
wezterm imgcat "$@" if [[ "$TERM_PROGRAM" == "WezTerm" ]]; then
elif [ "$TERM" = "xterm-kitty" ]; then cat - | wezterm imgcat
kitty +kitten icat "$@" elif [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
cat - | $(alias imgcat | cut -d "=" -f2-)
elif [[ "$TERM" = "xterm-kitty" ]]; then
cat - | kitty +kitten icat
else
echo "No image viewer defined for this terminal" && return 1
fi
return 0
}
function displaySVG() {
[[ ! -x "$(command -v convert)" ]] && echo "convert not found, install imagemagick" && return 1
convert -background none -density 192 - png:- | display
}
function displayVID() {
ffmpeg -i "$1" -vf scale=720:-1 -r 10 -f image2pipe -vcodec ppm - &>/dev/null | convert -delay 10 -loop 1 - gif:- | display
}
if [ ! -t 0 ]; then
input="$(cat - | base64)"
headers="$(echo "$input" | base64 -d | file - --mime-type | cut -d " " -f2-)"
case $headers in
*svg*) echo "$input" | base64 -d | displaySVG ;;
*video*) echo "haven't figured this part out yet" && return 1;;
*image*) echo "$input" | base64 -d | display ;;
*) echo "Unknown file type" && return 1 ;;
esac
elif [[ "$1" == http* ]]; then
case "$(curl -sSLI "$1" | grep -i "^content-type:")" in
*svg*) curl -fsSL "$1" | displaySVG ;;
*video*) echo "haven't figured this part out yet" && return 1;;
*image*) curl -fsSL "$1" | display ;;
*) echo "Unknown file type" && return 1 ;;
esac
else else
echo 'No image viewer defined for this terminal' [[ -z "$1" ]] && echo "Usage: icat <file|url>" && return 1
[[ ! -f "$1" ]] && echo "File not found: $1" && return 1
case "$(file -b --mime-type "$1")" in
*svg*) cat "$1" | displaySVG ;;
*video*) displayVID $1 ;;
*image*) cat "$1" | display ;;
*) echo "Unknown file type" && return 1 ;;
esac
fi fi
} }

Loading…
Cancel
Save