動作環境
- 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 君の存在を知ってしまった
もっといい方法あったら誰かがコメントしてくれると思った