Skip to content

Commit

Permalink
Merge pull request #33 from jfding/sync-with-mac-reminders
Browse files Browse the repository at this point in the history
Sync with mac reminders
  • Loading branch information
jfding authored Nov 3, 2024
2 parents dc31812 + dfa1977 commit 73326b5
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ jobs:
mv target/${{ matrix.platform.target }}/release${{ contains(matrix.platform.target, 'windows') && '-with-symbols' || '' }}/$_BIN ${{ env.BIN_NAME }}.bin
sh -c "cd $_BINDIR; ln -sf $_BIN today"
sh -c "cd $_BINDIR; ln -sf $_BIN tomorrow"
[[ ${{ matrix.platform.target }} == *"apple-darwin" ]] && cp scripts/t2reminders.scpt $_BINDIR/
zip -r --symlinks ${{ env.BIN_NAME }}-${{ matrix.platform.target }}.zip $_BINDIR/*
- name: archive the exe
Expand Down
5 changes: 5 additions & 0 deletions pkg/brew/todor-bin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ class TodorBin < Formula

def install
bin.install "todor"
bin.install "today"
bin.install "tomorrow"
on_macos do
bin.install "t2reminders.scpt"
end
end
end
File renamed without changes.
33 changes: 33 additions & 0 deletions scripts/t2reminders.scpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env osascript

-- Get the first argument or use default value
on run argv
if (count of argv) is 0 then
set boxname to "today"
else
set boxname to item 1 of argv
end if

tell application "Reminders"
set todos to do shell script "todor --inbox " & boxname & " list --plain"
if todos is "" then
return
end if

if not (exists list "Todor") then
make new list with properties {name:"Todor"}
end if

set mylist to list "Todor"

tell mylist
set AppleScript's text item delimiters to return
set todoLines to text items of todos
repeat with todo in todoLines
if not (exists reminder todo) then
make new reminder with properties {name:todo, body:""}
end if
end repeat
end tell
end tell
end run
10 changes: 9 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ pub enum Commands {

/// -> list all uncompeleted tasks in box
#[clap(visible_aliases(["l", "ls"]))]
List,
List {
/// including completed tasks
#[arg(short, long)]
all: bool,

/// plain mode means only show major task without styles
#[arg(long)]
plain: bool,
},

/// -> list all(including compeleted) tasks
#[clap(visible_aliases(["la"]))]
Expand Down
10 changes: 7 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ fn main() {
let mut inbox_path = util::get_inbox_file(inbox);

match args.command {
Some(Commands::List) | None => TaskBox::new(inbox_path).list(false),
Some(Commands::Listall) => TaskBox::new(inbox_path).list(true),
Some(Commands::Listall) => TaskBox::new(inbox_path).list(true, false),
Some(Commands::Enc) => TaskBox::new(inbox_path).encrypt().unwrap(),
Some(Commands::Dec) => TaskBox::new(inbox_path).decrypt().unwrap(),
Some(Commands::Routines) => TaskBox::new(get_inbox_file(ROUTINE_BOXNAME)).list(true),
Some(Commands::Routines) => TaskBox::new(get_inbox_file(ROUTINE_BOXNAME)).list(true, false),
None => TaskBox::new(inbox_path).list(false, false),

Some(Commands::List{ all, plain }) => {
TaskBox::new(inbox_path).list(all, plain)
}

Some(Commands::Count) => {
let cc = TaskBox::new(inbox_path).count();
Expand Down
10 changes: 7 additions & 3 deletions src/taskbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl TaskBox {
tasks
}

pub fn list(&mut self, listall: bool) {
pub fn list(&mut self, listall: bool, plain: bool) {
self.load();
let left : Vec<_> = self.tasks.iter().filter(|(_,done)| !done).map(|(task, _)| task.clone()).collect();
let dones : Vec<_> = self.tasks.iter().filter(|(_,done)| *done).map(|(task, _)| task.clone()).collect();
Expand All @@ -407,7 +407,7 @@ impl TaskBox {
}

if left.is_empty() {
println!(" {} left!", S_empty!("nothing"));
if ! plain { println!(" {} left!", S_empty!("nothing")); }
} else {
let mut msg;
let mut last_major_task :Option<(String, bool)> = None;
Expand Down Expand Up @@ -440,7 +440,11 @@ impl TaskBox {
msg = msg + t;
}

println!("{}", msg);
if plain {
if !t.starts_with(PREFIX_SUBT) { println!("{}", &t); }
} else {
println!("{}", msg);
}
}
}
}
Expand Down

0 comments on commit 73326b5

Please sign in to comment.