Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 34 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,112 +1,83 @@
# Woche - v1.3.1
# Woche - v1.4.0

Woche is a tool for managing weekly tasks using Bash scripts. It creates a new Markdown file for the current week and allows you to add tasks to specific days. "Woche" means 'week' in German, and you can choose between English or German day names.

![Screencast from 2024-10-20 15-15-38](https://github.com/user-attachments/assets/ef870bad-44c4-40ca-8c3d-a8313ea21d37)
Woche is a command-line tool for managing weekly tasks using Bash scripts. It helps you create and organize tasks in Markdown files, with support for English and German day names.

## Features

- Generates a new Markdown file for the current week with headers for each day.
- Allows adding, editing, and deleting tasks for specific days or lines.
- Lists and displays tasks from different weeks.
- Provides usage tips.
- Create weekly Markdown files.
- Add, edit, delete, and mark tasks as complete.
- View tasks by week, grouped by day with line numbers.
- Search for tasks across all weeks.
- Open weekly files in your preferred editor.

## Usage

### Create a New Markdown File for the Current Week
### Getting Started

```bash
./woche.sh create
# The file 241014.md has been created
```

This command creates a file using the YYMMDD format.

### Add a Task to a Specific Day

```bash
./woche.sh <day> "<task>"
```

Replace `<day>` with the day of the week and `<task>` with the task description. Days in English: mon, tue, wed, thu, fri, sat, sun. Days in German: mont, die, mit, don, frei, sam, son.

```bash
./woche.sh mon "Do something"
# Do something was added to Monday.
# Creates a new Markdown file for the current week (e.g., 241014.md)
```

### Display Tasks of the Current Week
### Adding Tasks

```bash
./woche.sh show
./woche.sh <day> "<task>" # Add task to a specific day (e.g., mon, tue, mont, die)
./woche.sh today "<task>" # Add task to the current day
```

### Edit a Task of the Current Week
### Viewing Tasks

```bash
./woche.sh edit 9 "That task"
# Line 9 edited.
./woche.sh show # Display tasks for the current week
./woche.sh show last # Display tasks for last week
./woche.sh show <YYMMDD> # Display tasks for a specific week (e.g., 210829)
./woche.sh all # List all weekly Markdown files
```

### Delete a Task of the Current Week
### Managing Tasks

```bash
./woche.sh delete 3
# Line 3 deleted.
./woche.sh edit <line_number> "<new_task>" # Edit a task by line number
./woche.sh delete <line_number> # Delete a task by line number (requires confirmation)
./woche.sh done <line_number> # Mark a task as complete
```

### List Files of Different Weeks
### Searching Tasks

```bash
./woche.sh all
./woche.sh search "<keyword>" # Search for a keyword in all weekly files
```

### Display Tasks of Last Week
### Other Commands

```bash
./woche.sh show last
```

### Show Tasks of a Specific Week

```bash
./woche.sh show 210829
```

### Access Instructions

```bash
./woche.sh help
./woche.sh open # Open the current week's file in $EDITOR
./woche.sh help # Display all commands and usage
```

## Testing

The `test.sh` script tests the functionality of `woche.sh`, checking both correct and incorrect user inputs. This test is mandatory for pull requests to the main branch and should be included in the [GitHub Actions](https://github.com/0jonjo/woche/actions) pipeline for automated testing.

To run the tests:
To run the test suite:

```bash
./test.sh
```

## Docker

To use the Dockerized version of Woche:
To use the Dockerized version:

```bash
# Build the image
docker build -t woche-app .

# Run the container
docker run -it woche-app
docker build -t woche-app . # Build the image
docker run -it woche-app # Run the container
```

## Customization Tips
## Customization

- Change the file creation path by modifying the `path` variable in `variables.sh`.
- Switch to German day names by replacing `week_array` with `woche_array` in `variables.sh`.
- Alter the date format of the Markdown file by adjusting the `start_day_of_week` method in `functions.sh`.
- Use the Dockerized version if not on an Ubuntu/Debian system.
- Change file path: Modify `path_to_files` in `variables.sh`.
- Switch to German days: Replace `week_array` with `woche_array` in `variables.sh`.
- Adjust date format: Modify `start_day_of_week` in `functions.sh`.

## License

Expand Down
79 changes: 74 additions & 5 deletions functions.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/usr/bin/env bash

tips() {
echo "tips: woche.sh"
help() {
echo "create: a new markdown file for the current week"
echo "Use the day alias to add a task to the day of the week."
echo "today: add a task to the current day"
echo "show: show the tasks for the current week"
echo "show YYMMDD: show the tasks for the week starting on YYMMDD"
echo "show last: show the tasks for last week"
echo "delete X: delete a task from the current week - X is the line number"
echo "edit X: edit a task from the current week - X is the line number"
echo "all: show all markdown files in the current directory"
echo "open: open the current week's file in your default editor"
}

current_week() {
Expand Down Expand Up @@ -69,8 +70,13 @@ create_week() {
}

delete_line() {
sed -i "${task}d" "$file.md"
echo "Line ${task} deleted."
read -p "Are you sure you want to delete line ${task}? (y/N): " confirm
if [[ "$confirm" =~ ^[yY]$ ]]; then
sed -i "${task}d" "$file.md"
echo "Line ${task} deleted."
else
echo "Deletion cancelled."
fi
}

edit_line() {
Expand All @@ -82,10 +88,73 @@ edit_line() {
show_file() {
start_day_formatted=$(date -d "$file" "+%d/%m/%Y")
printf "Week starts on %s.\n\n" "$start_day_formatted"
cat -n "$file.md"

legend_string=""
for day_full_name in "${week_array[@]}"; do
header_line=$(grep "^# ${day_full_name}," "$file.md")
if [ -n "$header_line" ]; then
date_part=$(echo "$header_line" | awk -F', ' '{print $2}' | awk '{print $1}')
day_abbr=$(echo "$day_full_name" | cut -c1-3 | tr '[:upper:]' '[:lower:]')
if [ -n "$legend_string" ]; then
legend_string+=", "
fi
legend_string+="${day_abbr} (${date_part})"
fi
done
printf "Current week: %s\n\n" "$legend_string"

awk_output=$(awk '
/^# / {
current_day = substr($0, 3);
sub(/,.*$/, "", current_day);
next;
}
/^- / {
print current_day "::" $0 " (" NR ")";
}
' "$file.md")

for ordered_day in "${week_array[@]}"; do
day_tasks=$(echo "$awk_output" | grep "^${ordered_day}::")

if [ -n "$day_tasks" ]; then
printf "%s:\n" "$ordered_day"
echo "$day_tasks" | sed 's/^[^:]*:://'
printf "\\n"
fi
done
}

show_all_files() {
echo "All markdown files in $path_to_files:"
ls -1 ./*.md
}

add_task() {
day_name="$1"
task_text="$2"
escaped_task=$(sed 's/[\/&]/\\&/g' <<< "$task_text")
sed -i "/# $day_name/ a\\- $escaped_task" "$file.md"
echo "Task '$task_text' added to $day_name."
}

search_files() {
search_term="$1"
echo "Searching for '$search_term' in markdown files:"
grep -n "$search_term" "$path_to_files"/*.md
}

mark_task_done() {
line_number="$1"
sed -i "${line_number}s/^- /- [x] /" "$file.md"
echo "Task on line ${line_number} marked as done."
}

open_file_in_editor() {
if [ -z "$EDITOR" ]; then
echo "Error: $EDITOR environment variable is not set. Please set it to your preferred editor (e.g., export EDITOR=nano)."
exit 1
fi
"$EDITOR" "$file.md"
echo "Opened $file.md in $EDITOR."
}
Loading