summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Isidoro <denisidoro@users.noreply.github.com>2019-10-18 13:21:11 -0300
committerGitHub <noreply@github.com>2019-10-18 13:21:11 -0300
commitbcf3f3576a202aa66ea79212d86ee95ce62abbcb (patch)
treefa00833120ba777d5b7d1b6fc041a998b6e1901d
parent4a67ff50da138c31a935a82f63804a1ac5ddf140 (diff)
Correctly escape backslashes (#132)v0.14.2
-rwxr-xr-xnavi2
-rw-r--r--src/cmd.sh10
-rw-r--r--src/main.sh2
-rw-r--r--src/selection.sh6
4 files changed, 15 insertions, 5 deletions
diff --git a/navi b/navi
index d0bdc7e..44aa585 100755
--- a/navi
+++ b/navi
@@ -37,7 +37,7 @@ source "${NAVI_HOME}/src/main.sh"
##? full docs
##? Please refer to the README at https://github.com/denisidoro/navi
-VERSION="0.14.1"
+VERSION="0.14.2"
NAVI_ENV="${NAVI_ENV:-prod}"
opts::eval "$@"
diff --git a/src/cmd.sh b/src/cmd.sh
index 8e74282..4df7689 100644
--- a/src/cmd.sh
+++ b/src/cmd.sh
@@ -1,5 +1,13 @@
#!/usr/bin/env bash
+cmd::escape() {
+ tr '\\' "$ESCAPE_CHAR_3"
+}
+
+cmd::unescape() {
+ tr "$ESCAPE_CHAR_3" '\\'
+}
+
cmd::loop() {
local -r cmd="$1"
local -r cheat="$2"
@@ -28,7 +36,7 @@ cmd::loop() {
}
cmd::finish() {
- local -r cmd="$1"
+ local -r cmd="$(echo "$1" | cmd::unescape)"
local -r unresolved_arg="$(echo "$cmd" | arg::next)"
diff --git a/src/main.sh b/src/main.sh
index 26a481e..0457ac1 100644
--- a/src/main.sh
+++ b/src/main.sh
@@ -53,7 +53,7 @@ handler::preview() {
local -r selection="$(echo "$query" | selection::dict)"
local -r cheats="$(cheat::memoized_read_all)"
local -r cheat="$(cheat::from_selection "$cheats" "$selection")"
- [ -n "$cheat" ] && selection::cmd_or_comment "$selection" "$cheat"
+ [ -n "$cheat" ] && selection::cmd_or_comment "$selection" "$cheat" | cmd::unescape
}
handler::help() {
diff --git a/src/selection.sh b/src/selection.sh
index 86b5e9d..a88c132 100644
--- a/src/selection.sh
+++ b/src/selection.sh
@@ -23,14 +23,16 @@ selection::cmd_or_comment() {
if echo "$core" | selection::core_is_comment; then
echo "$cheat" \
| grep "$core" -A999 \
- | str::last_paragraph_line
+ | str::last_paragraph_line \
+ | cmd::escape
elif $always_cmd; then
echo "$core"
else
echo "$cheat" \
| grep "^${core}$" -B999 \
| str::reverse_lines \
- | str::last_paragraph_line
+ | str::last_paragraph_line \
+ | cmd::escape
fi
}