Add “configure shell to emit OSC 7” to wiki #86

Closed
opened 1 year ago by Ordoviz · 7 comments
Ordoviz commented 1 year ago

I tried to edit the wiki but noticed I don’t have access. I attached the patch.

ctrl+shift+n in the README should link to the new section. You might also want to run dos2unix on the wiki.

I tried to edit the wiki but noticed I don’t have access. I attached the patch. ctrl+shift+n in the README should link to the new section. You might also want to run `dos2unix` on the wiki.
2.6 KiB
dnkl commented 1 year ago
Owner

I tried to edit the wiki but noticed I don’t have access.

I've looked through the settings, but there doesn't appear to be a way to give "everyone" access - but maybe collaborators.

I will however add a section to the wiki describing how to do; clone the repo and open an issue with the patch, just like you did.

ctrl+shift+n in the README should link to the new section

Will do!

You might also want to run dos2unix on the wiki.

So far I've been using the web UI to edit the Wiki; hence I blame it :)

> I tried to edit the wiki but noticed I don’t have access. I've looked through the settings, but there doesn't appear to be a way to give "everyone" access - but _maybe_ collaborators. I will however add a section to the wiki describing how to do; clone the repo and open an issue with the patch, just like you did. > ctrl+shift+n in the README should link to the new section Will do! > You might also want to run dos2unix on the wiki. So far I've been using the web UI to edit the Wiki; hence I blame it :)
dnkl commented 1 year ago
Owner
+osc7_cwd() {
+	printf '\e]7;file://%s%s\a' "$HOSTNAME" "$PWD"
+}

For reference, this is what I have (zsh only though):

_urlencode() {
    setopt localoptions extendedglob
    input=( ${(s::)1} )
    print -n ${(j::)input/(#b)([^A-Za-z0-9\/:_.\!~*\'\(\)-    ])/%${(l:2::0:)$(([##16]#match))}}
}

print -Pn "\e]7;file://%M"; _urlencode "${PWD}"; print -Pn "\e\\"

Not sure how to do that in bash or fish, but might be worth mentioning for zsh at least.

+autoload -Uz add-zsh-hook
+add-zsh-hook -Uz chpwd osc7_cwd

This was nice! I have been using preexec precmd so far, but this is better!

+Alternatively, wait until the next fish release or apply [#7099][1]. This only works if you leave `TERM` at the default value: `foot`

Might be a good idea to say which version "next version" is.

+	printf '\e]7;file://%s%s\a' "$HOSTNAME" "$PWD"

Although it doesn't really matter, it is (slightly) more correct to use \e\\ as OSC terminator instead of \a ;)

```diff +osc7_cwd() { + printf '\e]7;file://%s%s\a' "$HOSTNAME" "$PWD" +} ``` For reference, this is what I have (zsh only though): ```sh _urlencode() { setopt localoptions extendedglob input=( ${(s::)1} ) print -n ${(j::)input/(#b)([^A-Za-z0-9\/:_.\!~*\'\(\)- ])/%${(l:2::0:)$(([##16]#match))}} } print -Pn "\e]7;file://%M"; _urlencode "${PWD}"; print -Pn "\e\\" ``` Not sure how to do that in bash or fish, but might be worth mentioning for zsh at least. ```diff +autoload -Uz add-zsh-hook +add-zsh-hook -Uz chpwd osc7_cwd ``` This was nice! I have been using ~~`preexec`~~ `precmd` so far, but this is better! ```diff +Alternatively, wait until the next fish release or apply [#7099][1]. This only works if you leave `TERM` at the default value: `foot` ``` Might be a good idea to say _which_ version "next version" is. ```diff + printf '\e]7;file://%s%s\a' "$HOSTNAME" "$PWD" ``` Although it doesn't _really_ matter, it is (slightly) more correct to use `\e\\` as OSC terminator instead of `\a` ;)
Poster

I personally don’t percent-encode $PWD because you don’t need it unless your directory contains a % followed by two digits (how ironic!). The solution on the wiki that users copy-paste should be as robust as possible, though. This is urlencode in pure Bash found on askubuntu:

urlencode() {
    local length="${#1}"
    for (( i = 0; i < length; i++ )); do
        local c="${1:i:1}"
        case $c in
            [a-zA-Z0-9.~_-]) printf "$c" ;;
            *) printf '%%%02X' "'$c"
        esac
    done
}

fish has urlencode builtin. In fact, the code snippet in the patch already uses it.

Might be a good idea to say which version “next version” is.

Agreed. The pull request is tagged for 3.2.0 milestone.

Although it doesn’t really matter, it is (slightly) more correct to use \e\ as OSC terminator instead of \a ;)

