Convert the fs README to use a Cog list of scripts
- ID
139561e- date
2023-12-26 15:27:43+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
3e1bb06- message
Convert the fs README to use a Cog list of scripts- changed files
3 files, 115 additions, 37 deletions
Changed files
cog_helpers.py (1585) → cog_helpers.py (1962)
diff --git a/cog_helpers.py b/cog_helpers.py
index e8e5bca..fc0c35e 100644
--- a/cog_helpers.py
+++ b/cog_helpers.py
@@ -18,12 +18,17 @@ class ScriptWithName(TypedDict):
description: str
+class ScriptWithVariants(TypedDict):
+ variants: list[str]
+ description: str
+
+
class ScriptWithUsage(TypedDict):
usage: str
description: str
-Script = ScriptWithName | ScriptWithUsage
+Script = ScriptWithName | ScriptWithUsage | ScriptWithVariants
def outl(s: str, indent: int = 0):
@@ -39,23 +44,34 @@ def create_description_table(
outl("<dl>")
for i, s in enumerate(scripts, start=1):
- try:
- name = s["name"]
- except KeyError:
- name = s["usage"].split()[0]
-
- try:
- usage = s["usage"]
- except KeyError:
- usage = name
+ if "name" in s:
+ variants = [s["name"]]
+ elif "variants" in s:
+ variants = s["variants"]
+ else:
+ variants = [s["usage"].split()[0]]
outl("<dt>", indent=2)
- outl(
- f'<a href="https://github.com/{repo_name}/blob/{primary_branch}/{folder_name}/{name}">',
- indent=4,
- )
- outl(f"<code>{usage}</code>", indent=6)
- outl("</a>", indent=4)
+
+ for index, v in enumerate(variants, start=1):
+ name = v.split()[0]
+
+ outl(
+ f'<a href="https://github.com/{repo_name}/blob/{primary_branch}/{folder_name}/{name}">',
+ indent=4,
+ )
+
+ try:
+ usage = s["usage"]
+ except KeyError:
+ usage = v
+
+ outl(f"<code>{usage}</code>", indent=6)
+ outl("</a>", indent=4)
+
+ if index != len(variants):
+ outl("/")
+
outl("</dt>", indent=2)
outl("<dd>", indent=2)
fs/README.md (2396) → fs/README.md (4350)
diff --git a/fs/README.md b/fs/README.md
index 550e798..c68b3e8 100644
--- a/fs/README.md
+++ b/fs/README.md
@@ -4,6 +4,74 @@ These are scripts for manipulating files and folders in my local filesystem.
## The individual scripts
+<!-- [[[cog
+
+# This adds the root of the repo to the PATH, which has cog_helpers.py
+from os.path import abspath, dirname
+import sys
+
+sys.path.append(abspath(dirname(dirname("."))))
+
+import cog_helpers
+
+folder_name = "fs"
+
+scripts = [
+ {
+ "name": "cdir",
+ "description": """
+ counts all the entries in subfolders under the working directory, and prints them in a table
+ <p><pre><code>$ cdir
+ 37 fishconfig
+ 48 repros
+ 51 colossus-wheels
+ 70 services
+ 292 .git
+ -------
+ 699</code></pre></p>
+ """
+ },
+ {
+ "usage": "deepestdir [ROOT]",
+ "description": "prints the directory which is the deepest child of the given directory"
+ },
+ {
+ "name": "emptydir",
+ "description": "removes any empty directories under the current one (including directories that are empty aside from files that can be safely deleted, e.g. <code>.DS_Store</code>)"
+ },
+ {
+ "name": "flatten",
+ "description": """
+ flattens a directory structure.
+ When you run it in a folder, it moves any files in subfolders into the top-level folders, then deletes the now-empty folder.
+ """
+ },
+ {
+ "variants": ["hide [PATH]", "unhide [PATH]"],
+ "description": "alias for `chflags hidden PATH` and <code>chflags nohidden PATH</code>."
+ },
+ {
+ "name": "latest_download",
+ "description": "prints the path to the newest file in my Downloads folder"
+ },
+ {
+ "name": "sizes",
+ "description": """
+ gets the total size of all the files/folders under the working directory, and prints them in a table
+ <p><pre><code>$ sizes
+ 512.00K aws/
+ 520.00K wellcome/
+ 1.54M images/
+ 4.76M .git/
+ -------
+ 7.58M ~/repos/scripts</code></pre></p>
+ """
+ },
+]
+
+cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
+
+]]]-->
<dl>
<dt>
<a href="https://github.com/alexwlchan/scripts/blob/main/fs/cdir">
@@ -18,7 +86,7 @@ These are scripts for manipulating files and folders in my local filesystem.
51 colossus-wheels
70 services
292 .git
--------
+ -------
699</code></pre></p>
</dd>
@@ -54,10 +122,13 @@ These are scripts for manipulating files and folders in my local filesystem.
<a href="https://github.com/alexwlchan/scripts/blob/main/fs/hide">
<code>hide [PATH]</code>
</a>
+/
+ <a href="https://github.com/alexwlchan/scripts/blob/main/fs/unhide">
+ <code>unhide [PATH]</code>
+ </a>
</dt>
<dd>
- alias for <code>chflags hidden PATH</code>.
- See also: <code>unhide</code>.
+ alias for `chflags hidden PATH` and <code>chflags nohidden PATH</code>.
</dd>
<dt>
@@ -77,21 +148,12 @@ These are scripts for manipulating files and folders in my local filesystem.
<dd>
gets the total size of all the files/folders under the working directory, and prints them in a table
<p><pre><code>$ sizes
-512.00K aws/
-520.00K wellcome/
- 1.54M images/
- 4.76M .git/
--------
- 7.58M ~/repos/scripts</code></pre></p>
- </dd>
-
- <dt>
- <a href="https://github.com/alexwlchan/scripts/blob/main/fs/unhide">
- <code>unhide [PATH]</code>
- </a>
- </dt>
- <dd>
- alias for <code>chflags nohidden PATH</code>.
- See also: <code>hide</code>.
+ 512.00K aws/
+ 520.00K wellcome/
+ 1.54M images/
+ 4.76M .git/
+ -------
+ 7.58M ~/repos/scripts</code></pre></p>
</dd>
</dl>
+<!-- [[[end]]] (checksum: f58d126f6b43914a355f95c7476ecd35) -->
macos/README.md (5436) → macos/README.md (5428)
diff --git a/macos/README.md b/macos/README.md
index cceac94..d70ab52 100644
--- a/macos/README.md
+++ b/macos/README.md
@@ -126,7 +126,7 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
</dd>
<dt>
- <a href="https://github.com/alexwlchan/scripts/blob/main/macos/get_live_text [image]">
+ <a href="https://github.com/alexwlchan/scripts/blob/main/macos/get_live_text">
<code>get_live_text [image]</code>
</a>
</dt>
@@ -173,4 +173,4 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
</p>
</dd>
</dl>
-<!-- [[[end]]] (checksum: f83d99f7ee2b7ffd54416fcc1b1cb01e) -->
+<!-- [[[end]]] (checksum: 92219c4a3477e066af5311a2e97e1db6) -->