-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect_with_bemenu
executable file
·49 lines (42 loc) · 1.28 KB
/
select_with_bemenu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
# The following script selects a note using bemenu.
# It takes a single argument: the note directory.
# It then presents all *.md files within the directory.
# It outputs the file path of the slected note.
#
# bemenue supports priting the search query regradless of whether it matches a
# note or not. this allows editing nonexistent files, or in another sense
# creating a note if it doesn't already exist (assuming the program consuming
# the path supports opening files and creating them later, i.e. most editors)
# error on missing variables and failed piplines
set -eu
declare NOTES_DIRECTORY
if (($# != 1)); then
echo "expected exactly one argument, namely the notes directory"
echo "usage: $0 <notes_direcoty>"
exit 1
fi
FIND_COMMAND=(
fd
--type file
--and '.md$'
#--print0 # outputs a NUL separated list
)
BEMENU_FLAGS=(
--list 38
--ignorecase
--fixed-height
--prompt "Open Note"
-B2
--tf='#33ccff'
--hb='#44ddff'
--hf='#000000'
--bdr='#33ccff'
--bottom
--no-exec
)
NOTES_DIRECTORY="$(realpath $1)" # to normalize the path
cd "$NOTES_DIRECTORY" || exit 1
result=$("${FIND_COMMAND[@]}" | sed 's|^'$NOTES_DIRECTORY/'||' | sed 's|.md$||' | bemenu "${BEMENU_FLAGS[@]}")
[[ -z "$result" ]] && exit 1;
printf '%s' "$NOTES_DIRECTORY/$result.md"