在服务器上浏览图片

2024-06-24 12:38
文章标签 服务器 浏览 图片

本文主要是介绍在服务器上浏览图片,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

@StarSky 2018-10-26 15:09 字数 15971 阅读 28

https://www.zybuluo.com/StarSky/note/1294871 来源

2018-09-27 线上服务器安装 imgcat

Tool


 

  • 2018-09-27 线上服务器安装 imgcat
      • 0. 准备文件:iterm2_shell_integration.bash
      • 1. 在有权限的文件夹下新建文件 install_shell_integration_and_utilities.sh
      • 2. 新建文件 ~/.iterm2/imgcat
      • 3. 新建文件~/.iterm2/it2dl
      • 4. 新建 ~/.iterm2/imgls
      • 5. 执行 install_shell_integration_and_utilities.sh
      • 6. 退出 session ,并重新登陆

 

iterm2 的新特性支持 img display, 该特性可以在线看图,无需将图片下载到本地 
因为线上服务器不能链接到外网,整理安装步骤如下。 
?:能链外网的情况下直接 bash install_shell_integration_and_utilities.sh

0. 准备文件:iterm2_shell_integration.bash

vim iterm2_shell_integration.bash
 
  1. #!/bin/bash
  2. # This is based on "preexec.bash" but is customized for iTerm2.
  3.  
  4. # Note: this module requires 2 bash features which you must not otherwise be
  5. # using: the "DEBUG" trap, and the "PROMPT_COMMAND" variable. iterm2_preexec_install
  6. # will override these and if you override one or the other this _will_ break.
  7.  
  8. # This is known to support bash3, as well as *mostly* support bash2.05b. It
  9. # has been tested with the default shells on macOS 10.4 "Tiger", Ubuntu 5.10
  10. # "Breezy Badger", Ubuntu 6.06 "Dapper Drake", and Ubuntu 6.10 "Edgy Eft".
  11.  
  12. # tmux and screen are not supported; even using the tmux hack to get escape
  13. # codes passed through, ncurses interferes and the cursor isn't in the right
  14. # place at the time it's passed through.
  15. if [[ "$TERM" != screen && "$ITERM_SHELL_INTEGRATION_INSTALLED" = "" && "$-" == *i* ]]; then
  16. ITERM_SHELL_INTEGRATION_INSTALLED=Yes
  17. # Saved copy of your PS1. This is used to detect if the user changes PS1
  18. # directly. ITERM_PREV_PS1 will hold the last value that this script set PS1 to
  19. # (including various custom escape sequences).
  20. ITERM_PREV_PS1="$PS1"
  21.  
  22. # This variable describes whether we are currently in "interactive mode";
  23. # i.e. whether this shell has just executed a prompt and is waiting for user
  24. # input. It documents whether the current command invoked by the trace hook is
  25. # run interactively by the user; it's set immediately after the prompt hook,
  26. # and unset as soon as the trace hook is run.
  27. ITERM_PREEXEC_INTERACTIVE_MODE=""
  28.  
  29. # Default do-nothing implementation of preexec.
  30. function preexec () {
  31. true
  32. }
  33.  
  34. # Default do-nothing implementation of precmd.
  35. function precmd () {
  36. true
  37. }
  38.  
  39. # This function is installed as the PROMPT_COMMAND; it is invoked before each
  40. # interactive prompt display. It sets a variable to indicate that the prompt
  41. # was just displayed, to allow the DEBUG trap, below, to know that the next
  42. # command is likely interactive.
  43. function iterm2_preexec_invoke_cmd () {
  44. # Ideally we could do this in iterm2_preexec_install but CentOS 7.2 and
  45. # RHEL 7.2 complain about bashdb-main.inc not existing if you do that
  46. # (issue 4160).
  47. # *BOTH* of these options need to be set for the DEBUG trap to be invoked
  48. # in ( ) subshells. This smells like a bug in bash to me. The null stackederr
  49. # redirections are to quiet errors on bash2.05 (i.e. OSX's default shell)
  50. # where the options can't be set, and it's impossible to inherit the trap
  51. # into subshells.
  52. set -o functrace > /dev/null 2>&1
  53. shopt -s extdebug > /dev/null 2>&1
  54.  
  55. \local s=$?
  56. last_hist_ent="$(HISTTIMEFORMAT= builtin history 1)";
  57. precmd;
  58. # This is an iTerm2 addition to try to work around a problem in the
  59. # original preexec.bash.
  60. # When the PS1 has command substitutions, this gets invoked for each
  61. # substitution and each command that's run within the substitution, which
  62. # really adds up. It would be great if we could do something like this at
  63. # the end of this script:
  64. # PS1="$(iterm2_prompt_prefix)$PS1($iterm2_prompt_suffix)"
  65. # and have iterm2_prompt_prefix set a global variable that tells precmd not to
  66. # output anything and have iterm2_prompt_suffix reset that variable.
  67. # Unfortunately, command substitutions run in subshells and can't
  68. # communicate to the outside world.
  69. # Instead, we have this workaround. We save the original value of PS1 in
  70. # $ITERM_ORIG_PS1. Then each time this function is run (it's called from
  71. # PROMPT_COMMAND just before the prompt is shown) it will change PS1 to a
  72. # string without any command substitutions by doing eval on ITERM_ORIG_PS1. At
  73. # this point ITERM_PREEXEC_INTERACTIVE_MODE is still the empty string, so preexec
  74. # won't produce output for command substitutions.
  75.  
  76. # The first time this is called ITERM_ORIG_PS1 is unset. This tests if the variable
  77. # is undefined (not just empty) and initializes it. We can't initialize this at the
  78. # top of the script because it breaks with liquidprompt. liquidprompt wants to
  79. # set PS1 from a PROMPT_COMMAND that runs just before us. Setting ITERM_ORIG_PS1
  80. # at the top of the script will overwrite liquidprompt's PS1, whose value would
  81. # never make it into ITERM_ORIG_PS1. Issue 4532. It's important to check
  82. # if it's undefined before checking if it's empty because some users have
  83. # bash set to error out on referencing an undefined variable.
  84. if [ -z "${ITERM_ORIG_PS1+xxx}" ]
  85. then
  86. # ITERM_ORIG_PS1 always holds the last user-set value of PS1.
  87. # You only get here on the first time iterm2_preexec_invoke_cmd is called.
  88. export ITERM_ORIG_PS1="$PS1"
  89. fi
  90.  
  91. if [[ "$PS1" != "$ITERM_PREV_PS1" ]]
  92. then
  93. export ITERM_ORIG_PS1="$PS1"
  94. fi
  95.  
  96. # Get the value of the prompt prefix, which will change $?
  97. \local iterm2_prompt_prefix_value="$(iterm2_prompt_prefix)"
  98.  
  99. # Add the mark unless the prompt includes '$(iterm2_prompt_mark)' as a substring.
  100. if [[ $ITERM_ORIG_PS1 != *'$(iterm2_prompt_mark)'* ]]
  101. then
  102. iterm2_prompt_prefix_value="$iterm2_prompt_prefix_value$(iterm2_prompt_mark)"
  103. fi
  104.  
  105. # Send escape sequences with current directory and hostname.
  106. iterm2_print_state_data
  107.  
  108. # Reset $? to its saved value, which might be used in $ITERM_ORIG_PS1.
  109. sh -c "exit $s"
  110.  
  111. # Set PS1 to various escape sequences, the user's preferred prompt, and more escape sequences.
  112. export PS1="\[$iterm2_prompt_prefix_value\]$ITERM_ORIG_PS1\[$(iterm2_prompt_suffix)\]"
  113.  
  114. # Save the value we just set PS1 to so if the user changes PS1 we'll know and we can update ITERM_ORIG_PS1.
  115. export ITERM_PREV_PS1="$PS1"
  116. sh -c "exit $s"
  117.  
  118. # This must be the last line in this function, or else
  119. # iterm2_preexec_invoke_exec will do its thing at the wrong time.
  120. ITERM_PREEXEC_INTERACTIVE_MODE="yes";
  121. }
  122.  
  123. # This function is installed as the DEBUG trap. It is invoked before each
  124. # interactive prompt display. Its purpose is to inspect the current
  125. # environment to attempt to detect if the current command is being invoked
  126. # interactively, and invoke 'preexec' if so.
  127. function iterm2_preexec_invoke_exec () {
  128. if [ ! -t 1 ]
  129. then
  130. # We're in a piped subshell (STDOUT is not a TTY) like
  131. # (echo -n A; sleep 1; echo -n B) | wc -c
  132. # ...which should return "2".
  133. return
  134. fi
  135. if [[ -n "${COMP_LINE:-}" ]]
  136. then
  137. # We're in the middle of a completer. This obviously can't be
  138. # an interactively issued command.
  139. return
  140. fi
  141. if [[ -z "$ITERM_PREEXEC_INTERACTIVE_MODE" ]]
  142. then
  143. # We're doing something related to displaying the prompt. Let the
  144. # prompt set the title instead of me.
  145. return
  146. else
  147. # If we're in a subshell, then the prompt won't be re-displayed to put
  148. # us back into interactive mode, so let's not set the variable back.
  149. # In other words, if you have a subshell like
  150. # (sleep 1; sleep 2)
  151. # You want to see the 'sleep 2' as a set_command_title as well.
  152. if [[ 0 -eq "$BASH_SUBSHELL" ]]
  153. then
  154. ITERM_PREEXEC_INTERACTIVE_MODE=""
  155. fi
  156. fi
  157. if [[ "iterm2_preexec_invoke_cmd" == "$BASH_COMMAND" ]]
  158. then
  159. # Sadly, there's no cleaner way to detect two prompts being displayed
  160. # one after another. This makes it important that PROMPT_COMMAND
  161. # remain set _exactly_ as below in iterm2_preexec_install. Let's switch back
  162. # out of interactive mode and not trace any of the commands run in
  163. # precmd.
  164.  
  165. # Given their buggy interaction between BASH_COMMAND and debug traps,
  166. # versions of bash prior to 3.1 can't detect this at all.
  167. ITERM_PREEXEC_INTERACTIVE_MODE=""
  168. return
  169. fi
  170.  
  171. # In more recent versions of bash, this could be set via the "BASH_COMMAND"
  172. # variable, but using history here is better in some ways: for example, "ps
  173. # auxf | less" will show up with both sides of the pipe if we use history,
  174. # but only as "ps auxf" if not.
  175. hist_ent="$(HISTTIMEFORMAT= builtin history 1)";
  176. \local prev_hist_ent="${last_hist_ent}";
  177. last_hist_ent="${hist_ent}";
  178. if [[ "${prev_hist_ent}" != "${hist_ent}" ]]; then
  179. \local this_command="$(echo "${hist_ent}" | sed -e "s/^[ ]*[0-9]*[ ]*//g")";
  180. else
  181. \local this_command="";
  182. fi;
  183.  
  184. # If none of the previous checks have earlied out of this function, then
  185. # the command is in fact interactive and we should invoke the user's
  186. # preexec hook with the running command as an argument.
  187. preexec "$this_command";
  188. }
  189.  
  190. # Execute this to set up preexec and precmd execution.
  191. function iterm2_preexec_install () {
  192. # Finally, install the actual traps.
  193. if ( [ x"${PROMPT_COMMAND:-}" = x ]); then
  194. PROMPT_COMMAND="iterm2_preexec_invoke_cmd";
  195. else
  196. # If there's a trailing semicolon folowed by spaces, remove it (issue 3358).
  197. PROMPT_COMMAND="$(echo -n $PROMPT_COMMAND | sed -e 's/; *$//'); iterm2_preexec_invoke_cmd";
  198. fi
  199. # The $_ is ignored, but prevents it from changing (issue 3932).
  200. trap 'iterm2_preexec_invoke_exec "$_"' DEBUG;
  201. }
  202.  
  203. # -- begin iTerm2 customization
  204.  
  205. function iterm2_begin_osc {
  206. printf "\033]"
  207. }
  208.  
  209. function iterm2_end_osc {
  210. printf "\007"
  211. }
  212.  
  213. # Runs after interactively edited command but before execution
  214. function preexec() {
  215. iterm2_begin_osc
  216. printf "133;C;"
  217. iterm2_end_osc
  218. # If PS1 still has the value we set it to in iterm2_preexec_invoke_cmd then
  219. # restore it to its original value. It might have changed if you have
  220. # another PROMPT_COMMAND (like liquidprompt) that modifies PS1.
  221. if [ -n "${ITERM_ORIG_PS1+xxx}" -a "$PS1" = "$ITERM_PREV_PS1" ]
  222. then
  223. export PS1="$ITERM_ORIG_PS1"
  224. fi
  225. iterm2_ran_preexec="yes"
  226. }
  227.  
  228. function precmd () {
  229. # Work around a bug in CentOS 7.2 where preexec doesn't run if you press
  230. # ^C while entering a command.
  231. if [[ -z "${iterm2_ran_preexec:-}" ]]
  232. then
  233. preexec ""
  234. fi
  235. iterm2_ran_preexec=""
  236. }
  237.  
  238. function iterm2_print_state_data() {
  239. iterm2_begin_osc
  240. printf "1337;RemoteHost=%s@%s" "$USER" "$iterm2_hostname"
  241. iterm2_end_osc
  242.  
  243. iterm2_begin_osc
  244. printf "1337;CurrentDir=%s" "$PWD"
  245. iterm2_end_osc
  246.  
  247. iterm2_print_user_vars
  248. }
  249.  
  250. # Usage: iterm2_set_user_var key value
  251. function iterm2_set_user_var() {
  252. iterm2_begin_osc
  253. printf "1337;SetUserVar=%s=%s" "$1" $(printf "%s" "$2" | base64 | tr -d '\n')
  254. iterm2_end_osc
  255. }
  256.  
  257. if [ -z "$(type -t iterm2_print_user_vars)" ] || [ "$(type -t iterm2_print_user_vars)" != function ]; then
  258. # iterm2_print_user_vars is not already defined. Provide a no-op default version.
  259. #
  260. # Users can write their own version of this function. It should call
  261. # iterm2_set_user_var but not produce any other output.
  262. function iterm2_print_user_vars() {
  263. true
  264. }
  265. fi
  266.  
  267. function iterm2_prompt_prefix() {
  268. iterm2_begin_osc
  269. printf "133;D;\$?"
  270. iterm2_end_osc
  271. }
  272.  
  273. function iterm2_prompt_mark() {
  274. iterm2_begin_osc
  275. printf "133;A"
  276. iterm2_end_osc
  277. }
  278.  
  279. function iterm2_prompt_suffix() {
  280. iterm2_begin_osc
  281. printf "133;B"
  282. iterm2_end_osc
  283. }
  284.  
  285. function iterm2_print_version_number() {
  286. iterm2_begin_osc
  287. printf "1337;ShellIntegrationVersion=5;shell=bash"
  288. iterm2_end_osc
  289. }
  290.  
  291.  
  292. # If hostname -f is slow on your system, set iterm2_hostname before sourcing this script.
  293. if [ -z "${iterm2_hostname:-}" ]; then
  294. iterm2_hostname=$(hostname -f 2>/dev/null)
  295. # some flavors of BSD (i.e. NetBSD and OpenBSD) don't have the -f option
  296. if [ $? -ne 0 ]; then
  297. iterm2_hostname=$(hostname)
  298. fi
  299. fi
  300. iterm2_preexec_install
  301.  
  302. # This is necessary so the first command line will have a hostname and current directory.
  303. iterm2_print_state_data
  304. iterm2_print_version_number
  305. fi

