1
0
Fork 0

Compare commits

..

No commits in common. "a561bc881a87fcbc04ad56a866388dfd76e0c22e" and "b686140ad3c2d3dfa9970573e75b942c0d0997af" have entirely different histories.

7 changed files with 3 additions and 81 deletions

View File

@ -1,7 +1,7 @@
.PHONY: *
build:
./build.py out/ --draft
./build.py out/
pagefind --site out/
clean:

View File

@ -15,22 +15,12 @@ import markdown
def main():
parser = argparse.ArgumentParser()
parser.add_argument("out", help="output directory")
parser.add_argument("--draft", action="store_true", help="include draft pages")
args = parser.parse_args()
src = pathlib.Path("src")
out = pathlib.Path(args.out)
md = markdown.Markdown(extensions=[
# Set HTML attributes with {#id}
"attr_list",
# Footnotes [^1]
"footnotes",
# Parse markdown within HTML[markdown] blocks
"md_in_html",
# "YAML" frontmatter metadata
"meta",
])
md = markdown.Markdown(extensions=["attr_list", "footnotes", "md_in_html", "meta"])
comment_md = markdown.Markdown()
# Map of feed url -> FeedGenerator object
@ -124,10 +114,7 @@ def main():
page.header.append(aside)
# RSS metadata
if "pubdate" in meta and meta["pubdate"][0] == "draft" and not args.draft:
continue
if "feed" in meta and "pubdate" in meta and meta["pubdate"][0] != "draft":
if "feed" in meta and "pubdate" in meta:
pubdate = datetime.fromisoformat(meta["pubdate"][0])
link = f"https://www.alogoulogoi.com/{dest.relative_to(out).as_posix()}"
for feed in meta["feed"]:

View File

@ -32,14 +32,6 @@
pkgs.rsync
pkgs.pagefind
];
shellHook = ''
echo "make build - compile src/ into out/ with pagefind"
echo "make clean - delete out/ and srv/"
echo "make watch - rebuild on changes"
echo "make serve - serve out/"
echo "make pubdate - replace 'now' with the current date"
echo "make upload - build to srv/ and upload to alogoulogoi"
'';
};
};
};

View File

@ -52,11 +52,6 @@ sup {
:target {
background: palegoldenrod;
}
pre {
background: lightgray;
padding: 5px;
line-height: initial;
}
</style>
</head>
<body>

View File

@ -1,3 +1,2 @@
* [SHLVL PS1](./shlvl.md)
* [Backing up my ZFS NAS to an external drive](./zfs-nas-backup.md)
* [The traditional first software engineer blog post](./blog-start.md)

View File

@ -1,50 +0,0 @@
---
title: SHLVL PS1
pubdate: 2023-12-18T09:53:17-08:00
feed: blog
---
I often find myself in a subshell, usually because of `nix-shell` or `nix develop`, but also sometimes when I run `bash` from `bash` instead of using `pushd` and `popd`. The prompting in Nix shells can be inconsistent betwen tools or versions: `nix-shell` overrides the prompt to `[nix-shell:cwd]$`, but `nix shell`, the `nix` command's replacement for `nix-shell -p`, doesn't change `PS1` at all.
I want a way to tell when I'm in a subshell so I can quit it without quitting my terminal window entirely. There is not, to my knowledge as of writing, an environment variable that distinguishes `nix shell`. However, there is a `bash` feature that helps here: the [`SHLVL`](https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-SHLVL) environment variable.
> **SHLVL**
> Incremented by one each time a new instance of Bash is started. This is intended to be a count of how deeply your Bash shells are nested.
The default `PS1` on NixOS 23.11 GNOME is this[^1]:
PS1="\n\[\033[1;32m\][\[\e]0;\u@\h: \w\a\]\u@\h:\w]\$\[\033[0m\] "
# |------------|||-----+-----------+||------||\/|---------|
# ANSI color | xterm text to prompt || ANSI color
# code to make | escape set the text || reset
# the prompt | to set title to ||
# green | title |+- $ for user, # for root
# literal [ literal ]
[^1]: [Stack Overflow explanation of xterm title escape](https://unix.stackexchange.com/questions/306716/meaning-of-e0-in-ps1-in-bashrc)
This is what I added to my `.bashrc`. I decomposed it a bit to be more legible to my future self:
_TITLE_BAR="\u@\h: \w"
_SET_TITLE_BAR="\[\e]0;$_TITLE_BAR\a\]"
_PROMPT="\A \u@\h:\w"
_SHLVL=$(printf '\$%.0s' $(seq 1 $SHLVL))
_PS1="$_SET_TITLE_BAR[$_PROMPT]$_SHLVL "
export PS1="\[\033[1;32m\]$_PS1\[\033[0m\]"
The `printf` expression here is taken from [this Stack Overflow post](https://stackoverflow.com/questions/5349718/how-can-i-repeat-a-character-in-bash); essentially, it prints the string we want to repeat (`\$`), then formats the input to 0 characters wide. Repeating inputs lets us repeat the format, which `seq` does. Now the prompt shows how many subshells we're in:
[09:04 tvbimperium:~]$ bash
[09:04 tvbimperium:~]$$ bash
[09:04 tvbimperium:~]$$$ bash
[09:04 tvbimperium:~]$$$$ bash
[09:04 tvbimperium:~]$$$$$
exit
[09:05 tvbimperium:~]$$$$
exit
[09:05 tvbimperium:~]$$$
exit
[09:05 tvbimperium:~]$$
exit
[09:05 tvbimperium:~]$

View File

@ -4,6 +4,5 @@ title: Blog
[RSS](./feed.xml)
* [SHLVL PS1](./2023/shlvl.md)
* [Backing up my ZFS NAS to an external drive](./2023/zfs-nas-backup.md)
* [The traditional first software engineer blog post](./2023/blog-start.md)