From 2a29d5e6873ebe0fe46cf7a0bd007f1dd6a5364b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 2 Jan 2017 15:19:09 +1300 Subject: Work around newline-stripping in param expansion --- ISSUES.markdown | 3 --- sh/shrc.d/ad.sh | 7 +++++-- sh/shrc.d/bd.sh | 7 +++++-- sh/shrc.d/pd.sh | 7 +++++-- sh/shrc.d/rd.sh | 7 +++++-- sh/shrc.d/sd.sh | 7 +++++-- sh/shrc.d/ud.sh | 7 +++++-- 7 files changed, 30 insertions(+), 15 deletions(-) diff --git a/ISSUES.markdown b/ISSUES.markdown index cd21a33f..dda99334 100644 --- a/ISSUES.markdown +++ b/ISSUES.markdown @@ -17,6 +17,3 @@ Known issues jobspecs around that flee after a jobs builtin run; only saw this manifest after 90dcadf; either I understand job specs really poorly or this may be a bug in bash -* The directory navigation tools may not be handling directories with - terminal newlines in their names due to subshell expansion chomping them; - could maybe fix this by adding a slash to what's returned diff --git a/sh/shrc.d/ad.sh b/sh/shrc.d/ad.sh index d3e5a90a..4916b0e6 100644 --- a/sh/shrc.d/ad.sh +++ b/sh/shrc.d/ad.sh @@ -65,10 +65,13 @@ ad() { done - # Print the target - printf '%s\n' "$dir" + # Print the target with trailing slash to work around newline stripping + printf '%s/' "${dir%/}" )" + # Remove trailing slash + set -- "${1%/}" + # If the subshell printed nothing, return with failure [ -n "$1" ] || return diff --git a/sh/shrc.d/bd.sh b/sh/shrc.d/bd.sh index 1043a8cb..bf64a9aa 100644 --- a/sh/shrc.d/bd.sh +++ b/sh/shrc.d/bd.sh @@ -55,10 +55,13 @@ bd() { exit 1 fi - # Print the target - printf '%s\n' "$dirname" + # Print the target with trailing slash to work around newline stripping + printf '%s/' "${dirname%/}" )" + # Remove trailing slash + set -- "${1%/}" + # If the subshell printed nothing, return with failure [ -n "$1" ] || return diff --git a/sh/shrc.d/pd.sh b/sh/shrc.d/pd.sh index de4ea23b..ce43837b 100644 --- a/sh/shrc.d/pd.sh +++ b/sh/shrc.d/pd.sh @@ -25,10 +25,13 @@ pd() { exit 1 fi - # Print the target - printf '%s\n' "$dirname" + # Print the target with trailing slash to work around newline stripping + printf '%s/' "${dirname%/}" )" + # Remove trailing slash + set -- "${1%/}" + # If the subshell printed nothing, return with failure [ -n "$1" ] || return diff --git a/sh/shrc.d/rd.sh b/sh/shrc.d/rd.sh index 9fd99a55..3b699c0d 100644 --- a/sh/shrc.d/rd.sh +++ b/sh/shrc.d/rd.sh @@ -51,10 +51,13 @@ rd() { exit 1 fi - # Print the target - printf '%s\n' "$new" + # Print the target with trailing slash to work around newline stripping + printf '%s/' "${new%/}" )" + # Remove trailing slash + set -- "${1%/}" + # If the subshell printed nothing, return with failure [ -n "$1" ] || return diff --git a/sh/shrc.d/sd.sh b/sh/shrc.d/sd.sh index ce59bf99..4d63b7d6 100644 --- a/sh/shrc.d/sd.sh +++ b/sh/shrc.d/sd.sh @@ -72,10 +72,13 @@ sd() { ;; esac - # Print the target - printf '%s\n' "$1" + # Print the target with trailing slash to work around newline stripping + printf '%s/' "${1%/}" )" + # Remove trailing slash + set -- "${1%/}" + # If the subshell printed nothing, return with failure [ -n "$1" ] || return diff --git a/sh/shrc.d/ud.sh b/sh/shrc.d/ud.sh index 44a3a81d..79f4b5e7 100644 --- a/sh/shrc.d/ud.sh +++ b/sh/shrc.d/ud.sh @@ -34,10 +34,13 @@ ud() { exit 1 fi - # Print the target - printf '%s\n' "$dirname" + # Print the target with trailing slash to work around newline stripping + printf '%s/' "${dirname%/}" )" + # Remove trailing slash + set -- "${1%/}" + # If the subshell printed nothing, return with failure [ -n "$1" ] || return -- cgit v1.2.3