Skip to content

Commit 47d7708

Browse files
committed
Introduce focus.sh
0 parents  commit 47d7708

File tree

2 files changed

+261
-0
lines changed

2 files changed

+261
-0
lines changed

README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# `focus.sh`
2+
3+
This is a very simple command line that I developed for my own itch. I usually get distracted when I'm working on some
4+
task and then suddenly (have) to jump into a different topic. After switching back to the last task, I completely forgot
5+
what I've been working on or even forgot which task it is.
6+
7+
The CLI `focus.sh` is a very simple tracking I develop for myself (because I use the Terminal **a lot**).
8+
9+
## Concept
10+
11+
`focus.sh` uses a Git repository to keep track of all the data. It actually does not add any file into the Git
12+
repository so the `.git` directory is the source of truth.
13+
14+
- *Focus*: A focus is a Git branch.
15+
- *Update/Note*: A simple Git commit (with `--allow-empty`).
16+
17+
## Workflow
18+
19+
This section describes the typical workflow that I use `focus.sh` as well as some common commands.
20+
21+
```bash
22+
23+
# Show the current focus. In case this is the first time, or
24+
# the last focus has been done, it will show nothing (or master).
25+
$ focus now
26+
nothing
27+
28+
# Switch my focus into work/some-thing
29+
$ focus to work/some-thing
30+
31+
# I update with some steps that got finished.
32+
$ focus jot 'Some findings that I find"
33+
34+
# Or if I need a long text, I can use the default Git EDITOR (vim ftw).
35+
$ focus jot
36+
## open EDITOR to input more text.
37+
38+
# Then I got distracted by some other thing.
39+
$ focus to work/something-completely-different
40+
## now I got distracted
41+
42+
# A note to the new focus
43+
$ focus jot "Nothing to see here"
44+
45+
# Check what was the last focus
46+
$ focus before
47+
work/some-thing
48+
49+
# Set the current focus as DONE.
50+
$ focus done
51+
52+
# Switch back
53+
$ focus work/some-thing
54+
55+
```
56+
## Install
57+
58+
The following steps can be used to install
59+
60+
```bash
61+
$ git clone git@github.com:Genzer/focus.sh.git ~/.local/bin/focus.sh
62+
63+
$ echo '$HOME/.local/bin/focus.sh/' >>~/.bashrc
64+
65+
# Create an empty Git at $FOCUS_TRACKING_REPO. Default to $HOME/work/focus.sh-tracking
66+
$ focus init
67+
```
68+
69+
## Commands
70+
71+
Invoking `focus` without any command will show you the full usage of all available commands. Or `focus help`.
72+
73+
For example:
74+
75+
```bash
76+
$ focus
77+
The following commands can be used:
78+
79+
now
80+
Show the current topic (as a Git branch)
81+
82+
before [n]
83+
Show the previous topic. Use 'n' (1..99) to show the previous topic.
84+
85+
to SUMMARY_OF_TOPIC
86+
Switch the current focus to another topic.
87+
88+
done
89+
Mark the current topic as done.
90+
91+
all
92+
List all (undone) active focuses.
93+
94+
ls
95+
List what I did in the current topic
96+
97+
jot [MESSAGE]
98+
Jot down a quick summary of what has been done.
99+
The MESSAGE is optional. If it is missing, the default Git commit EDITOR will be opened.
100+
101+
fix
102+
Fix the last messsage jotted down.
103+
104+
help
105+
Show this usage.
106+
```

focus.sh

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#!/usr/bin/env bash
2+
3+
[ "$DEBUG" == "1" ] && set -x
4+
5+
FOCUS_TRACKING_REPO=${FOCUS_TRACKING_REPO:-$HOME/work/focus.sh-tracking}
6+
7+
function focus__version() {
8+
echo "0.1.0"
9+
}
10+
11+
function focus__init() {
12+
mkdir -p ${FOCUS_TRACKING_REPO}
13+
__git init
14+
__git switch -c "nothing"
15+
}
16+
17+
function __git() {
18+
git -C "$FOCUS_TRACKING_REPO" "$@"
19+
}
20+
21+
function focus__now() {
22+
__git branch --show-current
23+
}
24+
25+
function focus__before() {
26+
__git rev-parse --abbrev-ref "@{-${1:-1}}"
27+
}
28+
29+
function focus__done() {
30+
local current_branch="$(focus__now)"
31+
__git switch "done"
32+
__git merge --no-ff --no-edit "$current_branch"
33+
__git branch -D "${current_branch}"
34+
__git switch "nothing"
35+
}
36+
37+
function focus__all() {
38+
__git branch --all
39+
}
40+
41+
# Add an update/message/note into the current focus.
42+
function focus__jot() {
43+
__git commit --allow-empty "$@"
44+
}
45+
46+
function focus__to() {
47+
local new_topic="${*}"
48+
new_topic=${new_topic// /-}
49+
50+
focus__jot -m "Switch to [${new_topic}]"
51+
52+
$(__git show-ref --quiet --verify -- "refs/heads/${new_topic}")
53+
if [ "$?" == "0" ]
54+
then
55+
__git switch "${new_topic}"
56+
else
57+
__git switch -c "${new_topic}" "nothing"
58+
focus__jot -m "Started on ${new_topic}"
59+
fi
60+
61+
echo "previous topic $(focus__before)"
62+
}
63+
64+
function focus__ls() {
65+
__git ls
66+
}
67+
68+
function usage() {
69+
cat <<__USAGE__
70+
The following commands can be used:
71+
72+
now
73+
Show the current topic (as a Git branch)
74+
75+
before [n]
76+
Show the previous topic. Use 'n' (1..99) to show the previous topic.
77+
78+
to SUMMARY_OF_TOPIC
79+
Switch the current focus to another topic.
80+
81+
done
82+
Mark the current topic as done.
83+
84+
all
85+
List all (undone) active focuses.
86+
87+
ls
88+
List what I did in the current topic
89+
90+
jot [MESSAGE]
91+
Jot down a quick summary of what has been done.
92+
The MESSAGE is optional. If it is missing, the default Git commit EDITOR will be opened.
93+
94+
fix
95+
Fix the last messsage jotted down.
96+
97+
help
98+
Show this usage.
99+
__USAGE__
100+
101+
}
102+
103+
if [ "$#" == "0" ]
104+
then
105+
usage
106+
exit 0
107+
fi
108+
109+
110+
option="${1}"
111+
shift
112+
113+
case "$option" in
114+
init)
115+
focus__init
116+
;;
117+
now)
118+
focus__now
119+
;;
120+
before)
121+
focus__before "$@"
122+
;;
123+
to)
124+
focus__to "$@"
125+
;;
126+
done)
127+
focus__done
128+
;;
129+
jot)
130+
if [ "$#" == "0" ]
131+
then
132+
focus__jot
133+
else
134+
focus__jot -m "$*"
135+
fi
136+
;;
137+
fix)
138+
focus__jot --edit --amend
139+
;;
140+
ls)
141+
focus__ls
142+
;;
143+
all)
144+
focus__all
145+
;;
146+
help)
147+
usage
148+
;;
149+
version)
150+
focus__version
151+
;;
152+
*)
153+
usage
154+
;;
155+
esac

0 commit comments

Comments
 (0)