0
0

More than 3 years have passed since last update.

ssh先 & dirを指定→pecoで選んだfileをscpする

Last updated at Posted at 2021-01-05

動作環境

  • pecoが入ってる
  • rubyが入ってる
  • 他にもあるかも
function scp_file {
    ssh -qt $1 "QUOTING_STYLE=literal ls -1 $2" > /tmp/lsfiles

    # peco で選択した文字列をrubyに渡してshell safeにする
    valid_file_name=$(cat /tmp/lsfiles | peco | ruby -rshellwords -e "print(Shellwords.escape(gets.chomp))")

    scp "$1":"$2/$valid_file_name" $3
}

scp_file remove_host_name remote_host_path client_path
で実行可能。

背景

色々エスケープしないとscpできないファイル名(記号とかスペースとか)のものをscpしたいことが多かった
Shellwords.escape 君の存在を知ってしまった
もっといい方法あったら誰かがコメントしてくれると思った

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0