Linux Asynchronous Copy and Paste
2021-6-15 12:0:0 Author: k4yt3x.com(查看原文) 阅读量:5 收藏

Linux Asynchronous Copy and Paste

Asynchronous copy-paste can be helpful in a handful of situations. I'll show you how to add async copy-paste functionality into Zsh in this post.

Asynchronous copy-paste can be helpful in a handful of situations:

  • You can save the path in the clipboard and paste it later.
  • You don’t have to work with super-long copy/move commands.
  • Etc. (use your imagination)

Source Code

You can add the following code snippet to your zshrc to add the three commands into your shell. Note that some of the syntaxes in this snippet are zsh-only. You might need to modify it a bit if you want to use it in bash or other shells.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# async copy
function ac() {
    unset ACOPY
    unset AMOVE
    export ACOPY=("${(@f)$(realpath -e [email protected])}")
}

# async move
function am() {
    unset ACOPY
    unset AMOVE
    export AMOVE=("${(@f)$(realpath -e [email protected])}")
}

# async paste
function ap() {
    if [ ! -z "$ACOPY" ]; then
        cp -vr "${ACOPY[@]}" .
    elif [ ! -z "$AMOVE" ]; then
        mv -v "${AMOVE[@]}" .
        unset AMOVE
    else
        >&2 echo 'clipboard empty'
        return 1
    fi
}

Copying Files and Directories

You can use the ac (stands for async-copy) command to copy one or more files/directories, and use the ap (stands for async-paste) command to paste it when you’re under another directory. Directories will be copied recursively automatically.

copy
Asynchronously copying files and directories to a new location

Moving Files and Directories

You can use the am (stands for async-move) command to move one or more files/directories, and use the ap command to paste it elsewhere.

move
Asynchronously moving files and directories to a new location


最后修改于 2021-06-15


文章来源: https://k4yt3x.com/linux-asynchronous-copy-and-paste/
如有侵权请联系:admin#unsafe.sh