-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
178 additions
and
126 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,64 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## 0.1.7 (2023-06-17) | ||
|
||
### Changed | ||
|
||
- Migrated from setup.py to pyproject.toml. | ||
- Introduced package instead of a script | ||
- Refactored commands to be more modular | ||
|
||
## 0.1.6 (2023-02-13) | ||
|
||
### Added | ||
|
||
- `Makefile` | ||
- `requirements-dev.txt` for development | ||
- help to every command | ||
|
||
### Changed | ||
- Documentation is moved to [docs/](docs/README.md) | ||
|
||
- Documentation is moved to [docs/](docs/README.md) | ||
|
||
## 0.1.5 (2023-01-07) | ||
|
||
### Added | ||
- `ls -l` list files as wiki links | ||
|
||
- `ls -l` list files as wiki links | ||
|
||
## 0.1.4 (2022-12-03) | ||
|
||
### Changed | ||
|
||
- `count` command by default counts file modified from midnight of today in local time | ||
- `ls` command by default lists files modified today in local time | ||
|
||
|
||
## 0.1.3 | ||
|
||
### Added | ||
- `random` returns a random file | ||
|
||
- `random` returns a random file | ||
|
||
## 0.1.2 | ||
|
||
### Changed | ||
- `ls` command shows only `.md` files | ||
|
||
- `ls` command shows only `.md` files | ||
|
||
## 0.1.1 | ||
|
||
### Added | ||
- `ls` command to list files modified in last 24 hours in reverse chronological order | ||
|
||
- `ls` command to list files modified in last 24 hours in reverse chronological order | ||
|
||
## 0.1.0 | ||
|
||
### Added | ||
|
||
- `count` command | ||
- tests |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1.7 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
# Release checklist | ||
|
||
## Before release | ||
|
||
- [ ] tests pass (`make test`) | ||
- [ ] [CHANGELOG](../CHANGELOG.md) is updated | ||
- [ ] version is updated in [setup.py](../setup.py) | ||
- [ ] version is updated in [VERSION](../VERSION) and [pyproject.toml](../pyproject.toml) | ||
|
||
## After release | ||
|
||
- [ ] add a tag for the release in git: | ||
|
||
```bash | ||
git tag -a 0.1.0 -m "0.1.0" | ||
git push origin 0.1.0 | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[build-system] | ||
requires = ["setuptools", "wheel"] | ||
|
||
|
||
[project] | ||
name = "think-cli" | ||
version = "0.1.7" | ||
description = "A command line tool to work with Markdown files" | ||
readme = "README.md" | ||
dependencies = [ | ||
"Click>=8.1.3" | ||
] | ||
|
||
|
||
[project.scripts] | ||
t = "think:cli" | ||
|
||
|
||
[tool.isort] | ||
src_paths = ["think", "tests"] |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
|
||
from click.testing import CliRunner | ||
|
||
|
||
from think import count | ||
|
||
|
||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .think import * |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import os | ||
|
||
import click | ||
|
||
from .files import iter_markdown_files_modified_today | ||
|
||
|
||
@click.command( | ||
help="Prints the total number of files and number of files modified today" | ||
) | ||
def count(): | ||
n_files = len(os.listdir()) | ||
n_modified_day = 0 | ||
for _ in iter_markdown_files_modified_today(): | ||
n_modified_day += 1 | ||
click.echo(f"Total files: {n_files}") | ||
click.echo(f"Modified today: {n_modified_day}") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
from datetime import datetime, timezone | ||
from pathlib import Path | ||
|
||
LOCAL_TIMEZONE = datetime.now(timezone.utc).astimezone().tzinfo | ||
|
||
|
||
MARKDOWN_FILE_EXTENSIONS = { | ||
"md", | ||
"mkd", | ||
"mdwn", | ||
"mdown", | ||
"mdtxt", | ||
"mdtext", | ||
"markdown", | ||
"text", | ||
"txt", | ||
} | ||
|
||
|
||
def is_markdown(p: Path): | ||
extension = p.suffix.lower().replace(".", "") | ||
return extension in MARKDOWN_FILE_EXTENSIONS | ||
|
||
|
||
def is_modified_today(p: Path): | ||
today_local = datetime.now().replace( | ||
hour=0, minute=0, second=0, tzinfo=LOCAL_TIMEZONE | ||
) | ||
mtime = datetime.fromtimestamp(os.path.getmtime(p)).replace(tzinfo=LOCAL_TIMEZONE) | ||
return mtime > today_local | ||
|
||
|
||
def iter_markdown_files_modified_today(): | ||
for p in Path().iterdir(): | ||
if is_markdown(p) and is_modified_today(p): | ||
yield p |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import os | ||
|
||
import click | ||
|
||
from .files import iter_markdown_files_modified_today | ||
|
||
CONVERTER_FOR_LINKS_PARAMETER = { | ||
True: lambda x: f'[[{str(x).replace(".md", "")}]]', | ||
False: lambda x: x, | ||
} | ||
|
||
|
||
@click.command(help="List files changed today") | ||
@click.option("-l", "--links", is_flag=True, help="Formats files as wiki links") | ||
def ls(links): | ||
files = [(os.path.getmtime(p), p) for p in iter_markdown_files_modified_today()] | ||
files.sort(reverse=True) | ||
for f in files: | ||
click.echo(CONVERTER_FOR_LINKS_PARAMETER[links](f[1])) |
Oops, something went wrong.