datepicker

An fzf-like tool to interactively select a date in a provided format

git clone https://git.8pit.net/datepicker.git

 1## README
 2
 3An [fzf]-like tool to interactively select a date in a provided format.
 4
 5![Example usage with at(1) job scheduling](https://files.8pit.net/img/datepicker-demo-20250101.gif)
 6
 7### Motivation
 8
 9A variety of command-line utilities ([at], [journalctl], [mpick], [khal], …) allow passing dates in different formats via command-line options.
10Entering these dates in the required formats manually can be cumbersome and annoying.
11Inspired by [fzf], this utility allows visually selecting a date interactively through a TUI, thereby easing specification of dates for other command-line utilities.
12
13### Status
14
15Basic functionally is operational and works.
16However, I am not entirely happy with the keyboard navigation in the date selection view yet (see below).
17Further, the command-line interface needs some refinement, specifically additional display options from [cal] (e.g. `-m`) would be nice to have (see `TODO.md`).
18
19### Installation
20
21If you have a Haskell development environment setup and a compatible GHC version installed, you can install this utility by cloning the repository and running:
22
23	$ cabal install
24
25Alternatively, if you don't have a Haskell development environment, you can also install this software using [Guix].
26Guix will automatically install a supported GHC version for you and add the binary to your `$PATH`.
27In order to install `datepicker` this way run the following command
28
29	$ guix time-machine -C channels.scm -- package -f manifest.scm
30
31### Usage Examples
32
33By default, `datepicker` requires selection of both a date and a time and prints the selected date in the [RFC 1123] date format.
34The behavior can be customized using several command-line flags, e.g. the `-f` option allows specification of a different date format.
35This format must be specified using the format strings supported by the [formatTime] function from Haskell's `time` library.
36A few example usages are provided below.
37
38**at** — Execute a job at a specified time which is selected based on the current year (`-y`):
39
40	$ echo "ls ~" | at -m -t "$(datepicker -y -f %0Y%m%d%H%M)"
41
42**journalctl** — Select log entries newer than a given date from a span of three months (`-3`):
43
44	$ journalctl --since="$(datepicker -3 -f '%Y-%m-%d %H:%M:%S')"
45
46**mpick** — Select emails newer than a given date in the current month, skipping time selection (`-d`):
47
48	$ mlist ~/mail/INBOX | mpick -t "date >= \"$(datepicker -d -f %Y-%m-%d)\""
49
50Refer to the `--help` output for an overview of all supported command-line options.
51The command-line interface is still subject to change, more options will likely be added in future versions.
52
53### Key Bindings
54
55Two input views are provided: (1) A date selection view and (2) a time selection view.
56
57**Date Selection:**
58
59* `Esc` / `q`: Abort selection, exit with non-zero exit status
60* `Enter`: Confirm selection of focused date
61* `Up` and `Down`: Change focus to date in previous/next week
62* `Left` and `Right`: Change focus to previous/next date
63	* Note: For the first/last day of the week the focus is changed to the previous/next month
64	* This might change in a future version
65
66**Time Selection:**
67
68* `Esc` / `q`: Abort selection, exit with non-zero exit status
69* `Enter`: Confirm selection of specified time
70	* Note: If the time is invalid, confirming the selection won't be possible
71	* In a future version, this may cause an error to be emitted
72* `[0-9]`: Input a new digit at the highlighted location
73* `Backspace`: Move cursor to previous time digit
74* `Left` and `Right`: Move cursor to previous/next digit
75
76### License
77
78This program is free software: you can redistribute it and/or modify it
79under the terms of the GNU General Public License as published by the
80Free Software Foundation, either version 3 of the License, or (at your
81option) any later version.
82
83This program is distributed in the hope that it will be useful, but
84WITHOUT ANY WARRANTY; without even the implied warranty of
85MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
86Public License for more details.
87
88You should have received a copy of the GNU General Public License along
89with this program. If not, see <https://www.gnu.org/licenses/>.
90
91[fzf]: https://github.com/junegunn/fzf
92[cal]: https://manpages.debian.org/unstable/ncal/cal.1.en.html
93[at]: https://manpages.debian.org/unstable/at/at.1.en.html
94[journalctl]: https://manpages.debian.org/unstable/systemd/journalctl.1.en.html#FILTERING_OPTIONS
95[mpick]: https://manpages.debian.org/unstable/mblaze/mpick.1.en.html#EXAMPLES
96[khal]: https://manpages.debian.org/unstable/khal/khal.1.en.html
97[Guix]: https://guix.gnu.org
98[formatTime]: https://hackage.haskell.org/package/time/docs/Data-Time-Format.html#v:formatTime
99[RFC 1123]: https://datatracker.ietf.org/doc/html/rfc1123