Skip to content

Write the current URL

David-Apps edited this page Oct 6, 2023 · 5 revisions

These functions write a URL (or file name) to another buffer. If writing to a buffer in another session, the functions write the URL after the current line.

The functions behave differently. If the current buffer is a web page and the current line contains one or more links, the u function writes the URL of the current page and the url function writes the URLs of the links. If the current buffer is a directory, the u function writes the path of the current file in that directory and the url function writes the path of the directory.

# Write the file name to a buffer.
# usage: <u [<session>]
function+u {
db0
H-
ebvar+
lsX
if(*) {
![ -z "~0" ]
if(*) {
ebvar-
enew
r !echo '_/'.
bw
} else {
ebvar-
e~0
r !echo '_/'.
eret
}
} else {
![ -z "~0" ]
if(*) {
ebvar-
enew
r !echo "$EB_BASE"
bw
} else {
ebvar-
e~0
r !echo "$EB_BASE"
eret
}
}
}

# Write the current URL.
# usage <url [session or file]
function:url {
db0
A
if(?) {
h
} else {
# Remove surrounding HTML code.
g/^<br><a href='.*'>$/f +,+2d
,s/^<br><a href='\(.*\)'>$/$1/f
# Replace character entity references.
,s/&apos;/'/gf
,s/&amp;/\&/gf
bw
w~0@.
if(*) {
^
} else {
w~0
if(*) {
^
} else {
w+ ~0
if(*) {
^
}
}
}
}
}