1. 在有权限的文件夹下新建文件 install_shell_integration_and_utilities.sh

vim install_shell_integration_and_utilities.sh
 
  1.  
  2. #!/bin/bash
  3.  
  4. function die() {
  5. echo "${1}"
  6. exit 1
  7. }
  8.  
  9. which printf > /dev/null 2>&1 || die "Shell integration requires the printf binary to be in your path."
  10.  
  11. SHELL=${SHELL##*/}
  12. URL=""
  13. HOME_PREFIX='${HOME}'
  14. SHELL_AND='&&'
  15. QUOTE=''
  16. if [ "${SHELL}" = tcsh ]
  17. then
  18. URL="https://iterm2.com/misc/tcsh_startup.in"
  19. SCRIPT="${HOME}/.login"
  20. QUOTE='"'
  21. ALIASES='alias imgcat ~/.iterm2/imgcat; alias it2dl ~/.iterm2/it2dl'
  22. fi
  23. if [ "${SHELL}" = zsh ]
  24. then
  25. URL="https://iterm2.com/misc/zsh_startup.in"
  26. SCRIPT="${HOME}/.zshrc"
  27. QUOTE='"'
  28. ALIASES='alias imgcat=~/.iterm2/imgcat; alias it2dl=~/.iterm2/it2dl'
  29. fi
  30. if [ "${SHELL}" = bash ]
  31. then
  32. URL="https://iterm2.com/misc/bash_startup.in"
  33. test -f "${HOME}/.bash_profile" && SCRIPT="${HOME}/.bash_profile" || SCRIPT="${HOME}/.profile"
  34. QUOTE='"'
  35. ALIASES='alias imgcat=~/.iterm2/imgcat; alias it2dl=~/.iterm2/it2dl'
  36. fi
  37. if [ "${SHELL}" = fish ]
  38. then
  39. echo "Make sure you have fish 2.2 or later. Your version is:"
  40. fish -v
  41.  
  42. URL="https://iterm2.com/misc/fish_startup.in"
  43. mkdir -p "${HOME}/.config/fish"
  44. SCRIPT="${HOME}/.config/fish/config.fish"
  45. HOME_PREFIX='{$HOME}'
  46. SHELL_AND='; and'
  47. ALIASES='alias imgcat=~/.iterm2/imgcat; alias it2dl=~/.iterm2/it2dl; alias imgls=~/.iterm2/imgls'
  48. fi
  49. if [ "${URL}" = "" ]
  50. then
  51. die "Your shell, ${SHELL}, is not supported yet. Only tcsh, zsh, bash, and fish are supported. Sorry!"
  52. exit 1
  53. fi
  54.  
  55. FILENAME="${HOME}/.iterm2_shell_integration.${SHELL}"
  56. RELATIVE_FILENAME="${HOME_PREFIX}/.iterm2_shell_integration.${SHELL}"
  57. echo "Downloading script from ${URL} and saving it to ${FILENAME}..."
  58. # curl -SsL "${URL}" > "${FILENAME}" || die "Couldn't download script from ${URL}"
  59. chmod +x "${FILENAME}"
  60. echo "Checking if ${SCRIPT} contains iterm2_shell_integration..."
  61. if ! grep iterm2_shell_integration "${SCRIPT}" > /dev/null 2>&1; then
  62. echo "Appending source command to ${SCRIPT}..."
  63. cat <<-EOF >> "${SCRIPT}"
  64.  
  65. test -e ${QUOTE}${RELATIVE_FILENAME}${QUOTE} ${SHELL_AND} source ${QUOTE}${RELATIVE_FILENAME}${QUOTE}
  66. EOF
  67. fi
  68.  
  69. test -d ~/.iterm2 || mkdir ~/.iterm2
  70. echo "Downloading imgcat..."
  71. # curl -SsL "https://iterm2.com/imgcat" > ~/.iterm2/imgcat
  72. chmod +x ~/.iterm2/imgcat
  73. echo "Downloading it2dl..."
  74. # curl -SsL "https://iterm2.com/it2dl" > ~/.iterm2/it2dl
  75. chmod +x ~/.iterm2/it2dl
  76. echo "Downloading imgls..."
  77. # curl -SsL "https://iterm2.com/imgls" > ~/.iterm2/imgls
  78. chmod +x ~/.iterm2/imgls
  79. echo "Adding aliases..."
  80. echo "$ALIASES" >> "${FILENAME}"
  81.  
  82. echo "Done."
  83. echo "--------------------------------------------------------------------------------"
  84. echo ""
  85. echo "The next time you log in, shell integration will be enabled."
  86. echo ""
  87. echo "You will also have these commands:"
  88. echo "imgcat filename"
  89. echo " Displays the image inline."
  90. echo "it2dl filename"
  91. echo " Downloads the specified file, saving it in your Downloads folder."
  92.  

2. 新建文件 ~/.iterm2/imgcat

 
  1. #!/bin/bash
  2.  
  3. # tmux requires unrecognized OSC sequences to be wrapped with DCS tmux;
  4. # <sequence> ST, and for all ESCs in <sequence> to be replaced with ESC ESC. It
  5. # only accepts ESC backslash for ST.
  6. function print_osc() {
  7. if [[ $TERM == screen* ]] ; then
  8. printf "\033Ptmux;\033\033]"
  9. else
  10. printf "\033]"
  11. fi
  12. }
  13.  
  14. # More of the tmux workaround described above.
  15. function print_st() {
  16. if [[ $TERM == screen* ]] ; then
  17. printf "\a\033\\"
  18. else
  19. printf "\a"
  20. fi
  21. }
  22.  
  23. # print_image filename inline base64contents print_filename
  24. # filename: Filename to convey to client
  25. # inline: 0 or 1
  26. # base64contents: Base64-encoded contents
  27. # print_filename: If non-empty, print the filename
  28. # before outputting the image
  29. function print_image() {
  30. print_osc
  31. printf '1337;File='
  32. if [[ -n "$1" ]]; then
  33. printf 'name='`printf "%s" "$1" | base64`";"
  34. fi
  35.  
  36. VERSION=$(base64 --version 2>&1)
  37. if [[ "$VERSION" =~ fourmilab ]]; then
  38. BASE64ARG=-d
  39. elif [[ "$VERSION" =~ GNU ]]; then
  40. BASE64ARG=-di
  41. else
  42. BASE64ARG=-D
  43. fi
  44.  
  45. printf "%s" "$3" | base64 $BASE64ARG | wc -c | awk '{printf "size=%d",$1}'
  46. printf ";inline=$2"
  47. printf ":"
  48. printf "%s" "$3"
  49. print_st
  50. printf '\n'
  51. if [[ -n "$4" ]]; then
  52. echo $1
  53. fi
  54. }
  55.  
  56. function error() {
  57. echo "ERROR: $*" 1>&2
  58. }
  59.  
  60. function show_help() {
  61. echo "Usage: imgcat [-p] filename ..." 1>& 2
  62. echo " or: cat filename | imgcat" 1>& 2
  63. }
  64.  
  65. ## Main
  66.  
  67. if [ -t 0 ]; then
  68. has_stdin=f
  69. else
  70. has_stdin=t
  71. fi
  72.  
  73. # Show help if no arguments and no stdin.
  74. if [ $has_stdin = f -a $# -eq 0 ]; then
  75. show_help
  76. exit
  77. fi
  78.  
  79. # Look for command line flags.
  80. while [ $# -gt 0 ]; do
  81. case "$1" in
  82. -h|--h|--help)
  83. show_help
  84. exit
  85. ;;
  86. -p|--p|--print)
  87. print_filename=1
  88. ;;
  89. -*)
  90. error "Unknown option flag: $1"
  91. show_help
  92. exit 1
  93. ;;
  94. *)
  95. if [ -r "$1" ] ; then
  96. has_stdin=f
  97. print_image "$1" 1 "$(base64 < "$1")" "$print_filename"
  98. else
  99. error "imgcat: $1: No such file or directory"
  100. exit 2
  101. fi
  102. ;;
  103. esac
  104. shift
  105. done
  106.  
  107. # Read and print stdin
  108. if [ $has_stdin = t ]; then
  109. print_image "" 1 "$(cat | base64)" ""
  110. fi
  111.  
  112. exit 0

