Skip to content

Instantly share code, notes, and snippets.

@firedynasty
Last active September 7, 2021 22:31
Show Gist options
  • Save firedynasty/1c75290e32fddac09a573b2e1b65892d to your computer and use it in GitHub Desktop.
Save firedynasty/1c75290e32fddac09a573b2e1b65892d to your computer and use it in GitHub Desktop.
function copy() {
    if [[ $# -eq 0 ]]; then
        echo 'first argument: file'
        echo 'second argument: line number'
    else
    sed -n $2p $1 | pbcopy 
    fi
}

if the file is hello.txt
cat hello.txt
cat -n hello.txt (returns the file with the line numbers)
and if you want to copy one line
copy hello.txt 2 (for line 2)

or if you want to copy from an entire text file:

function copyfile() {
    if [[ $# -eq 0 ]]; then
        echo 'first argument: file'
        echo 'second argument: line number'
    else
    cat $1 | pbcopy 
    fi
}

copyfile hello.txt

will return the entire file in your clipboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment