Skip to content

Instantly share code, notes, and snippets.

@nguyent
Last active June 9, 2018 13:38
Show Gist options
  • Select an option

  • Save nguyent/a8dbb6012f0b5c1bb139bbb10cbf939e to your computer and use it in GitHub Desktop.

Select an option

Save nguyent/a8dbb6012f0b5c1bb139bbb10cbf939e to your computer and use it in GitHub Desktop.
recursive directory listing piped into fzf for scp
remotecp()
{
server=myserver
remote_directory=filedirectory
# get full file names, slashes, and put everything in quotes (for strings with spaces yo)
filename=$(ssh $server "tree ${remote_directory} -afFiQ --prune | head -n -2" | fzf)
cmd=(scp)
# recursive copy for bash
if [ "${filename: -1}" = / ]; then
cmd+=(-r)
fi
cmd+=($server:$filename .)
#cmd=(echo $filename)
${cmd[@]}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment