- das-shell 0.3.0: aliases and functions for every interactive bash (/usr/share/das/shell, loaded by /etc/bash/bashrc.d/das-aliases.sh, then the user's ~/.bash_aliases and ~/.bash_functions; off with ~/.config/das/no-aliases). Based on the author's own set, adapted to Void (xbps, nftables, das-update), with fixes (rmhost, netinfo, todo -r, dirsize, extract) and new ones (up, bigfiles, pkgowner, please, serve, weather, cheat, genpass, Docker shortcuts). lsfunc shows bilingual descriptions. Shell tests in tests/test_shell.py. - Names that shadowed commands are gone: gh -> hgrep, mount -> mounts, no install or ed. - README: "Aliases and functions" section; TODO: banner, dashboard service and prompt verified by the author on real hardware. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from tests.common import FILES, SCRATCH
|
||||
|
||||
ALIASES = os.path.join(FILES, "shell", "aliases.sh")
|
||||
FUNCTIONS = os.path.join(FILES, "shell", "functions.sh")
|
||||
|
||||
|
||||
def bash(script, cwd=None):
|
||||
"""Runs script in bash with the Das OS aliases and functions loaded."""
|
||||
full = f"shopt -s expand_aliases\n. {ALIASES}\n. {FUNCTIONS}\n{script}"
|
||||
return subprocess.run(["bash", "--norc", "-c", full], cwd=cwd, capture_output=True, text=True,
|
||||
env={**os.environ, "HOME": SCRATCH})
|
||||
|
||||
|
||||
class ShellTest(unittest.TestCase):
|
||||
def test_syntax(self):
|
||||
for path in (ALIASES, FUNCTIONS, os.path.join(FILES, "bashrc.d", "das-aliases.sh")):
|
||||
self.assertEqual(subprocess.run(["bash", "-n", path]).returncode, 0, path)
|
||||
|
||||
def test_every_function_has_a_description(self):
|
||||
out = bash("lsfunc").stdout.splitlines()
|
||||
self.assertIn("extract", [line.split()[0] for line in out])
|
||||
for line in out:
|
||||
name, _, descr = line.partition(" ")
|
||||
self.assertTrue(descr.strip(), f"{name} has no description")
|
||||
self.assertNotIn(" | ", descr, name)
|
||||
|
||||
def test_descriptions_follow_the_language(self):
|
||||
out = bash("LANG=uk_UA.UTF-8 lsfunc | grep '^mkcd '").stdout
|
||||
self.assertIn("Створити каталог", out)
|
||||
|
||||
def test_compress_and_extract(self):
|
||||
with tempfile.TemporaryDirectory(dir=SCRATCH) as d:
|
||||
r = bash("mkdir -p src/sub && echo hi >src/sub/x.txt && compress a.tar.gz src >/dev/null &&"
|
||||
" mkdir out && cd out && extract ../a.tar.gz >/dev/null && cat src/sub/x.txt", cwd=d)
|
||||
self.assertEqual(r.stdout, "hi\n", r.stderr)
|
||||
r = bash("extract nope.zip", cwd=d)
|
||||
self.assertEqual(r.returncode, 1)
|
||||
|
||||
def test_up_and_usage(self):
|
||||
with tempfile.TemporaryDirectory(dir=SCRATCH) as d:
|
||||
r = bash("mkcd a/b/c && up 2 && pwd", cwd=d)
|
||||
self.assertEqual(r.stdout.strip(), os.path.join(os.path.realpath(d), "a"))
|
||||
r = bash("up x")
|
||||
self.assertEqual(r.returncode, 2)
|
||||
self.assertIn("usage: up", r.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user