-
-
Save catfist/05fa098a7e88af806702 to your computer and use it in GitHub Desktop.
Alfred Workflow - Search and do Command in Local Repositories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DIFS=$IFS; IFS=',' read repo dir cmd <<< "{query}"; export PS1="repo:${repo}$ ";dir=`echo "$dir" | sed "s%~%$HOME%"`; cd "$dir"; IFS=$DIFS | |
$cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Author
catfist
commented
Nov 11, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment