mirror of
https://github.com/denisidoro/navi
synced 2024-11-22 11:33:10 +00:00
Correctly escape backslashes (#132)
This commit is contained in:
parent
4a67ff50da
commit
bcf3f3576a
4 changed files with 15 additions and 5 deletions
2
navi
2
navi
|
@ -37,7 +37,7 @@ source "${NAVI_HOME}/src/main.sh"
|
||||||
##? full docs
|
##? full docs
|
||||||
##? Please refer to the README at https://github.com/denisidoro/navi
|
##? Please refer to the README at https://github.com/denisidoro/navi
|
||||||
|
|
||||||
VERSION="0.14.1"
|
VERSION="0.14.2"
|
||||||
NAVI_ENV="${NAVI_ENV:-prod}"
|
NAVI_ENV="${NAVI_ENV:-prod}"
|
||||||
|
|
||||||
opts::eval "$@"
|
opts::eval "$@"
|
||||||
|
|
10
src/cmd.sh
10
src/cmd.sh
|
@ -1,5 +1,13 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
cmd::escape() {
|
||||||
|
tr '\\' "$ESCAPE_CHAR_3"
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd::unescape() {
|
||||||
|
tr "$ESCAPE_CHAR_3" '\\'
|
||||||
|
}
|
||||||
|
|
||||||
cmd::loop() {
|
cmd::loop() {
|
||||||
local -r cmd="$1"
|
local -r cmd="$1"
|
||||||
local -r cheat="$2"
|
local -r cheat="$2"
|
||||||
|
@ -28,7 +36,7 @@ cmd::loop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd::finish() {
|
cmd::finish() {
|
||||||
local -r cmd="$1"
|
local -r cmd="$(echo "$1" | cmd::unescape)"
|
||||||
|
|
||||||
local -r unresolved_arg="$(echo "$cmd" | arg::next)"
|
local -r unresolved_arg="$(echo "$cmd" | arg::next)"
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ handler::preview() {
|
||||||
local -r selection="$(echo "$query" | selection::dict)"
|
local -r selection="$(echo "$query" | selection::dict)"
|
||||||
local -r cheats="$(cheat::memoized_read_all)"
|
local -r cheats="$(cheat::memoized_read_all)"
|
||||||
local -r cheat="$(cheat::from_selection "$cheats" "$selection")"
|
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() {
|
handler::help() {
|
||||||
|
|
|
@ -23,14 +23,16 @@ selection::cmd_or_comment() {
|
||||||
if echo "$core" | selection::core_is_comment; then
|
if echo "$core" | selection::core_is_comment; then
|
||||||
echo "$cheat" \
|
echo "$cheat" \
|
||||||
| grep "$core" -A999 \
|
| grep "$core" -A999 \
|
||||||
| str::last_paragraph_line
|
| str::last_paragraph_line \
|
||||||
|
| cmd::escape
|
||||||
elif $always_cmd; then
|
elif $always_cmd; then
|
||||||
echo "$core"
|
echo "$core"
|
||||||
else
|
else
|
||||||
echo "$cheat" \
|
echo "$cheat" \
|
||||||
| grep "^${core}$" -B999 \
|
| grep "^${core}$" -B999 \
|
||||||
| str::reverse_lines \
|
| str::reverse_lines \
|
||||||
| str::last_paragraph_line
|
| str::last_paragraph_line \
|
||||||
|
| cmd::escape
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue