Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] feat(prompt): %p for percent encoded pwd
- X-seq: zsh-workers 53029
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Liao Junxuan <mikeljx@xxxxxxx>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: [PATCH] feat(prompt): %p for percent encoded pwd
- Date: Sun, 11 Aug 2024 16:28:35 +0200
- Archived-at: <https://zsh.org/workers/53029>
- In-reply-to: <20240811081900.40547-1-mikeljx@126.com>
- List-id: <zsh-workers.zsh.org>
- References: <20240811081900.40547-1-mikeljx@126.com>
On Sun, Aug 11, 2024 at 10:20 AM Liao Junxuan <mikeljx@xxxxxxx> wrote:
>
> This adds a new escape %p to allow the user to set an osc 8 sequence [1] in
> their prompt.
I use this function to URL-encode things in zsh:
function url-encode() {
emulate -L zsh -o extended_glob
local MATCH MBEGIN MEND
typeset -g
REPLY=${1//(#m)[^a-zA-Z0-9"\/:_.-!'()~"]/%${(l:2::0:)$(([##16]#MATCH))}}
}
(Please forgive a forced line break before "REPLY".)
Example:
% pwd
/home/romka/hello world
% url-encode $PWD && print -r -- $REPLY
/home/romka/hello%20world
It's suitable for generating OSC 8 and the like. I don't think I ever
wished zsh had a dedicated escape for URL-encoded $PWD.
Roman
Messages sorted by:
Reverse Date,
Date,
Thread,
Author