diff options
author | Marc Pervaz Boocha <mboocha@sudomsg.xyz> | 2025-02-04 00:30:21 +0530 |
---|---|---|
committer | Marc Pervaz Boocha <mboocha@sudomsg.xyz> | 2025-02-04 00:30:21 +0530 |
commit | cc32601238029a06bf9a9817514dfbfb3d48b126 (patch) | |
tree | d5faa6dea7ae45d8fb60d770d6fc96e3ac2d4821 /.local/bin/http-static | |
parent | Update plugins (diff) | |
download | dotfiles-cc32601238029a06bf9a9817514dfbfb3d48b126.tar dotfiles-cc32601238029a06bf9a9817514dfbfb3d48b126.tar.gz dotfiles-cc32601238029a06bf9a9817514dfbfb3d48b126.tar.bz2 dotfiles-cc32601238029a06bf9a9817514dfbfb3d48b126.tar.lz dotfiles-cc32601238029a06bf9a9817514dfbfb3d48b126.tar.xz dotfiles-cc32601238029a06bf9a9817514dfbfb3d48b126.tar.zst dotfiles-cc32601238029a06bf9a9817514dfbfb3d48b126.zip |
Update neovim and added static http-server
Diffstat (limited to '')
-rwxr-xr-x | .local/bin/http-static | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/.local/bin/http-static b/.local/bin/http-static new file mode 100755 index 0000000..7e6fa55 --- /dev/null +++ b/.local/bin/http-static @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +from argparse import ArgumentParser +from collections.abc import Sequence +from typing import Optional +from pathlib import Path +from http.server import SimpleHTTPRequestHandler,ThreadingHTTPServer +import sys + +def serve(bind, port, directory): + def handler(request, client_address, server): + return SimpleHTTPRequestHandler(request, client_address, server, directory=directory) + + with ThreadingHTTPServer((bind, port), handler) as httpd: + print(*httpd.socket.getsockname()) + try: + httpd.serve_forever() + except KeyboardInterrupt: + return + + +def main(argv: Optional[Sequence[str]] = None): + parser = ArgumentParser() + parser.add_argument('-b', '--bind', metavar='ADDRESS', default='', help='bind to this address') + parser.add_argument('-p', '--port', default=8080, type=int, help='bind to this port') + parser.add_argument('directory', type=Path, default=Path.cwd(), nargs="?", help='serve this directory') + args = parser.parse_args(argv) + serve(**vars(args)) + +if __name__ == '__main__': + sys.exit(main()) |