Mac上安装iTerm2,并使用rz sz命令上传下载文件

10,044次阅读
没有评论

共计 2242 个字符,预计需要花费 6 分钟才能阅读完成。

在 Mac 上安装好远程服务器链接软件 iTerm2,配置好远程服务器链接配置

iTerm

点击 iTerm2 的设置界面 Advanced -> Triggers 的 Edit 按钮,增加两条配置

然后再 /usr/local/bin/ 目录下增加 iterm2-recv-zmodem.sh 和 iterm2-send-zmodem.sh 文件

1. iterm2-recv-zmodem.sh

#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required 
# Remainder of script public domain

osascript -e 'tell application"iTerm2"to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[$NAME = "iTerm"]]; then
    FILE=`osascript -e 'tell application"iTerm"to activate' -e 'tell application"iTerm"to set thefile to choose folder with prompt"Choose a folder to place received files in"'-e"do shell script ("echo"&(quoted form of POSIX path of thefile as Unicode text)&"")"`
else
    FILE=`osascript -e 'tell application"iTerm2"to activate' -e 'tell application"iTerm2"to set thefile to choose folder with prompt"Choose a folder to place received files in"'-e"do shell script ("echo"&(quoted form of POSIX path of thefile as Unicode text)&"")"`
fi

if [[$FILE = ""]]; then
    echo Cancelled.
    # Send ZModem cancel
    echo -e \x18\x18\x18\x18\x18
    sleep 1
    echo
    echo # Cancelled transfer
else
    cd "$FILE"
    /usr/local/bin/rz -E -e -b
    sleep 1
    echo
    echo
    echo # Sent -> $FILE
fi

2.iterm2-send-zmodem.sh
#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required 
# Remainder of script public domain

osascript -e 'tell application"iTerm2"to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[$NAME = "iTerm"]]; then
    FILE=`osascript -e 'tell application"iTerm"to activate' -e 'tell application"iTerm"to set thefile to choose file with prompt"Choose a file to send"'-e"do shell script ("echo"&(quoted form of POSIX path of thefile as Unicode text)&"")"`
else
    FILE=`osascript -e 'tell application"iTerm2"to activate' -e 'tell application"iTerm2"to set thefile to choose file with prompt"Choose a file to send"'-e"do shell script ("echo"&(quoted form of POSIX path of thefile as Unicode text)&"")"`
fi
if [[$FILE = ""]]; then
    echo Cancelled.
    # Send ZModem cancel
    echo -e \x18\x18\x18\x18\x18
    sleep 1
    echo
    echo # Cancelled transfer
else
    /usr/local/bin/sz "$FILE" -e -b
    sleep 1
    echo
    echo # Received $FILE
fi

将文件写好后保存好,使用如下命令添加权限 chmod +777 iterm2-*

rz 上传功能

  • 在 bash 中,也就是 iTerm2 终端输入 rz 就会弹出文件选择框,选择文件 choose 就开始上传,会上传到当前目录

sz 下载功能

  • sz fileName(你要下载的文件的名字) 回车
  • 会弹出窗体 我们选择要保存的地方即可。

    正文完
     0
    Yojack
    版权声明:本篇文章由 Yojack 于1970-01-01发表,共计2242字。
    转载说明:
    1 本网站名称:优杰开发笔记
    2 本站永久网址:https://yojack.cn
    3 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
    4 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
    5 本站所有内容均可转载及分享, 但请注明出处
    6 我们始终尊重原创作者的版权,所有文章在发布时,均尽可能注明出处与作者。
    7 站长邮箱:laylwenl@gmail.com
    评论(没有评论)