[关闭]
@StarSky 2018-11-12T03:33:27.000000Z 字数 15975 阅读 1533

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

Tool 工作日记


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

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

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

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

  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 [[ $TERM == screen* ]] ; then
  7. printf "\033Ptmux;\033\033]"
  8. else
  9. printf "\033]"
  10. fi
  11. }
  12. # More of the tmux workaround described above.
  13. function print_st() {
  14. if [[ $TERM == screen* ]] ; then
  15. printf "\a\033\\"
  16. else
  17. printf "\a"
  18. fi
  19. }
  20. # print_image filename inline base64contents print_filename
  21. # filename: Filename to convey to client
  22. # inline: 0 or 1
  23. # base64contents: Base64-encoded contents
  24. # print_filename: If non-empty, print the filename
  25. # before outputting the image
  26. function print_image() {
  27. print_osc
  28. printf '1337;File='
  29. if [[ -n "$1" ]]; then
  30. printf 'name='`printf "%s" "$1" | base64`";"
  31. fi
  32. VERSION=$(base64 --version 2>&1)
  33. if [[ "$VERSION" =~ fourmilab ]]; then
  34. BASE64ARG=-d
  35. elif [[ "$VERSION" =~ GNU ]]; then
  36. BASE64ARG=-di
  37. else
  38. BASE64ARG=-D
  39. fi
  40. printf "%s" "$3" | base64 $BASE64ARG | wc -c | awk '{printf "size=%d",$1}'
  41. printf ";inline=$2"
  42. printf ":"
  43. printf "%s" "$3"
  44. print_st
  45. printf '\n'
  46. if [[ -n "$4" ]]; then
  47. echo $1
  48. fi
  49. }
  50. function error() {
  51. echo "ERROR: $*" 1>&2
  52. }
  53. function show_help() {
  54. echo "Usage: imgcat [-p] filename ..." 1>& 2
  55. echo " or: cat filename | imgcat" 1>& 2
  56. }
  57. ## Main
  58. if [ -t 0 ]; then
  59. has_stdin=f
  60. else
  61. has_stdin=t
  62. fi
  63. # Show help if no arguments and no stdin.
  64. if [ $has_stdin = f -a $# -eq 0 ]; then
  65. show_help
  66. exit
  67. fi
  68. # Look for command line flags.
  69. while [ $# -gt 0 ]; do
  70. case "$1" in
  71. -h|--h|--help)
  72. show_help
  73. exit
  74. ;;
  75. -p|--p|--print)
  76. print_filename=1
  77. ;;
  78. -*)
  79. error "Unknown option flag: $1"
  80. show_help
  81. exit 1
  82. ;;
  83. *)
  84. if [ -r "$1" ] ; then
  85. has_stdin=f
  86. print_image "$1" 1 "$(base64 < "$1")" "$print_filename"
  87. else
  88. error "imgcat: $1: No such file or directory"
  89. exit 2
  90. fi
  91. ;;
  92. esac
  93. shift
  94. done
  95. # Read and print stdin
  96. if [ $has_stdin = t ]; then
  97. print_image "" 1 "$(cat | base64)" ""
  98. fi
  99. 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. function check_dependency() {
  13. if ! (builtin command -V "$1" > /dev/null 2>& 1); then
  14. echo "imgcat: missing dependency: can't find $1" 1>& 2
  15. exit 1
  16. fi
  17. }
  18. # More of the tmux workaround described above.
  19. function print_st() {
  20. if [ x"$TERM" = "xscreen" ] ; then
  21. printf "\a\033\\"
  22. else
  23. printf "\a"
  24. fi
  25. }
  26. function list_file() {
  27. fn=$1
  28. 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")
  29. rc=$?
  30. if [[ $rc == 0 ]] ; then
  31. print_osc
  32. printf '1337;File=name='`echo -n "$fn" | base64`";"
  33. wc -c "$fn" | awk '{printf "size=%d",$1}'
  34. printf ";inline=1;height=3;width=3;preserveAspectRatio=true"
  35. printf ":"
  36. base64 < "$fn"
  37. print_st
  38. if [ x"$TERM" == "xscreen" ] ; then
  39. # This works in plain-old tmux but does the wrong thing in iTerm2's tmux
  40. # integration mode. tmux doesn't know that the cursor moves when the
  41. # image code is sent, while iTerm2 does. I had to pick one, since
  42. # integration mode is undetectable, so I picked the failure mode that at
  43. # least produces useful output (there is just too much whitespace in
  44. # integration mode). This could be fixed by not moving the cursor while
  45. # in integration mode. A better fix would be for tmux to interpret the
  46. # image sequence, though.
  47. #
  48. # tl;dr: If you use tmux in integration mode, replace this with the printf
  49. # from the else clause.
  50. printf '\033[4C\033[Bx'
  51. else
  52. printf '\033[A'
  53. fi
  54. echo -n "$dims "
  55. ls -ld "$fn"
  56. else
  57. ls -ld "$fn"
  58. fi
  59. }
  60. check_dependency php
  61. check_dependency base64
  62. check_dependency wc
  63. if [ $# -eq 0 ]; then
  64. for fn in *
  65. do
  66. list_file "$fn"
  67. done < <(ls -ls)
  68. else
  69. for fn in "$@"
  70. do
  71. list_file "$fn"
  72. done
  73. 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/

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注