Browse Source

Switch highlighting to pygments.

main
tastytea 9 months ago
parent
commit
f8e31a787f
Signed by: tastytea GPG Key ID: CFC39497F1B26E07
8 changed files with 101 additions and 108 deletions
  1. +2
    -0
      archetypes/default.adoc
  2. +9
    -14
      content/posts/Editing-remote-files-with-emacs-comfortably.adoc
  3. +5
    -8
      content/posts/keep-track-of-what-you-have-read-online-with-remwharead.adoc
  4. +5
    -6
      content/posts/using-asciidoc-with-gitea.adoc
  5. +9
    -14
      content/posts/wireguard-vpn-with-2-or-more-subnets.adoc
  6. +1
    -1
      layouts/partials/extra_head.html
  7. +70
    -0
      static/monokai.css
  8. +0
    -65
      static/tomorrow_night_bright.css

+ 2
- 0
archetypes/default.adoc View File

@@ -7,3 +7,5 @@ draft: true
tags:
-
---

:source-highlighter: pygments

+ 9
- 14
content/posts/Editing-remote-files-with-emacs-comfortably.adoc View File

@@ -7,6 +7,8 @@ tags: ["emacs", "ssh"]
comtodon: 9ibPpjSsYeNmHrbBDc
---

:source-highlighter: pygments

It took me a long time to collect all the bits and pieces I needed to make
editing remote files with Emacs work the way I want, with a simple command that
works via SSH. I hope I can save you some time by stitching it here together
@@ -26,8 +28,8 @@ alphabet, we get E M A C. The server will create the file
`~/.emacs.d/server/server` with the IP, port and password in it. This file needs
to be distributed to every host that should be able to access the server.

[source,elisp]
----
{{< highlight elisp >}}
;; Run server if:
;; - Our EUID is not 0,
;; - We are not logged in via SSH,
@@ -43,7 +45,6 @@ to be distributed to every host that should be able to access the server.
:config
(unless (eq (server-running-p) t) ; Run server if not t.
(server-start)))))
{{< / highlight >}}
----

The server expects filenames as input, we can't just feed it the file. The
@@ -58,8 +59,8 @@ My modification overwrites the original value of `tramp-password-prompt-regexp`,
which has a bunch of localized variants of “password” in it. You can view the
original value with `C-h v tramp-password-prompt-regexp`.

[source,elisp]
----
{{< highlight elisp >}}
(use-package tramp
:custom
(tramp-use-ssh-controlmaster-options nil) ; Don't override SSH config.
@@ -73,7 +74,6 @@ original value with `C-h v tramp-password-prompt-regexp`.
"Verification code")
t)
".*:\0? *")))
{{< / highlight >}}
----

== SSH
@@ -96,8 +96,8 @@ Everyone on the remote host can connect to the port you forward. They will still
need the password, but you might not want to do this if you don't trust the
other users.

[source,cfg]
----
{{< highlight cfg >}}
Host fc??:* fd??:* 192.168.* server1.example.com server2.example.com
# Reuse connections.
ControlMaster auto
@@ -107,7 +107,6 @@ Host fc??:* fd??:* 192.168.* server1.example.com server2.example.com
ControlPath ~/.ssh/sockets/%r@%h-%p
# Forward Emacs-server port.
RemoteForward 127.0.0.1:51313 127.0.0.1:51313
{{< / highlight >}}
----

== Wrapper for emacsclient
@@ -120,8 +119,8 @@ using sudo] and an option to use it with local servers. This file needs to be
distributed to every host that should be able to access the server.

.https://dotfiles.tastytea.de/bin/emacsremote[emacsremote]
[source,shell]
----
{{< highlight bash >}}
#!/bin/bash
# Open file on a remote Emacs server.
# https://andy.wordpress.com/2013/01/03/automatic-emacsclient/ with added sudo.
@@ -161,7 +160,6 @@ for p in "${@}"; do
done

emacsclient -f ~/.emacs.d/server/server "${params[@]}"
{{< / highlight >}}
----

I had to add `[[ "${TERM}" = "dumb" ]] && unsetopt zle` to my Zsh configuration
@@ -177,8 +175,8 @@ print an error message).

NOTE: I wrote the following code for Zsh, but it should also work for Bash.

[source,shell]
----
{{< highlight zsh >}}
# Set preferred editor.
if command -v emacsclient > /dev/null; then
VISUAL="$(command -v emacsclient) -f ~/.emacs.d/server/server -a emacs"
@@ -199,11 +197,10 @@ elif command -v nano > /dev/null; then
fi
export VISUAL
export EDITOR="${VISUAL}"
{{< / highlight >}}
----

