Skip to content

Commit

Permalink
Merge pull request #94 from cybercoder-naj/feat/add-realpath-command
Browse files Browse the repository at this point in the history
New command: `realpath`
  • Loading branch information
pimterry authored Jan 5, 2024
2 parents e4384e8 + ad23661 commit 579beeb
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ Displays the note. Shorthand alias also available with `notes c`.

Combine these together! This opens each matching note in your `$EDITOR` in turn.

### `notes realpath [note-name]`

Displays the path to the note name, if provided. Displays the root path to all notes otherwise.

## Tell me of the future

All the above works. Here's what's coming next:
Expand Down
17 changes: 17 additions & 0 deletions notes
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,19 @@ cat_note() {
cat "$note_path"
}

realpath() {
local note_path=$1

# If no note name was provided, return notes directory
if [[ -z "$note_path" ]]; then
note_path=$notes_dir
else # otherwise, get full path of note
note_path=$( get_full_note_path "$note_path" )
fi

echo "$note_path"
}

usage() {
local name=$(basename $0)
cat <<EOF
Expand All @@ -331,6 +344,7 @@ Usage:
$name mv <source> <dest>|<directory> # Rename a note, or move a note when a directory is given
$name rm [-r | --recursive] <name> # Remove note, or folder if -r or --recursive is given
$name cat|c <name> # Display note
$name realpath [name] # Display full path of note, or notes directory if no name is given
echo <name> | $name open|o # Open all note filenames piped in
echo <name> | $name cat # Display all note filenames piped in
$name --help # Print this usage information
Expand Down Expand Up @@ -397,6 +411,9 @@ main() {
"cat" | "c" )
cmd="handle_multiple_notes cat"
;;
"realpath" )
cmd="realpath"
;;
--help | -help | -h )
cmd="usage"
;;
Expand Down
36 changes: 36 additions & 0 deletions test/test-realpath.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!./test/libs/bats/bin/bats

load 'helpers'

setup() {
setupNotesEnv
}

teardown() {
teardownNotesEnv
}

export EDITOR=touch
notes="./notes"

@test "realpath should return notes_dir without a filename" {
run $notes realpath

assert_success
assert_output "$NOTES_DIRECTORY"
}

@test "realpath of non-existing notes should return the future path to the file" {
run $notes realpath note

assert_success
assert_output "$NOTES_DIRECTORY/note.md"
}

@test "realpath of any existing note should return the path to the file" {
run $notes new note
run $notes realpath note

assert_success
assert_output "$NOTES_DIRECTORY/note.md"
}

0 comments on commit 579beeb

Please sign in to comment.