3. 新建文件~/.iterm2/it2dl

 
  1. #!/bin/bash
  2. if [ $# -lt 1 ]; then
  3. echo "Usage: $(basename $0) file ..."
  4. exit 1
  5. fi
  6. for fn in "$@"
  7. do
  8. if [ -r "$fn" ] ; then
  9. [ -d "$fn" ] && { echo "$fn is a directory"; continue; }
  10. printf '\033]1337;File=name='`echo -n "$fn" | base64`";"
  11. wc -c "$fn" | awk '{printf "size=%d",$1}'
  12. printf ":"
  13. base64 < "$fn"
  14. printf '\a'
  15. else
  16. echo File $fn does not exist or is not readable.
  17. fi
  18. done

4. 新建 ~/.iterm2/imgls

 
  1. #!/bin/bash
  2. # tmux requires unrecognized OSC sequences to be wrapped with DCS tmux;
  3. # <sequence> ST, and for all ESCs in <sequence> to be replaced with ESC ESC. It
  4. # only accepts ESC backslash for ST.
  5. function print_osc() {
  6. if [ x"$TERM" = "xscreen" ] ; then
  7. printf "\033Ptmux;\033\033]"
  8. else
  9. printf "\033]"
  10. fi
  11. }
  12.  
  13. function check_dependency() {
  14. if ! (builtin command -V "$1" > /dev/null 2>& 1); then
  15. echo "imgcat: missing dependency: can't find $1" 1>& 2
  16. exit 1
  17. fi
  18. }
  19.  
  20. # More of the tmux workaround described above.
  21. function print_st() {
  22. if [ x"$TERM" = "xscreen" ] ; then
  23. printf "\a\033\\"
  24. else
  25. printf "\a"
  26. fi
  27. }
  28.  
  29. function list_file() {
  30. fn=$1
  31. dims=$(php -r 'if (!is_file($argv[1])) exit(1); $a = getimagesize($argv[1]); if ($a==FALSE) exit(1); else { echo $a[0] . "x" .$a[1]; exit(0); }' "$fn")
  32. rc=$?
  33. if [[ $rc == 0 ]] ; then
  34. print_osc
  35. printf '1337;File=name='`echo -n "$fn" | base64`";"
  36. wc -c "$fn" | awk '{printf "size=%d",$1}'
  37. printf ";inline=1;height=3;width=3;preserveAspectRatio=true"
  38. printf ":"
  39. base64 < "$fn"
  40. print_st
  41. if [ x"$TERM" == "xscreen" ] ; then
  42. # This works in plain-old tmux but does the wrong thing in iTerm2's tmux
  43. # integration mode. tmux doesn't know that the cursor moves when the
  44. # image code is sent, while iTerm2 does. I had to pick one, since
  45. # integration mode is undetectable, so I picked the failure mode that at
  46. # least produces useful output (there is just too much whitespace in
  47. # integration mode). This could be fixed by not moving the cursor while
  48. # in integration mode. A better fix would be for tmux to interpret the
  49. # image sequence, though.
  50. #
  51. # tl;dr: If you use tmux in integration mode, replace this with the printf
  52. # from the else clause.
  53. printf '\033[4C\033[Bx'
  54. else
  55. printf '\033[A'
  56. fi
  57. echo -n "$dims "
  58. ls -ld "$fn"
  59. else
  60. ls -ld "$fn"
  61. fi
  62. }
  63.  
  64. check_dependency php
  65. check_dependency base64
  66. check_dependency wc
  67.  
  68. if [ $# -eq 0 ]; then
  69. for fn in *
  70. do
  71. list_file "$fn"
  72. done < <(ls -ls)
  73. else
  74. for fn in "$@"
  75. do
  76. list_file "$fn"
  77. done
  78. fi

5. 执行 install_shell_integration_and_utilities.sh

bash install_shell_integration_and_utilities.sh

6. 退出 session ,并重新登陆

执行命令:

imgcat ****.jpg 

效果示例: 
示例

附: 
use rz in iterm2 
https://molunerfinn.com/iTerm2-lrzsz/

这篇关于在服务器上浏览图片的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1090174

相关文章

2024.6.24 IDEA中文乱码问题(服务器 控制台 TOMcat)实测已解决

1.问题产生原因: 1.文件编码不一致:如果文件的编码方式与IDEA设置的编码方式不一致,就会产生乱码。确保文件和IDEA使用相同的编码,通常是UTF-8。2.IDEA设置问题:检查IDEA的全局编码设置和项目编码设置是否正确。3.终端或控制台编码问题:如果你在终端或控制台看到乱码,可能是终端的编码设置问题。确保终端使用的是支持你的文件的编码方式。 2.解决方案: 1.File -> S

JAVA读取MongoDB中的二进制图片并显示在页面上

1:Jsp页面: <td><img src="${ctx}/mongoImg/show"></td> 2:xml配置: <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001

通过SSH隧道实现通过远程服务器上外网

搭建隧道 autossh -M 0 -f -D 1080 -C -N user1@remotehost##验证隧道是否生效,查看1080端口是否启动netstat -tuln | grep 1080## 测试ssh 隧道是否生效curl -x socks5h://127.0.0.1:1080 -I http://www.github.com 将autossh 设置为服务,隧道开机启动

【服务器运维】MySQL数据存储至数据盘

查看磁盘及分区 [root@MySQL tmp]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical)

【服务器运维】CentOS6 minimal 离线安装MySQL5.7

1.准备安装包(版本因人而异,所以下面的命令中版本省略,实际操作中用Tab自动补全就好了) cloog-ppl-0.15.7-1.2.el6.x86_64.rpmcpp-4.4.7-23.el6.x86_64.rpmgcc-4.4.7-23.el6.x86_64.rpmgcc-c++-4.4.7-23.el6.x86_64.rpmglibc-2.12-1.212.el6.x86_64.r

【服务器运维】CentOS7 minimal 离线安装 gcc perl vmware-tools

0. 本机在有网的情况下,下载CentOS镜像 https://www.centos.org/download/ 1. 取出rpm 有的情况可能不需要net-tools,但是如果出现跟ifconfig相关的错误,就把它安装上。另外如果不想升级内核版本的话,就找对应内核版本的rpm版本安装 perl-Time-Local-1.2300-2.el7.noarch.rpmperl-Tim

SQL Server中,always on服务器的相关操作

在SQL Server中,建立了always on服务,可用于数据库的同步备份,当数据库出现问题后,always on服务会自动切换主从服务器。 例如192.168.1.10为主服务器,12为从服务器,当主服务器出现问题后,always on自动将主服务器切换为12,保证数据库正常访问。 对于always on服务器有如下操作: 1、切换主从服务器:假如需要手动切换主从服务器时(如果两个服务

时间服务器中,适用于国内的 NTP 服务器地址,可用于时间同步或 Android 加速 GPS 定位

NTP 是什么?   NTP 是网络时间协议(Network Time Protocol),它用来同步网络设备【如计算机、手机】的时间的协议。 NTP 实现什么目的?   目的很简单,就是为了提供准确时间。因为我们的手表、设备等,经常会时间跑着跑着就有误差,或快或慢的少几秒,时间长了甚至误差过分钟。 NTP 服务器列表 最常见、熟知的就是 www.pool.ntp.org/zo

服务器雪崩的应对策略之----SQL优化

SQL语句的优化是数据库性能优化的重要方面,特别是在处理大规模数据或高频访问时。作为一个C++程序员,理解SQL优化不仅有助于编写高效的数据库操作代码,还能增强对系统性能瓶颈的整体把握。以下是详细的SQL语句优化技巧和策略: SQL优化 1. 选择合适的数据类型2. 使用索引3. 优化查询4. 范式化和反范式化5. 查询重写6. 使用缓存7. 优化数据库设计8. 分析和监控9. 调整配置1、