Skip to content

Instantly share code, notes, and snippets.

@vidul-nikolaev-petrov
Last active February 3, 2016 00:38
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 vidul-nikolaev-petrov/c93b2fc4ca88253c0b8e to your computer and use it in GitHub Desktop.
Save vidul-nikolaev-petrov/c93b2fc4ca88253c0b8e to your computer and use it in GitHub Desktop.
Simple command-line Todo with Git commits
[alias]
# add task
a = "!f() { \
if [[ -f .dummy ]]; then \
git rm -f .dummy; \
else \
touch .dummy; \
git add .dummy; \
fi; \
git commit -am \"$1\"; \
}; \
f"
# close task
c = "!f() { \
if [[ -z $1 ]]; then \
return; \
else \
HASH=$(git log --grep=\"task $1:\" --pretty=\"format:%H\"); \
if [[ -z $HASH ]]; then \
return; \
else \
git checkout -b tmp $HASH; \
git filter-branch -f --msg-filter \
\"sed 's/^task $1:/task $1 (closed):/'\" tmp~1..HEAD; \
git checkout master; \
git merge tmp --no-edit; \
git branch -d tmp; \
fi; \
fi; \
}; \
f"
# show task
s = "!f() { \
if [[ -z $1 ]]; then \
return; \
else \
HASH=$(git log --grep=\"task $1:\" --pretty=\"format:%H\"); \
if [[ -z $HASH ]]; then \
return; \
else \
git log $HASH -n 1; \
fi; \
fi; \
}; \
f"
# grep open tasks by search string
g = "!f() { \
if [[ -z $1 ]]; then \
return; \
else \
git l | grep \"$1\"; \
fi; \
}; \
f"
# grep tasks and show the first one (i.e. `git g | git s`)
gs = "!f() { \
if [[ -z $1 ]]; then \
return; \
else \
git s \"$(git g $1 | head -1 | cut -f 2 -d' ' | head -c 1)\"; \
fi; \
}; \
f"
loInner = log --grep=\"^task [0-9][0-9]*:\" \
--pretty="tformat:\"%C(white)%ad %C(green)%s\""
lcInner = log --grep=\"^task [0-9][0-9]* (closed):\" \
--pretty="tformat:\"%s\""
# list open tasks
# 'l' stands for `list`, 'o' stands for `open`
lo = "!f() { \
CLOSED=$(git lcInner | cut -f 1,2 -d' '); \
if [[ -z $CLOSED ]]; then \
CLOSED='^ø'; \
fi; \
git loInner | grep -v \"$CLOSED\"; \
}; \
f"
# list closed tasks
# 'l' stands for `list`, 'c' stands for `closed`
lc = log --grep=\"^task [0-9][0-9]* (closed):\" \
--pretty="tformat:\"%C(white)%ad %C(red)%s\""
# list all tasks (both open and closed)
# 'l' stands for `list`, 'a' stands for `all`
la = log --grep=\"^task [0-9][0-9]*\" \
--pretty="tformat:\"%C(white)%ad %C(yellow)%s\""
l = !sh -c 'git lo'
h = !sh -c 'echo Todo commands: \
\"\n\" \
\"\n\" \
lo \"\t\" list open tasks \
\"\n\" \
lc \"\t\" list closed tasks \
\"\n\" \
la \"\t\" list all tasks \
\"\n\" \
a \"\t\" add task \
\"\n\" \
c \"\t\" close task \
\"\n\" \
g \"\t\" grep open tasks by search string \
\"\n\" \
s \"\t\" show task \
\"\n\" \
gs \"\t\" grep open tasks and show the first one'
#!/bin/sh
COUNTER=$(git rev-list HEAD --count --grep="^task [0-9][0-9]*:")
COUNTER=$((COUNTER+1))
echo "task $COUNTER"': '$(cat "$1") > "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment