Skip to content

Instantly share code, notes, and snippets.

@catfist
Created November 11, 2014 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catfist/05fa098a7e88af806702 to your computer and use it in GitHub Desktop.
Save catfist/05fa098a7e88af806702 to your computer and use it in GitHub Desktop.
Alfred Workflow - Search and do Command in Local Repositories
on alfred_script(q)
set text item delimiters of AppleScript to ","
set {repo, dir, cmd} to every text item of q
tell application "iTerm"
activate
set _term to (make new terminal)
tell _term
launch session {}
tell the last session
write text "cd \"" & dir & "\""
if cmd is not "" then write text cmd
end tell
end tell
end tell
end alfred_script
DIFS=$IFS; IFS=',' read repo dir cmd <<< "{query}"; export PS1="repo:${repo}$ ";dir=`echo "$dir" | sed "s%~%$HOME%"`; cd "$dir"; IFS=$DIFS
$cmd
repos=(
"repo name 1,~/path/to/repo/1"
"repo name 2,~/path/to/repo/2"
)
IFS="," read q cmd text<<< "{query}"
case $cmd in
c* )
arg="git commit -m '$text'"
;;
p* )
arg="git push; echo 'display notification 'done push' with title 'MyGit'' | osascript"
;;
v* )
IFS="," read ver comment <<< $text
arg="git tag -a '$cmd' -m '$text'"
# arg="git tag -a '$ver' -m '$comment'"
;;
esac
cat << EOB
<?xml version="1.0"?>
<items>
EOB
(IFS=$'\n'
for i in `echo "${repos[*]}" | grep -i "^[^,]*$q[^,]*,"`
do
cat << EOB
<item uid="repos" arg="${i%%,*},${i#*,},$arg" valid="YES" >
<title>${i%%,*}</title>
<subtitle>Open "${i%%,*}" repo | "$arg"</subtitle>
</item>
EOB
done)
cat << EOB
</items>
EOB
@catfist
Copy link
Author

catfist commented Nov 11, 2014

screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment