在服务器上浏览图片

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

相关文章

服务器集群同步时间手记

1.时间服务器配置(必须root用户) (1)检查ntp是否安装 [root@node1 桌面]# rpm -qa|grep ntpntp-4.2.6p5-10.el6.centos.x86_64fontpackages-filesystem-1.41-1.1.el6.noarchntpdate-4.2.6p5-10.el6.centos.x86_64 (2)修改ntp配置文件 [r

使用opencv优化图片(画面变清晰)

文章目录 需求影响照片清晰度的因素 实现降噪测试代码 锐化空间锐化Unsharp Masking频率域锐化对比测试 对比度增强常用算法对比测试 需求 对图像进行优化,使其看起来更清晰,同时保持尺寸不变,通常涉及到图像处理技术如锐化、降噪、对比度增强等 影响照片清晰度的因素 影响照片清晰度的因素有很多,主要可以从以下几个方面来分析 1. 拍摄设备 相机传感器:相机传

Linux服务器Java启动脚本

Linux服务器Java启动脚本 1、初版2、优化版本3、常用脚本仓库 本文章介绍了如何在Linux服务器上执行Java并启动jar包, 通常我们会使用nohup直接启动,但是还是需要手动停止然后再次启动, 那如何更优雅的在服务器上启动jar包呢,让我们一起探讨一下吧。 1、初版 第一个版本是常用的做法,直接使用nohup后台启动jar包, 并将日志输出到当前文件夹n

Android 10.0 mtk平板camera2横屏预览旋转90度横屏拍照图片旋转90度功能实现

1.前言 在10.0的系统rom定制化开发中,在进行一些平板等默认横屏的设备开发的过程中,需要在进入camera2的 时候,默认预览图像也是需要横屏显示的,在上一篇已经实现了横屏预览功能,然后发现横屏预览后,拍照保存的图片 依然是竖屏的,所以说同样需要将图片也保存为横屏图标了,所以就需要看下mtk的camera2的相关横屏保存图片功能, 如何实现实现横屏保存图片功能 如图所示: 2.mtk

Spring MVC 图片上传

引入需要的包 <dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.1</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-

Prompt - 将图片的表格转换成Markdown

Prompt - 将图片的表格转换成Markdown 0. 引言1. 提示词2. 原始版本 0. 引言 最近尝试将图片中的表格转换成Markdown格式,需要不断条件和优化提示词。记录一下调整好的提示词,以后在继续优化迭代。 1. 提示词 英文版本: You are an AI assistant tasked with extracting the content of

速盾:直播 cdn 服务器带宽?

在当今数字化时代,直播已经成为了一种非常流行的娱乐和商业活动形式。为了确保直播的流畅性和高质量,直播平台通常会使用 CDN(Content Delivery Network,内容分发网络)服务器来分发直播流。而 CDN 服务器的带宽则是影响直播质量的一个重要因素。下面我们就来探讨一下速盾视角下的直播 CDN 服务器带宽问题。 一、直播对带宽的需求 高清视频流 直播通常需要传输高清视频

火语言RPA流程组件介绍--浏览网页

🚩【组件功能】:浏览器打开指定网址或本地html文件 配置预览 配置说明 网址URL 支持T或# 默认FLOW输入项 输入需要打开的网址URL 超时时间 支持T或# 打开网页超时时间 执行后后等待时间(ms) 支持T或# 当前组件执行完成后继续等待的时间 UserAgent 支持T或# User Agent中文名为用户代理,简称 UA,它是一个特殊字符串头,使得服务器

一种改进的red5集群方案的应用、基于Red5服务器集群负载均衡调度算法研究

转自: 一种改进的red5集群方案的应用: http://wenku.baidu.com/link?url=jYQ1wNwHVBqJ-5XCYq0PRligp6Y5q6BYXyISUsF56My8DP8dc9CZ4pZvpPz1abxJn8fojMrL0IyfmMHStpvkotqC1RWlRMGnzVL1X4IPOa_  基于Red5服务器集群负载均衡调度算法研究 http://ww

RTMP流媒体服务器 crtmpserver

http://www.oschina.net/p/crtmpserver crtmpserver又称rtmpd是Evostream Media Server(www.evostream.com)的社区版本采用GPLV3授权 其主要作用为一个高性能的RTMP流媒体服务器,可以实现直播与点播功能多终端支持功能,在特定情况下是FMS的良好替代品。 支持RTMP的一堆协议(RT