From 75ce5c5072d9df34d74857c0f908b7e6e27e04b0 Mon Sep 17 00:00:00 2001 From: delphinus Date: Thu, 22 Oct 2020 23:00:38 +0900 Subject: [PATCH 1/2] Enable to create notes including '$' in filenames --- nb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nb b/nb index 3466faf94..c7496422d 100755 --- a/nb +++ b/nb @@ -1240,7 +1240,8 @@ Can't edit archives. Export archive and expand to edit.\\n" touch "${_file_path:-}" fi - eval "${_editor_command} \"${_file_path}\"" + escaped=${_file_path//$/\\$} + eval "${_editor_command} \"$escaped\"" fi } From eabc1b1cafd08b5ea2aa9a15856d202abb72fed3 Mon Sep 17 00:00:00 2001 From: delphinus Date: Thu, 22 Oct 2020 23:01:13 +0900 Subject: [PATCH 2/2] Detect filenames including odd chars: '[' '*' --- nb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nb b/nb index c7496422d..242a66936 100755 --- a/nb +++ b/nb @@ -5720,7 +5720,8 @@ _index() { # grep -n "^${1:-}$" "${2:-}" | cut -f1 -d: # awk 'match($0,v){print NR; exit}' v="^${1:-}$" "${2:-}" # rg --color=never --line-number "^${1:-}$" "${2:-}" | cut -d: -f1 - sed -n "/^${1:-}$/=" "${2:-}" + escaped=$(printf "%s" "${1:-}" | sed -e 's/[\[\*]/\\&/g') + sed -n "/^$escaped$/=" "${2:-}" } local _basename="${2:-}" @@ -6428,7 +6429,8 @@ HEREDOC local _item_identifier= # use `sed` directly instead of `_index get_id` for performance _item_identifier="$( - sed -n "/^${__basename:-}$/=" "${_notebook_path:-}/.index" + escaped=$(printf "%s" "${__basename:-}" | sed -e 's/[\[\*]/\\&/g') + sed -n "/^$escaped$/=" "${_notebook_path:-}/.index" )" local _max_identifier="${_max_id}"