[source,shell]
----
{{< highlight zsh >}}
if [[ "${VISUAL}" =~ "emacs(client|remote)" ]]; then
alias e="${VISUAL} -n"
if [[ "${VISUAL}" =~ "emacsremote$" ]]; then
@@ -217,16 +214,14 @@ else
alias e="${VISUAL}"
alias se="sudo ${VISUAL}"
fi
{{< / highlight >}}
----

To detect SSH connections after using `sudo -i`, we have to tell sudo to
preserve the environment variable `SSH_CONNECTION`.

[source,shell]
----
{{< highlight zsh >}}
echo 'Defaults env_keep += "SSH_CONNECTION"' >> /etc/sudoers.d/ssh_vars
{{< / highlight >}}
----

== Updates


+ 5
- 8
content/posts/keep-track-of-what-you-have-read-online-with-remwharead.adoc View File

@@ -7,6 +7,7 @@ tags: ["remwharead", "bookmarks", "archive", "Tooting my own horn"]
comtodon: 9nIqtmAXvu4harUb7Q
---

:source-highlighter: pygments
:wp-asciidoc: https://en.wikipedia.org/wiki/AsciiDoc
:wp-rss: https://en.wikipedia.org/wiki/RSS
:wp-json: https://en.wikipedia.org/wiki/JSON
@@ -70,10 +71,9 @@ But most of the time you'll probably want to use {uri-ff-addon}[remwhareadFF],
the Firefox extension.

.Example: Save this article with the tags remwharead, bookmarks and archive.
[source,shell]
----
{{< highlight shell >}}
remwharead -t remwharead,bookmarks,archive https://blog.tastytea.de/posts/keep-track-of-what-you-have-read-online-with-remwharead/
{{< / highlight >}}
----

remwharead will automatically ask the Wayback machine from the
@@ -90,28 +90,26 @@ and `--search-all` with {uri-perlre}[regular expressions], with `-r` or
`--regex`.

.Example: Display all things you saved on 2019-09-23.
[source,shellsession]
----
{{< highlight shellsession >}}
% remwharead -e simple -T 2019-09-23,2019-09-24
2019-09-23: Keep track of what you've read online with remwharead
<https://blog.tastytea.de/posts/keep-track-of-what-you-have-read-online-with-remwharead/>
2019-09-23: Another good article
<https://example.com/good-article.html>
{{< / highlight >}}
----

Times are in the format _YYYY-MM-DDThh:mm:ss_. `2019-09-23` is short for
`2019-09-23T00:00:00`.

.Example: Display all things you tagged with “apple” or “onion”.
[source,shellsession]
----
{{< highlight shellsession >}}
% remwharead -e simple -s "apple OR onion"
2019-08-03: The best onion soup recipe of the whole internet!
<https://example.com/onion-soup.html>
2019-04-12: 5 funny faces you can carve into YOUR apple today!
<https://example.com/apple-faces.html>
{{< / highlight >}}
----

Most export formats show only a portion of the available data for readability
@@ -130,15 +128,14 @@ should have. You probably also want to change the title from “Visited things
something more descriptive.

.Example: Shell script to create a valid RSS feed of the last week.
[source,shell]
----
{{< highlight shell >}}
#!/bin/sh

remwharead -e rss -T $(date -d "-1 week" -I),$(date -Iminutes) \
| sed -e 's|<link/>|<link>https://example.com/</link>|' \
-e "s|<title>Visited things|<title>My hyperlink archive|" \
> /var/www/feed.rss
{{< / highlight >}}
----

TIP: Put that script into `/etc/cron.hourly/` to update your feed once an hour.

+ 5
- 6
content/posts/using-asciidoc-with-gitea.adoc View File

@@ -8,6 +8,8 @@ tags:
- gitea
---

:source-highlighter: pygments

