misc: cleanup

This commit is contained in:
Dylan Araps 2018-06-03 16:40:06 +10:00
parent ab01e65fad
commit 96bd33c2a0
1 changed files with 58 additions and 56 deletions

View File

@ -2708,28 +2708,32 @@ get_term() {
[[ "$TERM" == "tw52" || "$TERM" == "tw100" ]] && \ [[ "$TERM" == "tw52" || "$TERM" == "tw100" ]] && \
term="TosWin2" term="TosWin2"
[[ "$SSH_CONNECTION" ]] && \
term="$SSH_TTY"
# Check $PPID for terminal emulator. # Check $PPID for terminal emulator.
while [[ -z "$term" ]]; do while [[ -z "$term" ]]; do
if [[ "$SSH_CONNECTION" ]]; then
term="$SSH_TTY"; break
else
parent="$(get_ppid "$parent")" parent="$(get_ppid "$parent")"
[[ -z "$parent" ]] && break [[ -z "$parent" ]] && break
name="$(get_process_name "$parent")" name="$(get_process_name "$parent")"
case "${name// }" in case "${name// }" in
"${SHELL/*\/}"|*"sh"|"screen"|"su"*) ;; "${SHELL/*\/}"|*"sh"|"screen"|"su"*) ;;
"login"* | *"Login"* | "init" | "(init)") term="$(tty)" ;;
"ruby" | "1" | "systemd" | "sshd"* | "python"* |\ "login"*|*"Login"*|"init"|"(init)")
"USER"*"PID"* | "kdeinit"* | "launchd"*) term="$(tty)"
;;
"ruby"|"1"|"systemd"|"sshd"*|"python"*|"USER"*"PID"*|"kdeinit"*|"launchd"*)
break break
;; ;;
"gnome-terminal-") term="gnome-terminal" ;; "gnome-terminal-") term="gnome-terminal" ;;
*"nvim") term="Neovim Terminal" ;; *"nvim") term="Neovim Terminal" ;;
*"NeoVimServer"*) term="VimR Terminal" ;; *"NeoVimServer"*) term="VimR Terminal" ;;
*"tmux"*) term="tmux" ;; *"tmux"*) term="tmux" ;;
*) term="${name##*/}" ;; *) term="${name##*/}" ;;
esac esac
fi
done done
# Log that the function was run. # Log that the function was run.
@ -3351,7 +3355,7 @@ image_backend() {
printf '\e[2J\e[H' printf '\e[2J\e[H'
get_image_size get_image_size
make_thumbnail make_thumbnail
display_image display_image || to_off "Image: $image_backend failed to display the image."
;; ;;
*) *)
@ -3708,54 +3712,52 @@ make_thumbnail() {
display_image() { display_image() {
case "$image_backend" in case "$image_backend" in
"caca") "caca")
img2txt -W "$((width / font_width)))" \ img2txt \
-W "$((width / font_width)))" \
-H "$((height / font_height))" \ -H "$((height / font_height))" \
--gamma=0.6 "$image" ||\ --gamma=0.6 \
to_off "Image: libcaca failed to display the image." "$image"
;; ;;
"jp2a") "jp2a")
jp2a --width="$((width / font_width))" \ jp2a \
--width="$((width / font_width))" \
--height="$((height / font_height))" \ --height="$((height / font_height))" \
--colors "$image" ||\ --colors \
to_off "Image: jp2a failed to display the image." "$image"
;; ;;
"kitty") "kitty")
kitty icat \ kitty icat \
--align left \ --align left \
--place "$((width / font_width))x$((height / font_height))\ --place "$((width/font_width))x$((height/font_height))@${xoffset}x${yoffset}" \
@${xoffset}x${yoffset}" \ "$image"
"$image" ||\
to_off "Image: kitty failed to display the image."
;; ;;
"pixterm") "pixterm")
pixterm -tc "$((width / font_width))" \ pixterm \
-tc "$((width / font_width))" \
-tr "$((height / font_height))" \ -tr "$((height / font_height))" \
"$image" ||\ "$image"
to_off "Image: pixterm failed to display the image."
;; ;;
"sixel") "sixel")
img2sixel -w "$width" \ img2sixel \
-w "$width" \
-h "$height" \ -h "$height" \
"$image" ||\ "$image"
to_off "Image: libsixel failed to display the image."
;; ;;
"termpix") "termpix")
termpix --width "$((width / font_width))" \ termpix \
--width "$((width / font_width))" \
--height "$((height / font_height))" \ --height "$((height / font_height))" \
"$image" ||\ "$image"
to_off "Image: termpix failed to display the image."
;; ;;
"iterm2") "iterm2")
image="$(base64 < "$image")"
printf -v iterm_cmd '\e]1337;File=width=%spx;height=%spx;inline=1:%s' \ printf -v iterm_cmd '\e]1337;File=width=%spx;height=%spx;inline=1:%s' \
"$width" "$height" "$image" "$width" "$height" "$(base64 < "$image")"
# Tmux requires an additional escape sequence for this to work. # Tmux requires an additional escape sequence for this to work.
[[ -n "$TMUX" ]] && printf -v iterm_cmd '\ePtmux;\e%b\e'\\ "$iterm_cmd" [[ -n "$TMUX" ]] && printf -v iterm_cmd '\ePtmux;\e%b\e'\\ "$iterm_cmd"
@ -3764,8 +3766,9 @@ display_image() {
;; ;;
"tycat") "tycat")
tycat -g "${width}x${height}" "$image" ||\ tycat \
to_off "Image: tycat failed to display the image." -g "${width}x${height}" \
"$image"
;; ;;
"w3m") "w3m")
@ -3776,8 +3779,7 @@ display_image() {
# appearing in specific terminal emulators. # appearing in specific terminal emulators.
sleep 0.05 sleep 0.05
printf '%b\n%s;\n%s\n' "0;1;$xoffset;$yoffset;$width;$height;;;;;$image" 3 4 |\ printf '%b\n%s;\n%s\n' "0;1;$xoffset;$yoffset;$width;$height;;;;;$image" 3 4 |\
"${w3m_img_path:-false}" -bg "$background_color" &>/dev/null ||\ "${w3m_img_path:-false}" -bg "$background_color" &>/dev/null
to_off "Image: w3m-img failed to display the image."
;; ;;
esac esac
} }