aboutsummaryrefslogtreecommitdiff
path: root/lib/grep.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/grep.ml')
-rw-r--r--lib/grep.ml122
1 files changed, 70 insertions, 52 deletions
diff --git a/lib/grep.ml b/lib/grep.ml
index 3140347..7ec4c95 100644
--- a/lib/grep.ml
+++ b/lib/grep.ml
@@ -54,7 +54,8 @@ let done_get_args = [ grep_cmd; done_pattern_regexp; "-H"; "-r"; "-n"; "--no-mes
let get_done () =
let open Shexp_process in
let open Shexp_process.Infix in
- run_calls (call done_get_args |- call [ "sort"; "-n"; "-r" ])
+ try run_calls (call done_get_args |- call [ "sort"; "-n"; "-r" ]) with
+ | _ -> ""
let todo_get_args = [ grep_cmd; todo_pattern_regexp; "-H"; "-r"; "-n"; "--no-messages" ]
@@ -62,7 +63,8 @@ let todo_get_args = [ grep_cmd; todo_pattern_regexp; "-H"; "-r"; "-n"; "--no-mes
let get_todos () =
let open Shexp_process in
let open Shexp_process.Infix in
- run_calls (call todo_get_args |- call [ "sort"; "-n"; "-r" ])
+ try run_calls (call todo_get_args |- call [ "sort"; "-n"; "-r" ]) with
+ | _ -> ""
let parse_todo_files files =
@@ -99,25 +101,31 @@ let pretty_format_todo parsed_headlines =
let get_tagged_done tag () =
let open Shexp_process in
let open Shexp_process.Infix in
- eval
- (chdir
- execution_directory
- (call done_get_args
- |- call [ grep_cmd; "--no-messages"; "-E"; tag ]
- |- call [ "sort"; "-n"; "-r" ]
- |- read_all))
+ try
+ eval
+ (chdir
+ execution_directory
+ (call done_get_args
+ |- call [ grep_cmd; "--no-messages"; "-E"; tag ]
+ |- call [ "sort"; "-n"; "-r" ]
+ |- read_all))
+ with
+ | _ -> ""
let get_tagged_todo tag () =
let open Shexp_process in
let open Shexp_process.Infix in
- eval
- (chdir
- execution_directory
- (call todo_get_args
- |- call [ grep_cmd; "--no-messages"; "-E"; tag ]
- |- call [ "sort"; "-n"; "-r" ]
- |- read_all))
+ try
+ eval
+ (chdir
+ execution_directory
+ (call todo_get_args
+ |- call [ grep_cmd; "--no-messages"; "-E"; tag ]
+ |- call [ "sort"; "-n"; "-r" ]
+ |- read_all))
+ with
+ | _ -> ""
let toggle_done file_name =
@@ -167,30 +175,36 @@ let headline_args =
let get_headlines () =
let open Shexp_process in
let open Shexp_process.Infix in
- eval
- (chdir
- execution_directory
- (find_sort_name ()
- |- call headline_args
- |- call filter_todos_args
- |- call filter_done_args
- |- call [ "sort"; "-n"; "-r" ]
- |- read_all))
+ try
+ eval
+ (chdir
+ execution_directory
+ (find_sort_name ()
+ |- call headline_args
+ |- call filter_todos_args
+ |- call filter_done_args
+ |- call [ "sort"; "-n"; "-r" ]
+ |- read_all))
+ with
+ | _ -> ""
let get_tagged_headlines tag () =
let open Shexp_process in
let open Shexp_process.Infix in
- eval
- (chdir
- execution_directory
- (find_sort_name ()
- |- call headline_args
- |- call [ grep_cmd; "--no-messages"; "-E"; tag ]
- |- call filter_todos_args
- |- call filter_done_args
- |- call [ "sort"; "-n"; "-r" ]
- |- read_all))
+ try
+ eval
+ (chdir
+ execution_directory
+ (find_sort_name ()
+ |- call headline_args
+ |- call [ grep_cmd; "--no-messages"; "-E"; tag ]
+ |- call filter_todos_args
+ |- call filter_done_args
+ |- call [ "sort"; "-n"; "-r" ]
+ |- read_all))
+ with
+ | _ -> ""
let get_tags () =
@@ -228,14 +242,15 @@ let pretty_format parsed_headlines =
(** Full body parsing *)
-let get_full_content_command file = [ "cat"; file ]
-
let read_whole_file filename =
(* open_in_bin works correctly on Unix and Windows *)
- let ch = open_in_bin filename in
- let s = really_input_string ch (in_channel_length ch) in
- close_in ch;
- s
+ try
+ let ch = open_in_bin filename in
+ let s = really_input_string ch (in_channel_length ch) in
+ close_in ch;
+ s
+ with
+ | _ -> ""
let get_full_file_content_content file =
@@ -254,17 +269,20 @@ let parse_full_content files =
let get_file_names tag =
- let cmd =
- let open Shexp_process in
- let open Shexp_process.Infix in
- find_sort_name ()
- |- call [ "xargs"; grep_cmd; "-H"; "-r"; "-l"; "--no-messages"; "-E"; tag ]
- |- call [ "sort"; "-n"; "-r" ]
- |- read_all
- in
- Shexp_process.eval (Shexp_process.chdir execution_directory cmd)
- |> String.split_on_char '\n'
- |> List.filter (fun s -> not (String.equal "" s))
+ try
+ let cmd =
+ let open Shexp_process in
+ let open Shexp_process.Infix in
+ find_sort_name ()
+ |- call [ "xargs"; grep_cmd; "-H"; "-r"; "-l"; "--no-messages"; "-E"; tag ]
+ |- call [ "sort"; "-n"; "-r" ]
+ |- read_all
+ in
+ Shexp_process.eval (Shexp_process.chdir execution_directory cmd)
+ |> String.split_on_char '\n'
+ |> List.filter (fun s -> not (String.equal "" s))
+ with
+ | _ -> []
type display_type =