From e3bddfe05fd2d72ddf1f57697a87df21db5cc49a Mon Sep 17 00:00:00 2001 From: Artem Sapegin Date: Thu, 10 Jan 2013 14:57:25 +0400 Subject: [PATCH] Cloudapp, git-open, lyrics & showme scripts. --- bin/cloudapp | 62 +++++++++++++++++++++++++++++++++++++ bin/git-open | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/lyrics | 14 +++++++++ bin/showme | 41 +++++++++++++++++++++++++ 4 files changed, 203 insertions(+) create mode 100755 bin/cloudapp create mode 100755 bin/git-open create mode 100755 bin/lyrics create mode 100755 bin/showme diff --git a/bin/cloudapp b/bin/cloudapp new file mode 100755 index 0000000..1ec555a --- /dev/null +++ b/bin/cloudapp @@ -0,0 +1,62 @@ +#!/usr/bin/env ruby +# +# cloudapp +# Zach Holman / @holman +# +# Uploads a file from the command line to CloudApp, drops it into your +# clipboard (on a Mac, at least). +# +# Example: +# +# cloudapp drunk-blake.png +# +# This requires Aaron Russell's cloudapp_api gem: +# +# gem install cloudapp_api +# +# Requires you set your CloudApp credentials in ~/.cloudapp as a simple file of: +# +# email +# password + +require 'rubygems' + +['json', 'cloudapp_api'].each do |gem| + begin + require gem + rescue LoadError + puts "You need to install #{gem}: gem install #{gem}" + exit!(1) + end +end + +config_file = "#{ENV['HOME']}/.cloudapp" +unless File.exist?(config_file) + puts "You need to type your email and password (one per line) into "+ + "`~/.cloudapp`" + exit!(1) +end + +email,password = File.read(config_file).split("\n") + +if ARGV[0].nil? + puts "You need to specify a file to upload." + exit!(1) +end + +urls = [] +ARGV.each do |x| + CloudApp.authenticate(email,password) + puts "Attempting to upload #{x}" + url = CloudApp::Item.create(:upload, {:file => x}).url + + # Say it for good measure. + puts "Uploaded #{x} to #{url}" + + # Get the embed link. + url = "#{url}/#{ARGV[0].split('/').last}" + urls << url +end + +# Copy it to your (Mac's) clipboard. +`echo '#{urls.join(',')}' | tr -d "\n" | pbcopy` diff --git a/bin/git-open b/bin/git-open new file mode 100755 index 0000000..a604372 --- /dev/null +++ b/bin/git-open @@ -0,0 +1,86 @@ +#!/bin/sh + +## Usage: git-open FILE [LINE] +## Open GitHub file/blob page for FILE on LINE. FILE is the path to the +## file on disk; it must exist and be tracked with the current HEAD +## revision. LINE is the line number or line number range (e.g., 10-50). +## +## Open foo/bar.rb in browser: +## $ git-open foo/bar.rb +## +## Open foo/bar in browser w/ lines 50-57 highlighted: +## $ git-open foo/bar.rb 50-57 +## +## Open current file in vim on line 20: +## :!git-open % 20 +## +## https://github.com/jacobwg/dotfiles/blob/master/bin/github-open + +set -e + +FILE="$1" +LINE="$2" + +# usage and help +test -z "$FILE" -o "$FILE" = '--help' && { + cat "$0" | grep '^##' | cut -c4- 1>&2 + exit 1 +} + +# bail out with message to stderr and exit status 1 +die() { + echo "$(basename $0):" "$@" 1>&2 + exit 1 +} + +# figure out relative path to the file from the root +# of the work tree +path="$(basename $FILE)" +cd $(dirname $FILE) +while test ! -d .git ; +do + test "$(pwd)" = / && { + echo "error: git repository not found" 1>&2 + exit 1 + } + path="$(basename $(pwd))/$path" + cd .. +done + +# get the current branch in refs/heads/ form +ref=$(git symbolic-ref -q HEAD) +test -n "$ref" || +die "you're not on a branch" + +# just the branch name please +branch=$(echo "$ref" | sed 's@^refs/heads/@@') +test -n "$branch" || +die "you're in a weird place; get on a local branch" + +# remote we're tracking +remote=$(git config --get "branch.$branch.remote" || true) +test -n "$remote" || +die "you're not tracking a remote branch" + +# remote branch we're tracking +merge=$( + (git config --get "branch.$branch.merge") | + sed 's@refs/heads/@@' +) +test -n "$merge" || +die "you're not tracking a remote branch" + +# at this point we're in root of the work tree and $path is +# the relative path to file. +remote_url=$(git config --get remote.$remote.url) +repo=$(echo "$remote_url" | sed 's/^.*:\(.*\)\.git/\1/') +url="http://github.com/$repo/blob/$branch/$path" + +# debugging +# echo "url: $remote_url" +# echo "repo: $repo" + +# throw the line number on there if specified +test -n "$LINE" && url="$url#L$LINE" + +open "$url" \ No newline at end of file diff --git a/bin/lyrics b/bin/lyrics new file mode 100755 index 0000000..90a58cb --- /dev/null +++ b/bin/lyrics @@ -0,0 +1,14 @@ +#!/bin/bash +# +# lyrics.sh +# +# A fine piece of work by @febuiles +# https://gist.github.com/1549979 + +artist=`osascript -e'tell application "iTunes"' -e'get artist of current track' -e'end tell'` +title=`osascript -e'tell application "iTunes"' -e'get name of current track' -e'end tell'` + +song=`curl -G --data-urlencode "artist=$artist" \ + --data-urlencode "title=$title" -s http://makeitpersonal.co/lyrics` + +echo -e "$artist - $title\n$song" \ No newline at end of file diff --git a/bin/showme b/bin/showme new file mode 100755 index 0000000..8475324 --- /dev/null +++ b/bin/showme @@ -0,0 +1,41 @@ +#!/bin/sh + +# +# Takes N pictures of you via your iSight camera, animates them, uploads them to CloudApp, and puts the url in your clipboard. +# +# USAGE: showme [shots] +# +# Author: Artem Sapegin, sapegin.me +# Inspired by https://gist.github.com/832125 +# +# Requirements: +# brew istall imagemagick imagesnap +# gem install gifme cloudapp_api json +# https://github.com/holman/dotfiles/blob/master/bin/cloudapp +# http://www.getcloudapp.com/ +# + + +# 3 shots by default +shots=${1-3} +dir=`basename "$(pwd)"` + +TMPDIR=`mktemp -d` && { + cd $TMPDIR + + for ((shot=1; shot<=$shots; shot++)); do + echo "Prepare for shot $shot..." + echo "3..." + sleep 1 + echo "2..." + sleep 1 + echo "1..." + sleep 1 + echo "GO!" + imagesnap -q "shot$shot.jpg" + done + + gifme -w 200 -o hereisapictureofme.gif *.jpg + + rm -rf $TMPDIR +}