Skip to content

Instantly share code, notes, and snippets.

@ceving
Created September 13, 2016 09:11
Show Gist options
  • Save ceving/bad44b3489bbbac66d17448713679e65 to your computer and use it in GitHub Desktop.
Save ceving/bad44b3489bbbac66d17448713679e65 to your computer and use it in GitHub Desktop.
Annex one or more files.
#! /bin/bash
set -eu
annex ()
{
local option
local OPTARG
local OPTIND
local recursive=
local user=${SUDO_UID:-$(id -ru)}
local group=${SUDO_GID:-$(id -rg)}
while getopts ':R' option; do
case $option in
R) recursive=-R;;
\?) echo "Invalid option -$OPTARG" >&2; return 1;;
esac
done
shift $((OPTIND-1))
for file; do
chown $recursive "$user:$group" "$file"
done
}
annex "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment