less than 1 minute read

I often find that I need to paste the full filesystem path to a given file somewhere, into a config file, onto the command line, etc. This small shell function does that:

function filecc() {
    if [ -z $1 ] || [ ! -f $1 ]
    then
        echo Give me a file you dummy
        return 1
    fi
    readlink -f $1 | tr -d "\n" | xclip
}

Notes

  • Only tested in zsh
  • Depends on xclip which should be available from your distro’s package archive. Otherwise - https://github.com/astrand/xclip.
  • Ideally added to you .zshrc file

Example usage:

filecc somefile.txt
# Paste whereever needed