From: Bart Schaefer <schaefer@brasslantern.com>
To: Gürkan <seqizz@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Converting relative paths to full
Date: Tue, 10 Aug 2021 15:36:58 -0700 [thread overview]
Message-ID: <CAH+w=7Y53fficKbrX_JGA6FeP1hcZDqJKjRmzC9Xd3s9nu=bxg@mail.gmail.com> (raw)
In-Reply-To: <3c2e9d50-b7c5-6e59-c29f-3d175e7bf608@gmail.com>
On Tue, Aug 10, 2021 at 2:53 PM Gürkan <seqizz@gmail.com> wrote:
>
>
> function _edit_command_to_register_full_path {
> emulate -L zsh
>
> REPLACED="$1"
> for element in `echo "$1"`; do
> # Don't care about parameters
> if [[ "$element" == -* ]]; then
> continue
> fi
> FULLPATH="${element:P}"
> if [[ -f $FULLPATH ]] || [[ -d $FULLPATH ]]; then
> REPLACED=`echo "$REPLACED" | sed "s!$element!$FULLPATH!"`
> fi
> done
> print -Sr -- ${REPLACED%%$'\n'}
> return 1
> }
That's far more complicated than necessary.
function _edit_command_to_register_full_path {
emulate -L zsh
for element in ${(z)1}; do
# Don't care about parameters
[[ $element == -* ]] && continue
FULLPATH="${element:P}"
# Don't replace when already the full path
[[ $element == $FULLPATH ]] && continue
# Don't replace when path doesn't exist
[[ -f $FULLPATH || -d $FULLPATH ]] || continue
# [[:space:]] to protect previous replacements
# (this is still not foolproof for path prefixes)
set -- "${1/[[:space:]]$element/ $FULLPATH}"
done
print -Sr -- ${1%%$'\n'}
return 1
}
next prev parent reply other threads:[~2021-08-10 22:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-10 19:53 Gürkan
2021-08-10 20:44 ` Bart Schaefer
2021-08-10 21:39 ` Gürkan
2021-08-10 21:53 ` Gürkan
2021-08-10 22:36 ` Bart Schaefer [this message]
2021-08-11 6:24 ` Gürkan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH+w=7Y53fficKbrX_JGA6FeP1hcZDqJKjRmzC9Xd3s9nu=bxg@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=seqizz@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).