Skip to content

Instantly share code, notes, and snippets.

@ion1
Last active August 29, 2015 13:57
Show Gist options
  • Save ion1/9660286 to your computer and use it in GitHub Desktop.
Save ion1/9660286 to your computer and use it in GitHub Desktop.
Nautilus scripts for git-annex
#!/bin/sh
set -eu
shellquote() {
local space
space=''
for arg; do
printf '%s' "$space"
printf '%s' "$arg" | sed -e "s/'/'\\\\''/g; s/^/'/; s/\$/'/;"
space=' '
done
printf '\n'
}
# wow such metaprogramming
end_success="printf '\\nExiting.\\n'; sleep 2;"
end_failure="printf '\\nHit Return to exit. '; read dummy;"
go() {
local verb
verb="$1"; shift
exec gnome-terminal -x sh -euc "
if $(shellquote git annex "$verb" -- "$@"); then
$end_success
else
$end_failure
fi;
"
}
case "$0" in
*[Gg]et) go get "$@" ;;
*[Dd]rop) go drop "$@" ;;
*)
gnome-terminal -x sh -euc "
$(shellquote printf 'Error: "%s" does not end with Get/Drop.\n' "$0");
$end_failure
"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment