Skip to content

Commit e2afd35

Browse files
author
adam
committed
resolve: add the flag --pass
the `--pass` flag *passes* the query through if the search fails. passing the query through simply appends the query to the notes' absolute path, then appends '.md' and outputs the resulting string to standard output. the reason for this is wanting to edit a note despite it not existing. this is a common workflow supported by many editors, where the user is allowed to open nonexistent files until saved
1 parent 1179edf commit e2afd35

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

.readme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# goals, principles, thoughts
2+
3+
1. the product must gets out of the way.
4+
2. navigation must be flat, no hierarchy of menus to follow; aids goal 1.
5+
3. the product doesn't require or expect prior configuration; aids goal 1.
6+
4. the source code is easily modifiable; solves flexibility issues that maybe imposed by goal 3.
7+
5. the source code is the configuration; induced from 3 and 4.
8+
6. variable names are wide, clear and promoted to the top; aids 5.
9+
7. modules are split on the basis of relevance; serves 5, and 2 in spirit.
10+
8. use existing solutions when it makes sense.

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
A set of simple bash scripts for finding, opening, creating and managing notes. The scripts are simple, they don't assume much. They are meant to be easily integrated into one's preferred environment.
22

33
The following —and the source code— are the documentation:
4-
- `resolve` Takes two arguments: 1) a search query and 2) the directory containing the notes; `resolve` outputs the location of a note matching the query.
4+
- `resolve` Takes three positional arguments: 1) an optional flag (`-p` or `--pass`), 2) a search query and 3) the directory containing the notes; `resolve` outputs the absolute location of the note matching the query. if the `--pass` flag is present and no notes are found, the search query is appended to the notes' location then passed to stdout. the purpose of this is being able to resolve nonexitent files.
55
- `edit`: Takes two arguments: 1) an editor command and 2) the file path for a note. It inserts the file name at the top of the note before opening it. If the line changes, it renames the file accordingly. This allows the note's name to serve as the title. this streamlines editing
66
- `select_with_*` are scripts starting with `select_with_`. They allow selecting a note in various ways, using different menu programs, runners, launchers, etc.. The output is a file path to the selected note
77
- `select_random` outputs a random note given a notes directory

resolve

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,41 @@
44
# Finding the target of a link is no more than finding the match of an exact
55
# search by file name. If no matches are found, the script fails
66
# The script takes a search query, a location to search within
7+
# and optional flag
78

89
set -eu
910

11+
flag_pass_is_present=0;
12+
13+
if [[ "$1" == "-p" ]] || [[ "$1" == "--pass" ]];
14+
then
15+
flag_pass_is_present=1;
16+
shift;
17+
fi
18+
1019
if (($# != 2)); then
11-
echo "Usage: $0 <search query> <notes directory>"
20+
echo "Usage: $0 [-p|--pass] <search query> <notes directory>"
1221
echo "Example: $0 'Foundations of Mathematics' ~/notes"
1322
exit 1
1423
fi
1524

16-
SEARCH_QUERY="$1"
17-
NOTES_PATH="$(realpath "$2")"
25+
search_query="$1"
26+
notes_path="$(realpath "$2")"
1827

1928
FIND_COMMAND=(
2029
fd
21-
--search-path "$NOTES_PATH"
30+
--search-path "$notes_path"
2231
--type file
23-
--and "$SEARCH_QUERY.md"
32+
--and "$search_query.md"
2433
)
2534

2635
search_result="$("${FIND_COMMAND[@]}" | head -1)"
2736

28-
if [[ -z "$search_result" ]]; then
29-
exit 1
30-
else
37+
if [[ -n "$search_result" ]]; then
3138
printf '%s' "$search_result"
39+
elif [[ $flag_pass_is_present == 1 ]]; then
40+
printf '%s/%s.md' "$notes_path" "$search_query"
41+
else
42+
echo "No results found" >&2
43+
exit 1
3244
fi

select_random.sh renamed to select_random

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ FIND_COMMAND_ZERO_TERMINATED=(fd
1919
--glob '*.md'
2020
--print0)
2121

22-
echo "$NOTES_DIRECTORY"
2322
declare -a search_results
2423
readarray -d '' search_results < <("${FIND_COMMAND_ZERO_TERMINATED[@]}")
2524

0 commit comments

Comments
 (0)