You know escape sequences better than me. I copied the line from fish.

I personally don’t percent-encode `$PWD` because you don’t need it unless your directory contains a `%` followed by two digits (how ironic!). The solution on the wiki that users copy-paste should be as robust as possible, though. This is urlencode in pure Bash found on [askubuntu][1]: ```bash urlencode() { local length="${#1}" for (( i = 0; i < length; i++ )); do local c="${1:i:1}" case $c in [a-zA-Z0-9.~_-]) printf "$c" ;; *) printf '%%%02X' "'$c" esac done } ``` fish has urlencode builtin. In fact, the code snippet in the patch already uses it. > Might be a good idea to say which version “next version” is. Agreed. The pull request is tagged for 3.2.0 milestone. > Although it doesn’t really matter, it is (slightly) more correct to use \e\\ as OSC terminator instead of \a ;) You know escape sequences better than me. I copied the line from fish. [1]: https://askubuntu.com/a/295312
dnkl commented 1 year ago
Owner

This is urlencode in pure Bash found on askubuntu:

Thanks for looking that up!

This is urlencode in pure Bash found on askubuntu:

Aye, saw that :)

Agreed. The pull request is tagged for 3.2.0 milestone.

Thanks!

You know escape sequences better than me. I copied the line from fish.

I'll leave it as is. It really doesn't matter, unless you care deeply about standards.

I'll try to stitch something together, based on your patch and the urlencode updates, as soon as I have some time over.

It's weird; I was just thinking, today, about OSC7 and that I should write about it on the wiki. I would only have mentioned zsh, so a big thank you for taking the time to cover the three most common shells!

> This is urlencode in pure Bash found on askubuntu: Thanks for looking that up! > This is urlencode in pure Bash found on askubuntu: Aye, saw that :) > Agreed. The pull request is tagged for 3.2.0 milestone. Thanks! > You know escape sequences better than me. I copied the line from fish. I'll leave it as is. It **really** doesn't matter, unless you care deeply about standards. I'll try to stitch something together, based on your patch and the urlencode updates, as soon as I have some time over. It's weird; I was just thinking, today, about OSC7 and that I should write about it on the wiki. I would only have mentioned zsh, so a big thank you for taking the time to cover the three most common shells!
dnkl added the
wiki
label 1 year ago
Poster

This works in Bash and Zsh:

_urlencode() {
	local length="${#1}"
	for (( i = 0; i < length; i++ )); do
		local c="${1:$i:1}"
		case $c in
			%) printf '%%%02X' "'$c" ;;
			*) printf "%s" "$c" ;;
		esac
	done
}

osc7_cwd() {
	printf '\e]7;file://%s%s\a' "$HOSTNAME" "$(_urlencode "$PWD")"
}

The previous urlencode even encoded the / necessary for seperating hostname and PWD. The new _urlencode only encodes %. Change it to your regex [^A-Za-z0-9\/:_.\!~*\'\(\)- ] if you want.

This works in Bash and Zsh: ```bash _urlencode() { local length="${#1}" for (( i = 0; i < length; i++ )); do local c="${1:$i:1}" case $c in %) printf '%%%02X' "'$c" ;; *) printf "%s" "$c" ;; esac done } osc7_cwd() { printf '\e]7;file://%s%s\a' "$HOSTNAME" "$(_urlencode "$PWD")" } ``` The previous `urlencode` even encoded the `/` necessary for seperating hostname and PWD. The new `_urlencode` only encodes `%`. Change it to your regex `[^A-Za-z0-9\/:_.\!~*\'\(\)- ]` if you want.
dnkl commented 1 year ago
Owner
How is this: https://codeberg.org/dnkl/foot/wiki#user-content-how-to-configure-my-shell-to-emit-the-osc-7-escape-sequence ?
Poster

Great, thank you!

Great, thank you!
Ordoviz closed this issue 1 year ago
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.