In this blogpost I describe what I did to get AsciiDoc support into
https://gitea.io/[Gitea]. If you want more than syntax highlighting and basic
formatting, Gitea has to be patched unfortunately(this
@@ -25,15 +27,14 @@ want to use it you can use http://asciidoc.org/[AsciiDoc].
Add the following section to `conf/app.ini` in your Gitea path. The change
causes `.adoc` files to be rendered with asciidoctor.

[source,ini]
----
{{< highlight ini >}}[markup.asciidoc]
ENABLED = true
; List of file extensions that should be rendered by an external command
FILE_EXTENSIONS = .adoc,.asciidoc
; External command to render all matching extensions
RENDER_COMMAND = "asciidoctor --backend=html5 --no-header-footer --attribute source-highlighter=highlightjs --out-file=- -"
; Don't pass the file on STDIN, pass the filename as argument instead.
IS_INPUT_FILE = false{{< / highlight >}}
----

If you want to use asciidoc instead the command would be:
@@ -66,8 +67,8 @@ and the `class` exception is only useful if you add custom CSS to use them.

Apply the patch with `patch -p1 < gitea_relax-sanitizer.patch`.

[source,diff]
----
{{< highlight diff >}}
diff --git a/modules/markup/sanitizer.go b/modules/markup/sanitizer.go
index fd6f90b2a..ae11811b6 100644
--- a/modules/markup/sanitizer.go
@@ -89,7 +90,6 @@ index fd6f90b2a..ae11811b6 100644
+ sanitizer.policy.AllowAttrs("align", "valign").OnElements("td")
})
}
{{< / highlight >}}
----

== Tables without borders
@@ -100,8 +100,8 @@ snippet.

In your Gitea directory, create `custom/templates/custom/header.tmpl`.

[source,css]
----
{{< highlight css >}}<style>
/* Additions for asciidoc */
.markdown:not(code) table.frame-none
{
@@ -111,7 +111,6 @@ In your Gitea directory, create `custom/templates/custom/header.tmpl`.
{
border: 0 !important;
}
</style>{{< / highlight >}}
----

== Updates


+ 9
- 14
content/posts/wireguard-vpn-with-2-or-more-subnets.adoc View File

@@ -9,6 +9,8 @@ tags:
comtodon: 9fqBQKGZa6qMf98wIC
---

:source-highlighter: pygments

I wanted to create a https://en.wikipedia.org/wiki/WireGuard[WireGuard] VPN with
2 subnets in different physical places, each with their own server. I couldn't
find an example how to do that, so I wrote this one.
@@ -32,23 +34,21 @@ will connect to `server2`. `server1` and `server2` will be connected. If
https://www.wireguard.com/install/[Install WireGuard], create `/etc/wireguard`
and generate a key-pair on each participating peer.

[source,shell]
----
{{< highlight sh >}}
mkdir /etc/wireguard
cd /etc/wireguard
umask 077
wg genkey | tee privatekey | wg pubkey > publickey
{{< / highlight >}}
----

== Configure servers

.Turn on IP forwarding:
[source,shell]
----
{{< highlight sh >}}
echo "net.ipv6.conf.all.forwarding = 1" > /etc/sysctl.d/ip-forward.conf
sysctl -p /etc/sysctl.d/ip-forward.conf
{{< / highlight >}}
----

[NOTE]
@@ -57,8 +57,8 @@ it will no longer autoconfigure via https://en.wikipedia.org/wiki/SLAAC[SLAAC].
If you need SLAAC, add `net.ipv6.conf.DEVICE.accept_ra = 2` to `ip-forward.conf`.

.`server1:/etc/wireguard/wg0.conf`:
[source,cfg]
----
{{< highlight cfg >}}
# This peer
[Interface]
Address = fd69:0:0:1::1/48
@@ -79,12 +79,11 @@ AllowedIPs = fd69:0:0:1::a/128
[Peer]
PublicKey = <PUBLIC KEY OF client1b>
AllowedIPs = fd69:0:0:1::b/128
{{< / highlight >}}
----

.`server2:/etc/wireguard/wg0.conf`:
[source,cfg]
----
{{< highlight cfg >}}
# This peer
[Interface]
Address = fd69:0:0:2::1/48
@@ -101,14 +100,13 @@ AllowedIPs = fd69:0:0:1::/64
[Peer]
PublicKey = <PUBLIC KEY OF client2a>
AllowedIPs = fd69:0:0:2::a/128
{{< / highlight >}}
----

== Configure clients

.`client1a:/etc/wireguard/wg0.conf`:
[source,cfg]
----
{{< highlight cfg >}}
[Interface]
Address = fd69:0:0:1::a/48
PrivateKey = <PRIVATE KEY OF client1a>
@@ -118,12 +116,11 @@ PublicKey = <PUBLIC KEY OF server1>
Endpoint = server1:51820
AllowedIPs = fd69::/48
PersistentKeepalive = 25
{{< / highlight >}}
----

.`client1b:/etc/wireguard/wg0.conf`:
[source,cfg]
----
{{< highlight cfg >}}
[Interface]
Address = fd69:0:0:1::b/48
PrivateKey = <PRIVATE KEY OF client1b>
@@ -133,12 +130,11 @@ PublicKey = <PUBLIC KEY OF server1>
Endpoint = server1:51820
AllowedIPs = fd69::/48
PersistentKeepalive = 25
{{< / highlight >}}
----

.`client2a:/etc/wireguard/wg0.conf`:
[source,cfg]
----
{{< highlight cfg >}}
[Interface]
Address = fd69:0:0:2::a/48
PrivateKey = <PRIVATE KEY OF client2a>
@@ -148,7 +144,6 @@ PublicKey = <PUBLIC KEY OF server2>
Endpoint = server1:51820
AllowedIPs = fd69::/48
PersistentKeepalive = 25
{{< / highlight >}}
----

The `AllowedIPs` setting acts as a routing table. When a peer tries to send a


+ 1
- 1
layouts/partials/extra_head.html View File

@@ -1,2 +1,2 @@
<link rel="stylesheet" href="/comtodon.css"/>
<link rel="stylesheet" href="/tomorrow_night_bright.css"/>
<link rel="stylesheet" href="/monokai.css"/>

+ 70
- 0
static/monokai.css View File

@@ -0,0 +1,70 @@
.highlight .tok-hll { background-color: #49483e }
.highlight { background: #272822; color: #f8f8f2 }
.highlight .tok-c { color: #75715e } /* Comment */
.highlight .tok-err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .tok-k { color: #66d9ef } /* Keyword */
.highlight .tok-l { color: #ae81ff } /* Literal */
.highlight .tok-n { color: #f8f8f2 } /* Name */
.highlight .tok-o { color: #f92672 } /* Operator */
.highlight .tok-p { color: #f8f8f2 } /* Punctuation */
.highlight .tok-ch { color: #75715e } /* Comment.Hashbang */
.highlight .tok-cm { color: #75715e } /* Comment.Multiline */
.highlight .tok-cp { color: #75715e } /* Comment.Preproc */
.highlight .tok-cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .tok-c1 { color: #75715e } /* Comment.Single */
.highlight .tok-cs { color: #75715e } /* Comment.Special */
.highlight .tok-gd { color: #f92672 } /* Generic.Deleted */
.highlight .tok-ge { font-style: italic } /* Generic.Emph */
.highlight .tok-gi { color: #a6e22e } /* Generic.Inserted */
.highlight .tok-gs { font-weight: bold } /* Generic.Strong */
.highlight .tok-gu { color: #75715e } /* Generic.Subheading */
.highlight .tok-kc { color: #66d9ef } /* Keyword.Constant */
.highlight .tok-kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .tok-kn { color: #f92672 } /* Keyword.Namespace */
.highlight .tok-kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .tok-kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .tok-kt { color: #66d9ef } /* Keyword.Type */
.highlight .tok-ld { color: #e6db74 } /* Literal.Date */
.highlight .tok-m { color: #ae81ff } /* Literal.Number */
.highlight .tok-s { color: #e6db74 } /* Literal.String */
.highlight .tok-na { color: #a6e22e } /* Name.Attribute */
.highlight .tok-nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .tok-nc { color: #a6e22e } /* Name.Class */
.highlight .tok-no { color: #66d9ef } /* Name.Constant */
.highlight .tok-nd { color: #a6e22e } /* Name.Decorator */
.highlight .tok-ni { color: #f8f8f2 } /* Name.Entity */
.highlight .tok-ne { color: #a6e22e } /* Name.Exception */
.highlight .tok-nf { color: #a6e22e } /* Name.Function */
.highlight .tok-nl { color: #f8f8f2 } /* Name.Label */
.highlight .tok-nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .tok-nx { color: #a6e22e } /* Name.Other */
.highlight .tok-py { color: #f8f8f2 } /* Name.Property */
.highlight .tok-nt { color: #f92672 } /* Name.Tag */
.highlight .tok-nv { color: #f8f8f2 } /* Name.Variable */
.highlight .tok-ow { color: #f92672 } /* Operator.Word */
.highlight .tok-w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .tok-mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .tok-mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .tok-mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .tok-mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .tok-mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .tok-sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .tok-sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .tok-sc { color: #e6db74 } /* Literal.String.Char */
.highlight .tok-dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .tok-sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .tok-s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .tok-se { color: #ae81ff } /* Literal.String.Escape */
.highlight .tok-sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .tok-si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .tok-sx { color: #e6db74 } /* Literal.String.Other */
.highlight .tok-sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .tok-s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .tok-ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .tok-bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .tok-fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .tok-vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .tok-vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .tok-vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .tok-vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .tok-il { color: #ae81ff } /* Literal.Number.Integer.Long */

+ 0
- 65
static/tomorrow_night_bright.css View File

@@ -1,65 +0,0 @@
.highlight .hll { background-color: #424242 }
.highlight { background: #000000; color: #eaeaea }
.highlight .c { color: #969896 } /* Comment */
.highlight .err { color: #d54e53 } /* Error */
.highlight .k { color: #c397d8 } /* Keyword */
.highlight .l { color: #e78c45 } /* Literal */
.highlight .n { color: #eaeaea } /* Name */
.highlight .o { color: #70c0b1 } /* Operator */
.highlight .p { color: #eaeaea } /* Punctuation */
.highlight .cm { color: #969896 } /* Comment.Multiline */
.highlight .cp { color: #969896 } /* Comment.Preproc */
.highlight .c1 { color: #969896 } /* Comment.Single */
.highlight .cs { color: #969896 } /* Comment.Special */
.highlight .gd { color: #d54e53 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gh { color: #eaeaea; font-weight: bold } /* Generic.Heading */
.highlight .gi { color: #b9ca4a } /* Generic.Inserted */
.highlight .gp { color: #969896; font-weight: bold } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #70c0b1; font-weight: bold } /* Generic.Subheading */
.highlight .kc { color: #c397d8 } /* Keyword.Constant */
.highlight .kd { color: #c397d8 } /* Keyword.Declaration */
.highlight .kn { color: #70c0b1 } /* Keyword.Namespace */
.highlight .kp { color: #c397d8 } /* Keyword.Pseudo */
.highlight .kr { color: #c397d8 } /* Keyword.Reserved */
.highlight .kt { color: #e7c547 } /* Keyword.Type */
.highlight .ld { color: #b9ca4a } /* Literal.Date */
.highlight .m { color: #e78c45 } /* Literal.Number */
.highlight .s { color: #b9ca4a } /* Literal.String */
.highlight .na { color: #7aa6da } /* Name.Attribute */
.highlight .nb { color: #eaeaea } /* Name.Builtin */
.highlight .nc { color: #e7c547 } /* Name.Class */
.highlight .no { color: #d54e53 } /* Name.Constant */
.highlight .nd { color: #70c0b1 } /* Name.Decorator */
.highlight .ni { color: #eaeaea } /* Name.Entity */
.highlight .ne { color: #d54e53 } /* Name.Exception */
.highlight .nf { color: #7aa6da } /* Name.Function */
.highlight .nl { color: #eaeaea } /* Name.Label */
.highlight .nn { color: #e7c547 } /* Name.Namespace */
.highlight .nx { color: #7aa6da } /* Name.Other */
.highlight .py { color: #eaeaea } /* Name.Property */
.highlight .nt { color: #70c0b1 } /* Name.Tag */
.highlight .nv { color: #d54e53 } /* Name.Variable */
.highlight .ow { color: #70c0b1 } /* Operator.Word */
.highlight .w { color: #eaeaea } /* Text.Whitespace */
.highlight .mf { color: #e78c45 } /* Literal.Number.Float */
.highlight .mh { color: #e78c45 } /* Literal.Number.Hex */
.highlight .mi { color: #e78c45 } /* Literal.Number.Integer */
.highlight .mo { color: #e78c45 } /* Literal.Number.Oct */
.highlight .sb { color: #b9ca4a } /* Literal.String.Backtick */
.highlight .sc { color: #eaeaea } /* Literal.String.Char */
.highlight .sd { color: #969896 } /* Literal.String.Doc */
.highlight .s2 { color: #b9ca4a } /* Literal.String.Double */
.highlight .se { color: #e78c45 } /* Literal.String.Escape */
.highlight .sh { color: #b9ca4a } /* Literal.String.Heredoc */
.highlight .si { color: #e78c45 } /* Literal.String.Interpol */
.highlight .sx { color: #b9ca4a } /* Literal.String.Other */
.highlight .sr { color: #b9ca4a } /* Literal.String.Regex */
.highlight .s1 { color: #b9ca4a } /* Literal.String.Single */
.highlight .ss { color: #b9ca4a } /* Literal.String.Symbol */
.highlight .bp { color: #eaeaea } /* Name.Builtin.Pseudo */
.highlight .vc { color: #d54e53 } /* Name.Variable.Class */
.highlight .vg { color: #d54e53 } /* Name.Variable.Global */
.highlight .vi { color: #d54e53 } /* Name.Variable.Instance */
.highlight .il { color: #e78c45 } /* Literal.Number.Integer.Long */

Loading…
Cancel
Save