Skip to content

Commit

Permalink
Merge pull request #4 from LrWm3/feat/list-until
Browse files Browse the repository at this point in the history
feat - list & analyse supports since and until. thanks @LrWm3 !
  • Loading branch information
kungfusheep authored Sep 13, 2023
2 parents d109607 + 2bb5f8a commit f42eb2b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ source i.sh #this creates your journal repo at ~/i

> You can 'mention' names with `@` and 'tag' things with `%`.
### List entries between time range

```bash
❯ i list since "30 minutes ago"

21 minutes ago: went for a walk

❯ i list until "60 minutes ago"

79 minutes ago: created a journal

❯ i list until "50 minutes ago" since "60 minutes ago"

54 minutes ago: spoke to @john

54 minutes ago: added an entry

❯ i list since "60 minutes ago" until "50 minutes ago"

54 minutes ago: spoke to @john

54 minutes ago: added an entry
```
> See the official git documentation, [date-formats.txt](https://raw.githubusercontent.com/git/git/master/Documentation/date-formats.txt) for all possible date and time representations `since` and `until` support.
### List mentions
```bash
Expand All @@ -55,7 +81,7 @@ source i.sh #this creates your journal repo at ~/i
2 @fred
1 @linda
1 @kelly
````
```
### List specific entries for people
Expand Down
41 changes: 31 additions & 10 deletions i.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function i {
__i_amend "$@"; return;;

"list" ) # list out the journal
__i_list; return;;
shift
__i_list "$@"; return;;

"mentioned") # list out names mentioned
shift
Expand Down Expand Up @@ -166,8 +167,23 @@ function __i_amend {
}

# list the entries in readable format
# the syntax is `i list` or
# the syntax is `i list since "last monday" until "yesterday"`
function __i_list {
git -C $I_PATH/ log --since "${since:-1970}" --pretty=format:"%Cblue%cr: %Creset%B";
item="${1}"
local until_cmd since_cmd

while [ "$item" == "until" ] || [ "$item" == "since" ] && [ -n "${2}" ]; do
if [ "$item" == "until" ]; then
until_cmd="${2}"
elif [ "$item" == "since" ]; then
since_cmd="${2}"
fi
shift 2
item="${1}"
done

git -C $I_PATH/ log --since "${since_cmd:=1970}" --until "${until_cmd:=now}" --pretty=format:"%Cblue%cr: %Creset%B";
}

function __i_count_occurrences {
Expand Down Expand Up @@ -200,18 +216,23 @@ function __i_find {
}

# run arbitrary GPT analysis commands on a specific time window from the journal
# the syntax is `i analyse since "last monday" list all people i interacted with`
# the syntax is `i analyse since "last monday" until "yesterday" list all people i interacted with`
function __i_analyse {
item="${1}"
shift

if [ "$item" == "since" ]; then # allow user to type "since" as first argument
local until_cmd since_cmd

while [ "$item" == "until" ] || [ "$item" == "since" ] && [ -n "${2}" ]; do
if [ "$item" == "until" ]; then
until_cmd="${2}"
elif [ "$item" == "since" ]; then
since_cmd="${2}"
fi
shift 2
item="${1}"
shift
fi
done

# the journal
OUT=$(git -C $I_PATH/ log --since "$item" --pretty=format:"%cr: %B" | tr -d '"\n')
OUT=$(git -C $I_PATH/ log --since "${since_cmd:=1970}" --until "${until_cmd:=now}" --pretty=format:"%cr: %B" | tr -d '"\n')
# the whole prompt
PROMPT="$* \n\n\n "$OUT""

Expand Down Expand Up @@ -326,5 +347,5 @@ fi

# Check if the script is being executed directly. If so, we run i directly
if [[ "${BASH_SOURCE[0]}" = "${0}" ]]; then
i "$@"
i "$@"
fi

0 comments on commit f42eb2b

Please sign in to comment.