small pixel drawing of a pufferfish useposix.sh

It worky
Jes Olson j3s@c3f.net
Sat, 14 May 2022 16:17:31 -0500
commit

bd9f5adf0dc33b6792876c082938a0a0b2bba4c0

3 files changed, 89 insertions(+), 0 deletions(-)

jump to
A go.mod

@@ -0,0 +1,3 @@

+module git.j3s.sh/useposix.sh + +go 1.18
A main.go

@@ -0,0 +1,38 @@

+package main + +import ( + "fmt" + "log" + "net/http" + "path/filepath" + "html/template" + "os" +) + +func main() { + http.HandleFunc("/", rootHandler) + + log.Println("listening on :7368 tbh") + err := http.ListenAndServe(":7368", nil) + if err != nil { + log.Fatal(err) + } +} + +func rootHandler(w http.ResponseWriter, r *http.Request) { + t := filepath.Join("templates", "index.html") + _, err := os.Stat(t) + if err != nil { + fmt.Fprintf(w, err.Error()) + return + } + tmpl, err := template.ParseFiles(t) + if err != nil { + fmt.Fprintf(w, err.Error()) + return + } + err = tmpl.ExecuteTemplate(w, "wat", nil) + if err != nil { + fmt.Fprintf(w, err.Error()) + } +}
A templates/index.html

@@ -0,0 +1,48 @@

+{{ define "wat" }} +<!doctype html> +<html> +<head> + <style> + body {color: #ffffff; background-color: #222222; font-family: monospace;} + a {color: #ffffff;} + pre {color: #ffffff;} + sub {color: #4e4e4e;} + h1,h2,h4,h4,h5 {color: #ffffff96;} + </style> + + <!-- a j3s.sh production, again, lmao --> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Use POSIX Shell</title> +</head> + +<body> + <small>#!/bin/sh -eu</small> + <br> + <small>cat &lt;&lt;EOF</small> + <h4># use POSIX shell</h4> + <p>POSIX shell is portable, easy to maintain, and works for 99% of scripting use-cases.</p> + <p>command list: <a href="https://useposix.sh/commands">https://useposix.sh/commands</a></p> + <p>example: <a href="https://useposix.sh/ls">https://useposix.sh/ls</a></p> + <p>this site serves as a motivator as well as a desparate plea (USE POSIX SHELL PLS, I AM SO SICK OF ARCANE BASH SCRIPTS) and also a quick reference for POSIX compatability. it will eventually include a POSIX shellcheck interpreter. or something.</p> + <!-- lmao escape --> + + <h4># what is POSIX shell?</h4> + <p>POSIX shell is any shell script that adheres to the POSIX standard. <a href="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html">See this horrible document for excruciating details</a>. basically, if you write a shell script and follow the POSIX standard, you can mostly guarantee that it'll work _almost everywhere_.</p> + + <h4># there are two types of shell scripts in the world:</h4> + <ul>- small, portable, maintainable POSIX shell scripts</ul> + <ul>- incomprehensible spaghetti nightmare</ul> + + <h4># tips</h4> + <h4># if it starts feeling confusing as fuck, stop using shell.</h4> + <p>when you write only POSIX shell, it becomes very obvious when you should be using a real programming language. your script will begin seeming impossible to reason about. while shell is very powerful, it's also incredibly loose. it is fast and very productive, but becomes impenetrable VERY fast. if you cannot hold the entire script in your head, use a real language. for example, do you:</p> + <ul>- need arrays? stop using shell</ul> + <ul>- need strong types? stop using shell</ul> + <ul>- need a lot of dependencies? stop using shell</ul> + <ul>- need compile/runtime safety? stop using shell</ul> + <p>see how easy it is? simple, maintainable shell. or none at all.</p> + <small>EOF</small> +</body> +</html> +{{ end }}