Skip to content

Instantly share code, notes, and snippets.

@octiwhale
Last active July 12, 2025 10:11
Show Gist options
  • Select an option

  • Save octiwhale/6ae5cefe5631a1a4e632019599431ccf to your computer and use it in GitHub Desktop.

Select an option

Save octiwhale/6ae5cefe5631a1a4e632019599431ccf to your computer and use it in GitHub Desktop.
fcop.sh - copy file contents to clipboard
#!/bin/bash
# fcop - Copy file contents to clipboard (quiet version)
FILE="$1"
# Usage check
[ -z "$FILE" ] && { echo "Usage: fcop <filename>"; exit 1; }
# File exists?
[ ! -e "$FILE" ] && { echo "'$FILE' not found."; exit 1; }
# Check if readable by current user
if [ -r "$FILE" ]; then
cat "$FILE" | pbcopy
exit 0
fi
# If not readable, show file metadata
INFO=$(ls -ld "$FILE")
OWNER=$(stat -f '%Su' "$FILE")
GROUP=$(stat -f '%Sg' "$FILE")
PERMS=$(stat -f '%Sp' "$FILE")
echo "No read access to '$FILE'."
echo "$OWNER:$GROUP, $PERMS"
# Interactively request perms
sudo cat "$FILE" | pbcopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment