Compare commits
6 Commits
b686140ad3
...
a561bc881a
Author | SHA1 | Date |
---|---|---|
Tim Van Baak | a561bc881a | |
Tim Van Baak | 5c69465509 | |
Tim Van Baak | bf7e19ad61 | |
Tim Van Baak | 779f96afe1 | |
Tim Van Baak | a2d8371353 | |
Tim Van Baak | 63893b0f2e |
2
Makefile
2
Makefile
|
@ -1,7 +1,7 @@
|
|||
.PHONY: *
|
||||
|
||||
build:
|
||||
./build.py out/
|
||||
./build.py out/ --draft
|
||||
pagefind --site out/
|
||||
|
||||
clean:
|
||||
|
|
17
build.py
17
build.py
|
@ -15,12 +15,22 @@ 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=["attr_list", "footnotes", "md_in_html", "meta"])
|
||||
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",
|
||||
])
|
||||
comment_md = markdown.Markdown()
|
||||
|
||||
# Map of feed url -> FeedGenerator object
|
||||
|
@ -114,7 +124,10 @@ def main():
|
|||
page.header.append(aside)
|
||||
|
||||
# RSS metadata
|
||||
if "feed" in meta and "pubdate" in meta:
|
||||
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":
|
||||
pubdate = datetime.fromisoformat(meta["pubdate"][0])
|
||||
link = f"https://www.alogoulogoi.com/{dest.relative_to(out).as_posix()}"
|
||||
for feed in meta["feed"]:
|
||||
|
|
|
@ -32,6 +32,14 @@
|
|||
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"
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -52,6 +52,11 @@ sup {
|
|||
:target {
|
||||
background: palegoldenrod;
|
||||
}
|
||||
pre {
|
||||
background: lightgray;
|
||||
padding: 5px;
|
||||
line-height: initial;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
* [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)
|
|
@ -0,0 +1,50 @@
|
|||
---
|
||||
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:~]$
|
|
@ -4,5 +4,6 @@ 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)
|
Loading…
Reference in New Issue